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

Re: th/remote-usage

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Nov 18, 2009, 12:05 UTC
Message-ID
<20091118120508.GB13346@progeny.tock>
In-Reply-To
<20091118114808.GA13346@progeny.tock>
Hi,
Another thought.
Yesterday, Tim Henigan wrote:
Show 9 quoted lines
> Do you object to the new #defines for the strings?  I added them since we now
> really need to construct the usage string for 2 separate uses:
>   (1) When 'git remote -h' is invoked, we need to return the usage
> string showing
>        all subcommands.
>   (2) When 'git remote <subcommand> -h' is invoked, we need to return the
>       usage for just that command.
>
> It doesn't make sense to me to maintain separate strings for the two use cases.
Another option would be to make the strings into static variables.

I vaguely hoped this would help the code size a little, but gcc is already smart enough to notice the strings are the same on its own. Actually, this increases the text size by 15 bytes. Apparently, static arrays have to live at 4-byte aligned addresses in the x86 ABI.

So there is not much to recommend this. I am sending it mostly for academic interest. It also has the virtue of decreasing the density of capital letters in the code.

 builtin-remote.c |   47 ++++++++++++++++++++++++-----------------------
 1 files changed, 24 insertions(+), 23 deletions(-)
diff --git a/builtin-remote.c b/builtin-remote.c
index cfd8a36..185ce42 100644
--- a/builtin-remote.c
+++ b/builtin-remote.c
@@ -7,34 +7,35 @@
 #include "run-command.h"
 #include "refs.h"
 
-#define REMOTE_BARE_USAGE "git remote [options]"
-#define REMOTE_ADD_USAGE "git remote add [options] <name> <url>"
-#define REMOTE_RENAME_USAGE "git remote rename <old> <new>"
-#define REMOTE_RM_USAGE "git remote rm <name>"
-#define REMOTE_SETHEAD_USAGE "git remote set-head <name> (-a|-d|<branch>)"
-#define REMOTE_SHOW_USAGE "git remote show [options] <name>"
-#define REMOTE_PRUNE_USAGE "git remote prune [options] <name>"
-#define REMOTE_UPDATE_USAGE "git remote update [options]"
+static const char remote_bare_usage[] = "git remote [options]";
+static const char remote_add_usage[] = "git remote add [options] <name> <url>";
+static const char remote_rename_usage[] = "git remote rename <old> <new>";
+static const char remote_rm_usage[] = "git remote rm <name>";
+static const char remote_sethead_usage[] =
+"git remote set-head <name> (-a|-d|<branch>)";
+static const char remote_show_usage[] = "git remote show [options] <name>";
+static const char remote_prune_usage[] = "git remote prune [options] <name>";
+static const char remote_update_usage[] = "git remote update [options]";
 
 static const char * const builtin_remote_usage[] = {
-	REMOTE_BARE_USAGE,
-	REMOTE_ADD_USAGE,
-	REMOTE_RENAME_USAGE,
-	REMOTE_RM_USAGE,
-	REMOTE_SETHEAD_USAGE,
-	REMOTE_SHOW_USAGE,
-	REMOTE_PRUNE_USAGE,
-	REMOTE_UPDATE_USAGE,
+	remote_bare_usage,
+	remote_add_usage,
+	remote_rename_usage,
+	remote_rm_usage,
+	remote_sethead_usage,
+	remote_show_usage,
+	remote_prune_usage,
+	remote_update_usage,
 	NULL
 };
 
-static const char * const builtin_remote_add_usage[] = { REMOTE_ADD_USAGE, NULL };
-static const char * const builtin_remote_rename_usage[] = { REMOTE_RENAME_USAGE, NULL };
-static const char * const builtin_remote_rm_usage[] = { REMOTE_RM_USAGE, NULL };
-static const char * const builtin_remote_sethead_usage[] = { REMOTE_SETHEAD_USAGE, NULL };
-static const char * const builtin_remote_show_usage[] = { REMOTE_SHOW_USAGE, NULL };
-static const char * const builtin_remote_prune_usage[] = { REMOTE_PRUNE_USAGE, NULL };
-static const char * const builtin_remote_update_usage[] = { REMOTE_UPDATE_USAGE, NULL };
+static const char * const builtin_remote_add_usage[] = { remote_add_usage, NULL };
+static const char * const builtin_remote_rename_usage[] = { remote_rename_usage, NULL };
+static const char * const builtin_remote_rm_usage[] = { remote_rm_usage, NULL };
+static const char * const builtin_remote_sethead_usage[] = { remote_sethead_usage, NULL };
+static const char * const builtin_remote_show_usage[] = { remote_show_usage, NULL };
+static const char * const builtin_remote_prune_usage[] = { remote_prune_usage, NULL };
+static const char * const builtin_remote_update_usage[] = { remote_update_usage, NULL };
 
 #define GET_REF_STATES (1<<0)
 #define GET_HEAD_NAMES (1<<1)
-- 
1.6.5.2
Previous: Jonathan NiederNext: Tim Henigan
Message 6 of 9 in “What's cooking in git.git (Nov 2009, #04; Tue, 17)”
  1. Junio C HamanoNov 18, 2009
  2. Tay Ray ChuanNov 18, 2009
  3. Johannes SixtNov 18, 2009
  4. Junio C HamanoNov 19, 2009
  5. th/remote-usageJonathan Nieder, Nov 18, 2009
  6. Jonathan NiederNov 18, 2009
  7. Tim HeniganNov 18, 2009
  8. Nguyen Thai Ngoc DuyNov 18, 2009
  9. Johannes SixtNov 18, 2009

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.