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

Re: [PATCH v3 3/4] commit.c: replace some literal strings with constants

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Feb 17, 2011, 05:19 UTC
Message-ID
<20110217051919.GA7740@elie>
In-Reply-To
<1297916325-89688-4-git-send-email-jaysoffian@gmail.com>
Jay Soffian wrote:
Show 5 quoted lines
> I converted these per
> http://article.gmane.org/gmane.comp.version-control.git/167015
>
> Maybe this should be the last patch in the series; it's questionable to
> me whether it's even worth doing.
What have I wrought?  I think this makes the code much less readable.
Show 12 quoted lines
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -626,13 +632,13 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
>  		format_commit_message(commit, "fixup! %s\n\n",
>  				      &sb, &ctx);
>  		hook_arg1 = "message";
> -	} else if (!stat(git_path("MERGE_MSG"), &statbuf)) {
> -		if (strbuf_read_file(&sb, git_path("MERGE_MSG"), 0) < 0)
> -			die_errno("could not read MERGE_MSG");
> +	} else if (!stat(git_path(merge_msg), &statbuf)) {
> +		if (strbuf_read_file(&sb, git_path(merge_msg), 0) < 0)
> +			die_errno("could not read %s", merge_msg);

So now a person needs to look earlier in the file to see that merge_msg means "MERGE_MSG" rather than being something that can vary.

Yes, commit_editmsg has the same problem. If I get to choose[*] then cache.h would contain something like

	#define MERGE_HEAD_FILE "MERGE_HEAD"
	#define PREPARED_COMMIT_MESSAGE_FILE "MERGE_MSG"
	#define <description of SQUASH_MSG goes here> "SQUASH_MSG"
and commit.c or cache.h would contain something like
	#define EDITABLE_COMMIT_MESSAGE_FILE "COMMIT_EDITMSG"

and those symbolic names would be used throughout builtin code to name those files. So we would get

 (1) documentation of what filenames are special to git, collected
     in one place
 (2) protection against typos
without losing
 (3) names that look like constants
Jonathan

[*] and I shouldn't! What I like should matter much less than what is right.

Previous: Jay SoffianNext: Jay Soffian
Message 13 of 17 in “CHERRY_PICK_HEAD”
  1. 0/4 CHERRY_PICK_HEADJay Soffian, Feb 17, 2011
  2. 1/4 Introduce CHERRY_PICK_HEADJay Soffian, Feb 17, 2011
  3. Junio C HamanoFeb 17, 2011
  4. Jonathan NiederFeb 17, 2011
  5. Jay SoffianFeb 20, 2011
  6. Jonathan NiederFeb 20, 2011
  7. Junio C HamanoFeb 20, 2011
  8. Junio C HamanoFeb 17, 2011
  9. Jay SoffianFeb 17, 2011
  10. Jonathan NiederFeb 17, 2011
  11. 2/4 bash: teach __git_ps1 about CHERRY_PICK_HEADJay Soffian, Feb 17, 2011
  12. 3/4 commit.c: replace some literal strings with constantsJay Soffian, Feb 17, 2011
  13. Jonathan NiederFeb 17, 2011
  14. Teach commit about CHERRY_PICK_HEADJay Soffian, Feb 17, 2011
  15. Jonathan NiederFeb 18, 2011
  16. Junio C HamanoFeb 17, 2011
  17. 4/4 Teach commit about CHERRY_PICK_HEADJay Soffian, Feb 17, 2011

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.