attr: drop DEBUG_ATTR code

Since its inception in d0bfd026a8 (Add basic infrastructure to assign attributes to paths, 2007-04-12), the attribute code carries a little bit of debug code that is conditionally compiled only when DEBUG_ATTR is set. But since you have to know about it and make a special build of Git to use it, it's not clear that it's helping anyone (and there are very few mentions of it on the list over the years). Meanwhile, it causes slight headaches. Since it's not built as part of a regular compile, it's subject to bitrot. E.g., this was dealt with in 712efb1a42 (attr: make it build with DEBUG_ATTR again, 2013-01-15), and it currently fails to build with DEVELOPER=1 since e810e06357 (attr: tighten const correctness with git_attr and match_attr, 2017-01-27). And it causes confusion with -Wunused-parameter; the "what" parameter of fill_one() is unused in a normal build, but needed in a debug build. Let's just get rid of this code (and the now-useless parameter). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 6, 2022 at 09:23 UTC 69c5f17f11a2afe6b56b04f5a4377e4332858cde
1 file changed +3 -38
attr.c
+3 -38
@@ -23,10 +23,6 @@ static const char git_attr__unknown[] = "(builtin)unknown";
23 #define ATTR__UNSET NULL
24 #define ATTR__UNKNOWN git_attr__unknown
25
26 -#ifndef DEBUG_ATTR
27 -#define DEBUG_ATTR 0
28 -#endif
29 -
26 struct git_attr {
27 int attr_nr; /* unique attribute number */
28 char name[FLEX_ARRAY]; /* attribute name */
@@ -807,33 +803,6 @@ static struct attr_stack *read_attr(struct index_state *istate,
803 return res;
804 }
805
810 -#if DEBUG_ATTR
811 -static void debug_info(const char *what, struct attr_stack *elem)
812 -{
813 - fprintf(stderr, "%s: %s\n", what, elem->origin ? elem->origin : "()");
814 -}
815 -static void debug_set(const char *what, const char *match, struct git_attr *attr, const void *v)
816 -{
817 - const char *value = v;
818 -
819 - if (ATTR_TRUE(value))
820 - value = "set";
821 - else if (ATTR_FALSE(value))
822 - value = "unset";
823 - else if (ATTR_UNSET(value))
824 - value = "unspecified";
825 -
826 - fprintf(stderr, "%s: %s => %s (%s)\n",
827 - what, attr->name, (char *) value, match);
828 -}
829 -#define debug_push(a) debug_info("push", (a))
830 -#define debug_pop(a) debug_info("pop", (a))
831 -#else
832 -#define debug_push(a) do { ; } while (0)
833 -#define debug_pop(a) do { ; } while (0)
834 -#define debug_set(a,b,c,d) do { ; } while (0)
835 -#endif /* DEBUG_ATTR */
836 -
806 static const char *git_etc_gitattributes(void)
807 {
808 static const char *system_wide;
@@ -954,7 +923,6 @@ static void prepare_attr_stack(struct index_state *istate,
923 (!namelen || path[namelen] == '/'))
924 break;
925
957 - debug_pop(elem);
926 *stack = elem->prev;
927 attr_stack_free(elem);
928 }
@@ -1028,7 +996,7 @@ static int path_matches(const char *pathname, int pathlen,
996
997 static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem);
998
1031 -static int fill_one(const char *what, struct all_attrs_item *all_attrs,
999 +static int fill_one(struct all_attrs_item *all_attrs,
1000 const struct match_attr *a, int rem)
1001 {
1002 int i;
@@ -1039,9 +1007,6 @@ static int fill_one(const char *what, struct all_attrs_item *all_attrs,
1007 const char *v = a->state[i].setto;
1008
1009 if (*n == ATTR__UNKNOWN) {
1042 - debug_set(what,
1043 - a->is_macro ? a->u.attr->name : a->u.pat.pattern,
1044 - attr, v);
1010 *n = v;
1011 rem--;
1012 rem = macroexpand_one(all_attrs, attr->attr_nr, rem);
@@ -1064,7 +1029,7 @@ static int fill(const char *path, int pathlen, int basename_offset,
1029 continue;
1030 if (path_matches(path, pathlen, basename_offset,
1031 &a->u.pat, base, stack->originlen))
1067 - rem = fill_one("fill", all_attrs, a, rem);
1032 + rem = fill_one(all_attrs, a, rem);
1033 }
1034 }
1035
@@ -1076,7 +1041,7 @@ static int macroexpand_one(struct all_attrs_item *all_attrs, int nr, int rem)
1041 const struct all_attrs_item *item = &all_attrs[nr];
1042
1043 if (item->macro && item->value == ATTR__TRUE)
1079 - return fill_one("expand", all_attrs, item->macro, rem);
1044 + return fill_one(all_attrs, item->macro, rem);
1045 else
1046 return rem;
1047 }