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

[PATCH 2/6] git-blame: --show-name (and -f)

From
Junio C Hamano <junkio@cox.net>
Date
Oct 5, 2006, 21:06 UTC
Message-ID
<7vmz8acw1d.fsf@assigned-by-dhcp.cox.net>

The new option makes the command's native output format show the filename even when there were no renames in its history, to make it simpler for Porcelains to parse its output.

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 blame.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/blame.c b/blame.c
index 394b5c3..d830b29 100644
--- a/blame.c
+++ b/blame.c
@@ -752,7 +752,7 @@ int main(int argc, const char **argv)
 	const char *buf;
 	int max_digits;
 	int longest_file, longest_author;
-	int found_rename;
+	int show_name = 0;
 
 	const char *prefix = setup_git_directory();
 	git_config(git_default_config);
@@ -786,6 +786,11 @@ int main(int argc, const char **argv)
 				}
 				usage(blame_usage);
 			}
+			if (!strcmp(argv[i], "-f") ||
+			    !strcmp(argv[i], "--show-name")) {
+				show_name = 1;
+				continue;
+			}
 			if (!strcmp(argv[i], "--")) {
 				options = 0;
 				continue;
@@ -853,7 +858,6 @@ int main(int argc, const char **argv)
 
 	longest_file = 0;
 	longest_author = 0;
-	found_rename = 0;
 	for (i = 0; i < num_blame_lines; i++) {
 		struct commit *c = blame_lines[i];
 		struct util_info *u;
@@ -861,8 +865,8 @@ int main(int argc, const char **argv)
 			c = initial;
 		u = c->util;
 
-		if (!found_rename && strcmp(filename, u->pathname))
-			found_rename = 1;
+		if (!show_name && strcmp(filename, u->pathname))
+			show_name = 1;
 		if (longest_file < strlen(u->pathname))
 			longest_file = strlen(u->pathname);
 		get_commit_info(c, &ci);
@@ -886,7 +890,7 @@ int main(int argc, const char **argv)
 			       i+1);
 		}
 		else {
-			if (found_rename)
+			if (show_name)
 				printf(" %-*.*s", longest_file, longest_file,
 				       u->pathname);
 			printf(" (%-*.*s %10s %*d) ",
-- 
1.4.2.3.g866f3
Message 1 of 1 in “git-blame: --show-name (and -f)”
  1. 2/6 git-blame: --show-name (and -f)Junio C Hamano, Oct 5, 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.