Skip to content

Commit 37e4c1b

Browse files
authored
Merge pull request libgit2#5119 from libgit2/ethomson/attr
attr: rename constants and macros for consistency
2 parents c3bbbcf + 91a300b commit 37e4c1b

File tree

12 files changed

+113
-91
lines changed

12 files changed

+113
-91
lines changed

include/git2/attr.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ GIT_BEGIN_DECL
3030
* Then for file `xyz.c` looking up attribute "foo" gives a value for
3131
* which `GIT_ATTR_TRUE(value)` is true.
3232
*/
33-
#define GIT_ATTR_TRUE(attr) (git_attr_value(attr) == GIT_ATTR_TRUE_T)
33+
#define GIT_ATTR_IS_TRUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_TRUE)
3434

3535
/**
3636
* GIT_ATTR_FALSE checks if an attribute is set off. In core git
@@ -44,7 +44,7 @@ GIT_BEGIN_DECL
4444
* Then for file `zyx.h` looking up attribute "foo" gives a value for
4545
* which `GIT_ATTR_FALSE(value)` is true.
4646
*/
47-
#define GIT_ATTR_FALSE(attr) (git_attr_value(attr) == GIT_ATTR_FALSE_T)
47+
#define GIT_ATTR_IS_FALSE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_FALSE)
4848

4949
/**
5050
* GIT_ATTR_UNSPECIFIED checks if an attribute is unspecified. This
@@ -62,7 +62,7 @@ GIT_BEGIN_DECL
6262
* file `onefile.rb` or looking up "bar" on any file will all give
6363
* `GIT_ATTR_UNSPECIFIED(value)` of true.
6464
*/
65-
#define GIT_ATTR_UNSPECIFIED(attr) (git_attr_value(attr) == GIT_ATTR_UNSPECIFIED_T)
65+
#define GIT_ATTR_IS_UNSPECIFIED(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_UNSPECIFIED)
6666

6767
/**
6868
* GIT_ATTR_HAS_VALUE checks if an attribute is set to a value (as
@@ -74,17 +74,17 @@ GIT_BEGIN_DECL
7474
* Given this, looking up "eol" for `onefile.txt` will give back the
7575
* string "lf" and `GIT_ATTR_SET_TO_VALUE(attr)` will return true.
7676
*/
77-
#define GIT_ATTR_HAS_VALUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_T)
77+
#define GIT_ATTR_HAS_VALUE(attr) (git_attr_value(attr) == GIT_ATTR_VALUE_STRING)
7878

7979
/**
8080
* Possible states for an attribute
8181
*/
8282
typedef enum {
83-
GIT_ATTR_UNSPECIFIED_T = 0, /**< The attribute has been left unspecified */
84-
GIT_ATTR_TRUE_T, /**< The attribute has been set */
85-
GIT_ATTR_FALSE_T, /**< The attribute has been unset */
86-
GIT_ATTR_VALUE_T, /**< This attribute has a value */
87-
} git_attr_t;
83+
GIT_ATTR_VALUE_UNSPECIFIED = 0, /**< The attribute has been left unspecified */
84+
GIT_ATTR_VALUE_TRUE, /**< The attribute has been set */
85+
GIT_ATTR_VALUE_FALSE, /**< The attribute has been unset */
86+
GIT_ATTR_VALUE_STRING, /**< This attribute has a value */
87+
} git_attr_value_t;
8888

8989
/**
9090
* Return the value type for a given attribute.
@@ -99,7 +99,7 @@ typedef enum {
9999
* @param attr The attribute
100100
* @return the value type for the attribute
101101
*/
102-
GIT_EXTERN(git_attr_t) git_attr_value(const char *attr);
102+
GIT_EXTERN(git_attr_value_t) git_attr_value(const char *attr);
103103

104104
/**
105105
* Check attribute flags: Reading values from index and working directory.

include/git2/deprecated.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,28 @@
4545
*/
4646
GIT_BEGIN_DECL
4747

48+
/** @name Deprecated Attribute Constants
49+
*
50+
* These enumeration values are retained for backward compatibility.
51+
* The newer versions of these functions should be preferred in all
52+
* new code.
53+
*
54+
* There is no plan to remove these backward compatibility values at
55+
* this time.
56+
*/
57+
/**@{*/
58+
59+
#define GIT_ATTR_UNSPECIFIED_T GIT_ATTR_VALUE_UNSPECIFIED
60+
#define GIT_ATTR_TRUE_T GIT_ATTR_VALUE_TRUE
61+
#define GIT_ATTR_FALSE_T GIT_ATTR_VALUE_FALSE
62+
#define GIT_ATTR_VALUE_T GIT_ATTR_VALUE_STRING
63+
64+
#define GIT_ATTR_TRUE(attr) GIT_ATTR_IS_TRUE(attr)
65+
#define GIT_ATTR_FALSE(attr) GIT_ATTR_IS_FALSE(attr)
66+
#define GIT_ATTR_UNSPECIFIED(attr) GIT_ATTR_IS_UNSPECIFIED(attr)
67+
68+
/**@}*/
69+
4870
/** @name Deprecated Blob Functions
4971
*
5072
* These functions are retained for backward compatibility. The newer

src/attr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,18 @@ const char *git_attr__true = "[internal]__TRUE__";
1919
const char *git_attr__false = "[internal]__FALSE__";
2020
const char *git_attr__unset = "[internal]__UNSET__";
2121

22-
git_attr_t git_attr_value(const char *attr)
22+
git_attr_value_t git_attr_value(const char *attr)
2323
{
2424
if (attr == NULL || attr == git_attr__unset)
25-
return GIT_ATTR_UNSPECIFIED_T;
25+
return GIT_ATTR_VALUE_UNSPECIFIED;
2626

2727
if (attr == git_attr__true)
28-
return GIT_ATTR_TRUE_T;
28+
return GIT_ATTR_VALUE_TRUE;
2929

3030
if (attr == git_attr__false)
31-
return GIT_ATTR_FALSE_T;
31+
return GIT_ATTR_VALUE_FALSE;
3232

33-
return GIT_ATTR_VALUE_T;
33+
return GIT_ATTR_VALUE_STRING;
3434
}
3535

3636
static int collect_attr_files(

src/crlf.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ struct crlf_filter {
4444

4545
static git_crlf_t check_crlf(const char *value)
4646
{
47-
if (GIT_ATTR_TRUE(value))
47+
if (GIT_ATTR_IS_TRUE(value))
4848
return GIT_CRLF_TEXT;
49-
else if (GIT_ATTR_FALSE(value))
49+
else if (GIT_ATTR_IS_FALSE(value))
5050
return GIT_CRLF_BINARY;
51-
else if (GIT_ATTR_UNSPECIFIED(value))
51+
else if (GIT_ATTR_IS_UNSPECIFIED(value))
5252
;
5353
else if (strcmp(value, "input") == 0)
5454
return GIT_CRLF_TEXT_INPUT;
@@ -60,7 +60,7 @@ static git_crlf_t check_crlf(const char *value)
6060

6161
static git_cvar_value check_eol(const char *value)
6262
{
63-
if (GIT_ATTR_UNSPECIFIED(value))
63+
if (GIT_ATTR_IS_UNSPECIFIED(value))
6464
;
6565
else if (strcmp(value, "lf") == 0)
6666
return GIT_EOL_LF;

src/diff_driver.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,11 +371,11 @@ int git_diff_driver_lookup(
371371
attrsession, 0, path, 1, attrs)) < 0)
372372
/* return error below */;
373373

374-
else if (GIT_ATTR_UNSPECIFIED(values[0]))
374+
else if (GIT_ATTR_IS_UNSPECIFIED(values[0]))
375375
/* just use the auto value */;
376-
else if (GIT_ATTR_FALSE(values[0]))
376+
else if (GIT_ATTR_IS_FALSE(values[0]))
377377
*out = &global_drivers[DIFF_DRIVER_BINARY];
378-
else if (GIT_ATTR_TRUE(values[0]))
378+
else if (GIT_ATTR_IS_TRUE(values[0]))
379379
*out = &global_drivers[DIFF_DRIVER_TEXT];
380380

381381
/* otherwise look for driver information in config and build driver */

src/filter.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static int filter_list_check_attributes(
445445

446446
for (i = 0; !error && i < fdef->nattrs; ++i) {
447447
const char *want = fdef->attrs[fdef->nattrs + i];
448-
git_attr_t want_type, found_type;
448+
git_attr_value_t want_type, found_type;
449449

450450
if (!want)
451451
continue;
@@ -455,7 +455,7 @@ static int filter_list_check_attributes(
455455

456456
if (want_type != found_type)
457457
error = GIT_ENOTFOUND;
458-
else if (want_type == GIT_ATTR_VALUE_T &&
458+
else if (want_type == GIT_ATTR_VALUE_STRING &&
459459
strcmp(want, strs[i]) &&
460460
strcmp(want, "*"))
461461
error = GIT_ENOTFOUND;

src/merge_driver.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,17 +371,17 @@ static int merge_driver_name_for_path(
371371
return error;
372372

373373
/* set: use the built-in 3-way merge driver ("text") */
374-
if (GIT_ATTR_TRUE(value))
374+
if (GIT_ATTR_IS_TRUE(value))
375375
*out = merge_driver_name__text;
376376

377377
/* unset: do not merge ("binary") */
378-
else if (GIT_ATTR_FALSE(value))
378+
else if (GIT_ATTR_IS_FALSE(value))
379379
*out = merge_driver_name__binary;
380380

381-
else if (GIT_ATTR_UNSPECIFIED(value) && default_driver)
381+
else if (GIT_ATTR_IS_UNSPECIFIED(value) && default_driver)
382382
*out = default_driver;
383383

384-
else if (GIT_ATTR_UNSPECIFIED(value))
384+
else if (GIT_ATTR_IS_UNSPECIFIED(value))
385385
*out = merge_driver_name__text;
386386

387387
else

tests/attr/attr_expect.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ GIT_INLINE(void) attr_check_expected(
2323
{
2424
switch (expected) {
2525
case EXPECT_TRUE:
26-
cl_assert_(GIT_ATTR_TRUE(value), name);
26+
cl_assert_(GIT_ATTR_IS_TRUE(value), name);
2727
break;
2828

2929
case EXPECT_FALSE:
30-
cl_assert_(GIT_ATTR_FALSE(value), name);
30+
cl_assert_(GIT_ATTR_IS_FALSE(value), name);
3131
break;
3232

3333
case EXPECT_UNDEFINED:
34-
cl_assert_(GIT_ATTR_UNSPECIFIED(value), name);
34+
cl_assert_(GIT_ATTR_IS_UNSPECIFIED(value), name);
3535
break;
3636

3737
case EXPECT_STRING:

tests/attr/file.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ void test_attr_file__simple_read(void)
2626
assign = get_assign(rule, 0);
2727
cl_assert(assign != NULL);
2828
cl_assert_equal_s("binary", assign->name);
29-
cl_assert(GIT_ATTR_TRUE(assign->value));
29+
cl_assert(GIT_ATTR_IS_TRUE(assign->value));
3030

3131
git_attr_file__free(file);
3232
}
@@ -53,7 +53,7 @@ void test_attr_file__match_variants(void)
5353
assign = get_assign(rule,0);
5454
cl_assert_equal_s("attr0", assign->name);
5555
cl_assert(assign->name_hash == git_attr_file__name_hash(assign->name));
56-
cl_assert(GIT_ATTR_TRUE(assign->value));
56+
cl_assert(GIT_ATTR_IS_TRUE(assign->value));
5757

5858
rule = get_rule(1);
5959
cl_assert_equal_s("pat1", rule->match.pattern);
@@ -83,7 +83,7 @@ void test_attr_file__match_variants(void)
8383
cl_assert((rule->match.flags & GIT_ATTR_FNMATCH_HASWILD) != 0);
8484
assign = get_assign(rule,0);
8585
cl_assert_equal_s("attr7", assign->name);
86-
cl_assert(GIT_ATTR_TRUE(assign->value));
86+
cl_assert(GIT_ATTR_IS_TRUE(assign->value));
8787

8888
rule = get_rule(8);
8989
cl_assert_equal_s("pat8 with spaces", rule->match.pattern);
@@ -144,11 +144,11 @@ void test_attr_file__assign_variants(void)
144144
assign = git_attr_rule__lookup_assignment(rule, "multiple");
145145
cl_assert(assign);
146146
cl_assert_equal_s("multiple", assign->name);
147-
cl_assert(GIT_ATTR_TRUE(assign->value));
147+
cl_assert(GIT_ATTR_IS_TRUE(assign->value));
148148
assign = git_attr_rule__lookup_assignment(rule, "single");
149149
cl_assert(assign);
150150
cl_assert_equal_s("single", assign->name);
151-
cl_assert(GIT_ATTR_FALSE(assign->value));
151+
cl_assert(GIT_ATTR_IS_FALSE(assign->value));
152152
assign = git_attr_rule__lookup_assignment(rule, "values");
153153
cl_assert(assign);
154154
cl_assert_equal_s("values", assign->name);
@@ -170,7 +170,7 @@ void test_attr_file__assign_variants(void)
170170
assign = git_attr_rule__lookup_assignment(rule, "again");
171171
cl_assert(assign);
172172
cl_assert_equal_s("again", assign->name);
173-
cl_assert(GIT_ATTR_TRUE(assign->value));
173+
cl_assert(GIT_ATTR_IS_TRUE(assign->value));
174174
assign = git_attr_rule__lookup_assignment(rule, "another");
175175
cl_assert(assign);
176176
cl_assert_equal_s("another", assign->name);
@@ -194,10 +194,10 @@ static void assert_examples(git_attr_file *file)
194194
cl_assert_equal_s("java", assign->value);
195195
assign = git_attr_rule__lookup_assignment(rule, "crlf");
196196
cl_assert_equal_s("crlf", assign->name);
197-
cl_assert(GIT_ATTR_FALSE(assign->value));
197+
cl_assert(GIT_ATTR_IS_FALSE(assign->value));
198198
assign = git_attr_rule__lookup_assignment(rule, "myAttr");
199199
cl_assert_equal_s("myAttr", assign->name);
200-
cl_assert(GIT_ATTR_TRUE(assign->value));
200+
cl_assert(GIT_ATTR_IS_TRUE(assign->value));
201201
assign = git_attr_rule__lookup_assignment(rule, "missing");
202202
cl_assert(assign == NULL);
203203

@@ -206,7 +206,7 @@ static void assert_examples(git_attr_file *file)
206206
cl_assert(rule->assigns.length == 1);
207207
assign = get_assign(rule, 0);
208208
cl_assert_equal_s("myAttr", assign->name);
209-
cl_assert(GIT_ATTR_UNSPECIFIED(assign->value));
209+
cl_assert(GIT_ATTR_IS_UNSPECIFIED(assign->value));
210210

211211
rule = get_rule(2);
212212
cl_assert_equal_s("README", rule->match.pattern);

tests/attr/flags.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void test_attr_flags__bare(void)
1515

1616
cl_git_pass(git_attr_get(
1717
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM, "README.md", "diff"));
18-
cl_assert(GIT_ATTR_UNSPECIFIED(value));
18+
cl_assert(GIT_ATTR_IS_UNSPECIFIED(value));
1919
}
2020

2121
void test_attr_flags__index_vs_workdir(void)
@@ -29,7 +29,7 @@ void test_attr_flags__index_vs_workdir(void)
2929
cl_git_pass(git_attr_get(
3030
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
3131
"README.md", "bar"));
32-
cl_assert(GIT_ATTR_FALSE(value));
32+
cl_assert(GIT_ATTR_IS_FALSE(value));
3333

3434
cl_git_pass(git_attr_get(
3535
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
@@ -39,13 +39,13 @@ void test_attr_flags__index_vs_workdir(void)
3939
cl_git_pass(git_attr_get(
4040
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
4141
"README.txt", "foo"));
42-
cl_assert(GIT_ATTR_FALSE(value));
42+
cl_assert(GIT_ATTR_IS_FALSE(value));
4343

4444
/* index then wd */
4545
cl_git_pass(git_attr_get(
4646
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
4747
"README.md", "bar"));
48-
cl_assert(GIT_ATTR_TRUE(value));
48+
cl_assert(GIT_ATTR_IS_TRUE(value));
4949

5050
cl_git_pass(git_attr_get(
5151
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
@@ -55,7 +55,7 @@ void test_attr_flags__index_vs_workdir(void)
5555
cl_git_pass(git_attr_get(
5656
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
5757
"README.txt", "foo"));
58-
cl_assert(GIT_ATTR_TRUE(value));
58+
cl_assert(GIT_ATTR_IS_TRUE(value));
5959
}
6060

6161
void test_attr_flags__subdir(void)
@@ -77,7 +77,7 @@ void test_attr_flags__subdir(void)
7777
cl_git_pass(git_attr_get(
7878
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
7979
"sub/sub/README.txt", "again"));
80-
cl_assert(GIT_ATTR_TRUE(value));
80+
cl_assert(GIT_ATTR_IS_TRUE(value));
8181

8282
cl_git_pass(git_attr_get(
8383
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_FILE_THEN_INDEX,
@@ -98,7 +98,7 @@ void test_attr_flags__subdir(void)
9898
cl_git_pass(git_attr_get(
9999
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,
100100
"sub/sub/README.txt", "again"));
101-
cl_assert(GIT_ATTR_TRUE(value));
101+
cl_assert(GIT_ATTR_IS_TRUE(value));
102102

103103
cl_git_pass(git_attr_get(
104104
&value, repo, GIT_ATTR_CHECK_NO_SYSTEM | GIT_ATTR_CHECK_INDEX_THEN_FILE,

0 commit comments

Comments
 (0)