Skip to content

Commit d64324c

Browse files
tboegigitster
authored andcommitted
Make git_check_attr() a void function
git_check_attr() returns always 0. Remove all the error handling code of the callers, which is never executed. Change git_check_attr() to be a void function. Signed-off-by: Torsten Bögershausen <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d4361b commit d64324c

9 files changed

+57
-69
lines changed

archive.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ static const struct attr_check *get_archive_attrs(struct index_state *istate,
110110
static struct attr_check *check;
111111
if (!check)
112112
check = attr_check_initl("export-ignore", "export-subst", NULL);
113-
return git_check_attr(istate, path, check) ? NULL : check;
113+
git_check_attr(istate, path, check);
114+
return check;
114115
}
115116

116117
static int check_attr_export_ignore(const struct attr_check *check)

attr.c

+3-5
Original file line numberDiff line numberDiff line change
@@ -1143,9 +1143,9 @@ static void collect_some_attrs(const struct index_state *istate,
11431143
fill(path, pathlen, basename_offset, check->stack, check->all_attrs, rem);
11441144
}
11451145

1146-
int git_check_attr(const struct index_state *istate,
1147-
const char *path,
1148-
struct attr_check *check)
1146+
void git_check_attr(const struct index_state *istate,
1147+
const char *path,
1148+
struct attr_check *check)
11491149
{
11501150
int i;
11511151

@@ -1158,8 +1158,6 @@ int git_check_attr(const struct index_state *istate,
11581158
value = ATTR__UNSET;
11591159
check->items[i].value = value;
11601160
}
1161-
1162-
return 0;
11631161
}
11641162

11651163
void git_all_attrs(const struct index_state *istate,

attr.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ void attr_check_free(struct attr_check *check);
6363
*/
6464
const char *git_attr_name(const struct git_attr *);
6565

66-
int git_check_attr(const struct index_state *istate,
67-
const char *path, struct attr_check *check);
66+
void git_check_attr(const struct index_state *istate,
67+
const char *path, struct attr_check *check);
6868

6969
/*
7070
* Retrieve all attributes that apply to the specified path.

builtin/check-attr.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ static void check_attr(const char *prefix,
6565
if (collect_all) {
6666
git_all_attrs(&the_index, full_path, check);
6767
} else {
68-
if (git_check_attr(&the_index, full_path, check))
69-
die("git_check_attr died");
68+
git_check_attr(&the_index, full_path, check);
7069
}
7170
output_attr(check, file);
7271

builtin/pack-objects.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,7 @@ static int no_try_delta(const char *path)
951951

952952
if (!check)
953953
check = attr_check_initl("delta", NULL);
954-
if (git_check_attr(&the_index, path, check))
955-
return 0;
954+
git_check_attr(&the_index, path, check);
956955
if (ATTR_FALSE(check->items[0].value))
957956
return 1;
958957
return 0;

convert.c

+19-23
Original file line numberDiff line numberDiff line change
@@ -1297,6 +1297,7 @@ static void convert_attrs(const struct index_state *istate,
12971297
struct conv_attrs *ca, const char *path)
12981298
{
12991299
static struct attr_check *check;
1300+
struct attr_check_item *ccheck = NULL;
13001301

13011302
if (!check) {
13021303
check = attr_check_initl("crlf", "ident", "filter",
@@ -1306,30 +1307,25 @@ static void convert_attrs(const struct index_state *istate,
13061307
git_config(read_convert_config, NULL);
13071308
}
13081309

1309-
if (!git_check_attr(istate, path, check)) {
1310-
struct attr_check_item *ccheck = check->items;
1311-
ca->crlf_action = git_path_check_crlf(ccheck + 4);
1312-
if (ca->crlf_action == CRLF_UNDEFINED)
1313-
ca->crlf_action = git_path_check_crlf(ccheck + 0);
1314-
ca->ident = git_path_check_ident(ccheck + 1);
1315-
ca->drv = git_path_check_convert(ccheck + 2);
1316-
if (ca->crlf_action != CRLF_BINARY) {
1317-
enum eol eol_attr = git_path_check_eol(ccheck + 3);
1318-
if (ca->crlf_action == CRLF_AUTO && eol_attr == EOL_LF)
1319-
ca->crlf_action = CRLF_AUTO_INPUT;
1320-
else if (ca->crlf_action == CRLF_AUTO && eol_attr == EOL_CRLF)
1321-
ca->crlf_action = CRLF_AUTO_CRLF;
1322-
else if (eol_attr == EOL_LF)
1323-
ca->crlf_action = CRLF_TEXT_INPUT;
1324-
else if (eol_attr == EOL_CRLF)
1325-
ca->crlf_action = CRLF_TEXT_CRLF;
1326-
}
1327-
ca->working_tree_encoding = git_path_check_encoding(ccheck + 5);
1328-
} else {
1329-
ca->drv = NULL;
1330-
ca->crlf_action = CRLF_UNDEFINED;
1331-
ca->ident = 0;
1310+
git_check_attr(istate, path, check);
1311+
ccheck = check->items;
1312+
ca->crlf_action = git_path_check_crlf(ccheck + 4);
1313+
if (ca->crlf_action == CRLF_UNDEFINED)
1314+
ca->crlf_action = git_path_check_crlf(ccheck + 0);
1315+
ca->ident = git_path_check_ident(ccheck + 1);
1316+
ca->drv = git_path_check_convert(ccheck + 2);
1317+
if (ca->crlf_action != CRLF_BINARY) {
1318+
enum eol eol_attr = git_path_check_eol(ccheck + 3);
1319+
if (ca->crlf_action == CRLF_AUTO && eol_attr == EOL_LF)
1320+
ca->crlf_action = CRLF_AUTO_INPUT;
1321+
else if (ca->crlf_action == CRLF_AUTO && eol_attr == EOL_CRLF)
1322+
ca->crlf_action = CRLF_AUTO_CRLF;
1323+
else if (eol_attr == EOL_LF)
1324+
ca->crlf_action = CRLF_TEXT_INPUT;
1325+
else if (eol_attr == EOL_CRLF)
1326+
ca->crlf_action = CRLF_TEXT_CRLF;
13321327
}
1328+
ca->working_tree_encoding = git_path_check_encoding(ccheck + 5);
13331329

13341330
/* Save attr and make a decision for action */
13351331
ca->attr_action = ca->crlf_action;

ll-merge.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -371,13 +371,12 @@ int ll_merge(mmbuffer_t *result_buf,
371371
if (!check)
372372
check = attr_check_initl("merge", "conflict-marker-size", NULL);
373373

374-
if (!git_check_attr(&the_index, path, check)) {
375-
ll_driver_name = check->items[0].value;
376-
if (check->items[1].value) {
377-
marker_size = atoi(check->items[1].value);
378-
if (marker_size <= 0)
379-
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
380-
}
374+
git_check_attr(&the_index, path, check);
375+
ll_driver_name = check->items[0].value;
376+
if (check->items[1].value) {
377+
marker_size = atoi(check->items[1].value);
378+
if (marker_size <= 0)
379+
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;
381380
}
382381
driver = find_ll_merge_driver(ll_driver_name);
383382

@@ -398,7 +397,8 @@ int ll_merge_marker_size(const char *path)
398397

399398
if (!check)
400399
check = attr_check_initl("conflict-marker-size", NULL);
401-
if (!git_check_attr(&the_index, path, check) && check->items[0].value) {
400+
git_check_attr(&the_index, path, check);
401+
if (check->items[0].value) {
402402
marker_size = atoi(check->items[0].value);
403403
if (marker_size <= 0)
404404
marker_size = DEFAULT_CONFLICT_MARKER_SIZE;

userdiff.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -278,8 +278,7 @@ struct userdiff_driver *userdiff_find_by_path(const char *path)
278278
check = attr_check_initl("diff", NULL);
279279
if (!path)
280280
return NULL;
281-
if (git_check_attr(&the_index, path, check))
282-
return NULL;
281+
git_check_attr(&the_index, path, check);
283282

284283
if (ATTR_TRUE(check->items[0].value))
285284
return &driver_true;

ws.c

+20-24
Original file line numberDiff line numberDiff line change
@@ -74,35 +74,31 @@ unsigned parse_whitespace_rule(const char *string)
7474
unsigned whitespace_rule(const char *pathname)
7575
{
7676
static struct attr_check *attr_whitespace_rule;
77+
const char *value;
7778

7879
if (!attr_whitespace_rule)
7980
attr_whitespace_rule = attr_check_initl("whitespace", NULL);
8081

81-
if (!git_check_attr(&the_index, pathname, attr_whitespace_rule)) {
82-
const char *value;
83-
84-
value = attr_whitespace_rule->items[0].value;
85-
if (ATTR_TRUE(value)) {
86-
/* true (whitespace) */
87-
unsigned all_rule = ws_tab_width(whitespace_rule_cfg);
88-
int i;
89-
for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++)
90-
if (!whitespace_rule_names[i].loosens_error &&
91-
!whitespace_rule_names[i].exclude_default)
92-
all_rule |= whitespace_rule_names[i].rule_bits;
93-
return all_rule;
94-
} else if (ATTR_FALSE(value)) {
95-
/* false (-whitespace) */
96-
return ws_tab_width(whitespace_rule_cfg);
97-
} else if (ATTR_UNSET(value)) {
98-
/* reset to default (!whitespace) */
99-
return whitespace_rule_cfg;
100-
} else {
101-
/* string */
102-
return parse_whitespace_rule(value);
103-
}
104-
} else {
82+
git_check_attr(&the_index, pathname, attr_whitespace_rule);
83+
value = attr_whitespace_rule->items[0].value;
84+
if (ATTR_TRUE(value)) {
85+
/* true (whitespace) */
86+
unsigned all_rule = ws_tab_width(whitespace_rule_cfg);
87+
int i;
88+
for (i = 0; i < ARRAY_SIZE(whitespace_rule_names); i++)
89+
if (!whitespace_rule_names[i].loosens_error &&
90+
!whitespace_rule_names[i].exclude_default)
91+
all_rule |= whitespace_rule_names[i].rule_bits;
92+
return all_rule;
93+
} else if (ATTR_FALSE(value)) {
94+
/* false (-whitespace) */
95+
return ws_tab_width(whitespace_rule_cfg);
96+
} else if (ATTR_UNSET(value)) {
97+
/* reset to default (!whitespace) */
10598
return whitespace_rule_cfg;
99+
} else {
100+
/* string */
101+
return parse_whitespace_rule(value);
106102
}
107103
}
108104

0 commit comments

Comments
 (0)