git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] config.c: avoid duplicated global static variables

From
Johannes Sixt <j6t@kdbg.org>
Date
Aug 9, 2016, 14:16 UTC
Message-ID
<57A9E5C1.3030205@kdbg.org>

Repeating the definition of a static variable seems to be valid in C. Nevertheless, it is bad style because it can cause confusion, definitely when it becomes necessary to change the type.

d64ec16 (git config: reorganize to use parseopt, 2009-02-21) added two static variables near the top of the file config.c without removing the definitions of the two variables that occurs later in the file.

The two variables were needed earlier in the file in the newly introduced parseopt structure. These references were removed later in d0e08d6 (config: fix parsing of "git config --get-color some.key -1", 2014-11-20).

Remove the redundant, younger, definitions near the top of the file and keep the original definitions that occur later.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
---
 Why the heck are duplicated static variables not an error in C?
 Since they aren't (as it seems), this and the next patch are just
 a matter of taste.
 builtin/config.c | 1 -
 1 file changed, 1 deletion(-)
diff --git a/builtin/config.c b/builtin/config.c
index a991a53..6cbf733 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -25,7 +25,6 @@ static char term = '\n';
 static int use_global_config, use_system_config, use_local_config;
 static struct git_config_source given_config_source;
 static int actions, types;
-static const char *get_color_slot, *get_colorbool_slot;
 static int end_null;
 static int respect_includes = -1;
 static int show_origin;
-- 
2.9.2.935.gccae72a.dirty
Next: Johannes Sixt
Message 1 of 4 in “config.c: avoid duplicated global static variables”
  1. 1/2 config.c: avoid duplicated global static variablesJohannes Sixt, Aug 9, 2016
  2. 2/2 commit-slab.h: avoid duplicated global static variablesJohannes Sixt, Aug 9, 2016
  3. Johannes SixtAug 9, 2016
  4. Junio C HamanoAug 9, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.