All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jacob Keller <jacob.e.keller@intel.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Jacob Keller <jacob.keller@gmail.com>,
	Glen Choo <chooglen@google.com>
Subject: [PATCH] blame: use different author name for fake commit generated by --contents
Date: Mon, 24 Apr 2023 12:35:08 -0700	[thread overview]
Message-ID: <20230424193508.2245566-1-jacob.e.keller@intel.com> (raw)

From: Jacob Keller <jacob.keller@gmail.com>

When the --contents option is used with git blame, and the contents of
the file have lines which can't be annotated by the history being
blamed, the user will see an author of "Not Committed Yet". This is
similar to the way blame handles working tree contents when blaming
without a revision.

This is slightly confusing since this data isn't the working copy and
while it is technically "not committed yet", its also coming from an
external file. Replace this author name with "External file
(--contents)" to better differentiate such lines from actual working
copy lines.

Suggested-by: Junio C Hamano <gitster@pobox.com>
Suggested-by: Glen Choo <chooglen@google.com>
Signed-off-by: Jacob Keller <jacob.keller@gmail.com>
---
Changes since v2
* Fix the test case to pass and align with the other similar test cases

 Documentation/blame-options.txt |  8 +++-----
 blame.c                         |  8 ++++++--
 t/annotate-tests.sh             | 11 +++++++++--
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt
index 95599bd6e5f4..552dcc60f2a4 100644
--- a/Documentation/blame-options.txt
+++ b/Documentation/blame-options.txt
@@ -64,11 +64,9 @@ include::line-range-format.txt[]
 	manual page.
 
 --contents <file>::
-	Pretend the file being annotated has a commit with the
-	contents from the named file and a parent of <rev>,
-	defaulting to HEAD when no <rev> is specified. You may
-	specify '-' to make the command read from the standard
-	input for the file contents.
+	Annotate using the contents from the named file, starting from <rev>
+	if it is specified, and HEAD otherwise. You may specify '-' to make
+	the command read from the standard input for the file contents.
 
 --date <format>::
 	Specifies the format used to output dates. If --date is not
diff --git a/blame.c b/blame.c
index 2c427bcdbfdd..47dd77d045dc 100644
--- a/blame.c
+++ b/blame.c
@@ -206,8 +206,12 @@ static struct commit *fake_working_tree_commit(struct repository *r,
 
 	origin = make_origin(commit, path);
 
-	ident = fmt_ident("Not Committed Yet", "not.committed.yet",
-			WANT_BLANK_IDENT, NULL, 0);
+	if (contents_from)
+		ident = fmt_ident("External file (--contents)", "external.file",
+				  WANT_BLANK_IDENT, NULL, 0);
+	else
+		ident = fmt_ident("Not Committed Yet", "not.committed.yet",
+				  WANT_BLANK_IDENT, NULL, 0);
 	strbuf_addstr(&msg, "tree 0000000000000000000000000000000000000000\n");
 	for (parent = commit->parents; parent; parent = parent->next)
 		strbuf_addf(&msg, "parent %s\n",
diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh
index b35be20cf327..2ef70235b101 100644
--- a/t/annotate-tests.sh
+++ b/t/annotate-tests.sh
@@ -72,6 +72,13 @@ test_expect_success 'blame 1 author' '
 	check_count A 2
 '
 
+test_expect_success 'blame working copy' '
+	test_when_finished "git restore file" &&
+	echo "1A quick brown fox jumps over the" >file &&
+	echo "another lazy dog" >>file &&
+	check_count A 1 "Not Committed Yet" 1
+'
+
 test_expect_success 'blame with --contents' '
 	check_count --contents=file A 2
 '
@@ -79,7 +86,7 @@ test_expect_success 'blame with --contents' '
 test_expect_success 'blame with --contents changed' '
 	echo "1A quick brown fox jumps over the" >contents &&
 	echo "another lazy dog" >>contents &&
-	check_count --contents=contents A 1 "Not Committed Yet" 1
+	check_count --contents=contents A 1 "External file (--contents)" 1
 '
 
 test_expect_success 'blame in a bare repo without starting commit' '
@@ -109,7 +116,7 @@ test_expect_success 'blame 2 authors' '
 '
 
 test_expect_success 'blame with --contents and revision' '
-	check_count -h testTag --contents=file A 2 "Not Committed Yet" 2
+	check_count -h testTag --contents=file A 2 "External file (--contents)" 2
 '
 
 test_expect_success 'setup B1 lines (branch1)' '
-- 
2.40.0.471.gbd7f14d9353b


             reply	other threads:[~2023-04-24 19:35 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-24 19:35 Jacob Keller [this message]
2023-04-24 19:36 ` [PATCH] blame: use different author name for fake commit generated by --contents Jacob Keller
  -- strict thread matches above, loose matches on Subject: below --
2023-04-21 22:30 Jacob Keller
2023-04-21 23:34 ` Junio C Hamano
2023-04-22  0:11   ` Jacob Keller
2023-04-24 16:05     ` Junio C Hamano
2023-04-24 17:59     ` Glen Choo
2023-04-24 18:37       ` Jacob Keller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230424193508.2245566-1-jacob.e.keller@intel.com \
    --to=jacob.e.keller@intel.com \
    --cc=chooglen@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jacob.keller@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.