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

Re: Fixes for option parsing

From
Linus Torvalds <torvalds@osdl.org>
Date
Apr 17, 2006, 03:03 UTC
Message-ID
<Pine.LNX.4.64.0604161952500.3701@g5.osdl.org>
In-Reply-To
<Pine.LNX.4.64.0604161938070.3701@g5.osdl.org>
On Sun, 16 Apr 2006, Linus Torvalds wrote:
> 
> Maybe. I'm not convinced, though. The reason? cmd_log_wc needs to generate 
> it regardless, for the "always" case.

Of course, you could just have the "diff" logic unconditionally do the call-back. That would be clean enough.

> Also, I think the "---" printing should be removed, and moved into the 
> "diffstat" flushing code. Right now it does the wrong thing entirely if 
> no diff exists, but we have always_show_header: it will print the "---" 
> for no good reason.

The alternative is to do something like this, but because the "diffstat" doesn't flush the header priperly, it doesn't add the "---" for merges (and it used to not show the log at all, even for "git log", before I fixed it).

Try it with
	git log --cc --patch-with-stat
to see what I mean.

I do agree that this would be much cleaner with a "print header" callback in the diffopt structure. This patch is the really hacky "continue to do things the ugly way" approach to fix some of the uglier output.

Only meant as a RFC and to illustrate what I think the output should look like (modulo the lack of "---" before a diffstat with no patch - for merges). Not meant to actually be applied, I think this can be done much more cleanly with the callback.

		Linus
---
diff --git a/git.c b/git.c
index fc4e429..dc577fa 100644
--- a/git.c
+++ b/git.c
@@ -284,7 +284,7 @@ static int cmd_log_wc(int argc, const ch
 	struct commit *commit;
 	char *buf = xmalloc(LOGSIZE);
 	const char *commit_prefix = "commit ";
-	int shown = 0;
+	int shown = 0, always_show_header;
 
 	rev->abbrev = DEFAULT_ABBREV;
 	rev->commit_format = CMIT_FMT_DEFAULT;
@@ -295,13 +295,19 @@ static int cmd_log_wc(int argc, const ch
 	if (rev->commit_format == CMIT_FMT_ONELINE)
 		commit_prefix = "";
 
+	/*
+	 * We handle always_show_header outselves, and leave the
+	 * "---" handling to log_tree_commit
+	 */
+	always_show_header = rev->always_show_header;
+	rev->always_show_header = 0;
+
 	prepare_revision_walk(rev);
 	setup_pager();
 	while ((commit = get_revision(rev)) != NULL) {
 		unsigned long ofs = 0;
 
-		if (shown && rev->diff &&
-		    rev->commit_format != CMIT_FMT_ONELINE)
+		if (shown && rev->commit_format != CMIT_FMT_ONELINE)
 			putchar('\n');
 
 		ofs = sprintf(buf, "%s", commit_prefix);
@@ -338,14 +344,16 @@ static int cmd_log_wc(int argc, const ch
 					   buf + ofs,
 					   LOGSIZE - ofs - 20,
 					   rev->abbrev);
+		if (always_show_header || !rev->diff) {
+			fputs(buf, stdout);
+			ofs = 0;
+		}
 
 		if (rev->diff) {
+			strcpy(buf + ofs, rev->diffopt.with_stat ? "---" : "\n");
 			rev->use_precomputed_header = buf;
-			strcpy(buf + ofs, "\n---\n");
 			log_tree_commit(rev, commit);
 		}
-		else
-			printf("%s\n", buf);
 		shown = 1;
 		free(commit->buffer);
 		commit->buffer = NULL;
Previous: Linus TorvaldsNext: Junio C Hamano
Message 4 of 18 in “Fixes for option parsing”
  1. Linus TorvaldsApr 16, 2006
  2. Junio C HamanoApr 17, 2006
  3. Linus TorvaldsApr 17, 2006
  4. Linus TorvaldsApr 17, 2006
  5. Junio C HamanoApr 17, 2006
  6. Linus TorvaldsApr 17, 2006
  7. Log message printout cleanupsLinus Torvalds, Apr 17, 2006
  8. Junio C HamanoApr 17, 2006
  9. Linus TorvaldsApr 17, 2006
  10. Junio C HamanoApr 18, 2006
  11. Junio C HamanoApr 18, 2006
  12. Linus TorvaldsApr 18, 2006
  13. Junio C HamanoApr 18, 2006
  14. Linus TorvaldsApr 18, 2006
  15. Linus TorvaldsApr 18, 2006
  16. Junio C HamanoApr 18, 2006
  17. diff --stat: make sure to set recursive.Junio C Hamano, Apr 18, 2006
  18. Linus TorvaldsApr 18, 2006

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.