]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'jc/c99-var-decl-in-for-loop'
authorJunio C Hamano <gitster@pobox.com>
Tue, 21 Dec 2021 23:03:15 +0000 (15:03 -0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Dec 2021 23:03:15 +0000 (15:03 -0800)
Weather balloon to find compilers that do not grok variable
declaration in the for() loop.

* jc/c99-var-decl-in-for-loop:
  revision: use C99 declaration of variable in for() loop

Makefile
revision.c

index 9c00a793e4701287f6e7b1007fc75111b09715a7..c8c2eca6802414d2a28bef82298ed34b8482486f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1206,6 +1206,7 @@ endif
 # Set CFLAGS, LDFLAGS and other *FLAGS variables. These might be
 # tweaked by config.* below as well as the command-line, both of
 # which'll override these defaults.
+# Older versions of GCC may require adding "-std=gnu99" at the end.
 CFLAGS = -g -O2 -Wall
 LDFLAGS =
 CC_LD_DYNPATH = -Wl,-rpath,
index 1981a0859f0e24cadec5e496e9616dc39f23330c..5390a479b30fb91222e2c326b6930182feb0620e 100644 (file)
@@ -44,10 +44,15 @@ static inline int want_ancestry(const struct rev_info *revs);
 
 void show_object_with_name(FILE *out, struct object *obj, const char *name)
 {
-       const char *p;
-
        fprintf(out, "%s ", oid_to_hex(&obj->oid));
-       for (p = name; *p && *p != '\n'; p++)
+       /*
+        * This "for (const char *p = ..." is made as a first step towards
+        * making use of such declarations elsewhere in our codebase.  If
+        * it causes compilation problems on your platform, please report
+        * it to the Git mailing list at git@vger.kernel.org. In the meantime,
+        * adding -std=gnu99 to CFLAGS may help if you are with older GCC.
+        */
+       for (const char *p = name; *p && *p != '\n'; p++)
                fputc(*p, out);
        fputc('\n', out);
 }