{"thread":{"id":"59646","subject":"[PATCH] blame: use different author name for fake commit generated by --contents","startedAt":"2023-04-24T19:35:23Z","lastAt":"2023-04-24T19:36:25Z","messageCount":2,"participants":["Jacob Keller"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"475961","messageId":"20230424193508.2245566-1-jacob.e.keller@intel.com","threadId":"59646","inReplyTo":null,"subject":"[PATCH] blame: use different author name for fake commit generated by --contents","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2023-04-24T19:35:08Z","receivedAt":"2023-04-24T19:35:23Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"From: Jacob Keller <jacob.keller@gmail.com>\n\nWhen the --contents option is used with git blame, and the contents of\nthe file have lines which can't be annotated by the history being\nblamed, the user will see an author of \"Not Committed Yet\". This is\nsimilar to the way blame handles working tree contents when blaming\nwithout a revision.\n\nThis is slightly confusing since this data isn't the working copy and\nwhile it is technically \"not committed yet\", its also coming from an\nexternal file. Replace this author name with \"External file\n(--contents)\" to better differentiate such lines from actual working\ncopy lines.\n\nSuggested-by: Junio C Hamano <gitster@pobox.com>\nSuggested-by: Glen Choo <chooglen@google.com>\nSigned-off-by: Jacob Keller <jacob.keller@gmail.com>\n---\nChanges since v2\n* Fix the test case to pass and align with the other similar test cases\n\n Documentation/blame-options.txt |  8 +++-----\n blame.c                         |  8 ++++++--\n t/annotate-tests.sh             | 11 +++++++++--\n 3 files changed, 18 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/blame-options.txt b/Documentation/blame-options.txt\nindex 95599bd6e5f4..552dcc60f2a4 100644\n--- a/Documentation/blame-options.txt\n+++ b/Documentation/blame-options.txt\n@@ -64,11 +64,9 @@ include::line-range-format.txt[]\n \tmanual page.\n \n --contents <file>::\n-\tPretend the file being annotated has a commit with the\n-\tcontents from the named file and a parent of <rev>,\n-\tdefaulting to HEAD when no <rev> is specified. You may\n-\tspecify '-' to make the command read from the standard\n-\tinput for the file contents.\n+\tAnnotate using the contents from the named file, starting from <rev>\n+\tif it is specified, and HEAD otherwise. You may specify '-' to make\n+\tthe command read from the standard input for the file contents.\n \n --date <format>::\n \tSpecifies the format used to output dates. If --date is not\ndiff --git a/blame.c b/blame.c\nindex 2c427bcdbfdd..47dd77d045dc 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -206,8 +206,12 @@ static struct commit *fake_working_tree_commit(struct repository *r,\n \n \torigin = make_origin(commit, path);\n \n-\tident = fmt_ident(\"Not Committed Yet\", \"not.committed.yet\",\n-\t\t\tWANT_BLANK_IDENT, NULL, 0);\n+\tif (contents_from)\n+\t\tident = fmt_ident(\"External file (--contents)\", \"external.file\",\n+\t\t\t\t  WANT_BLANK_IDENT, NULL, 0);\n+\telse\n+\t\tident = fmt_ident(\"Not Committed Yet\", \"not.committed.yet\",\n+\t\t\t\t  WANT_BLANK_IDENT, NULL, 0);\n \tstrbuf_addstr(&msg, \"tree 0000000000000000000000000000000000000000\\n\");\n \tfor (parent = commit->parents; parent; parent = parent->next)\n \t\tstrbuf_addf(&msg, \"parent %s\\n\",\ndiff --git a/t/annotate-tests.sh b/t/annotate-tests.sh\nindex b35be20cf327..2ef70235b101 100644\n--- a/t/annotate-tests.sh\n+++ b/t/annotate-tests.sh\n@@ -72,6 +72,13 @@ test_expect_success 'blame 1 author' '\n \tcheck_count A 2\n '\n \n+test_expect_success 'blame working copy' '\n+\ttest_when_finished \"git restore file\" &&\n+\techo \"1A quick brown fox jumps over the\" >file &&\n+\techo \"another lazy dog\" >>file &&\n+\tcheck_count A 1 \"Not Committed Yet\" 1\n+'\n+\n test_expect_success 'blame with --contents' '\n \tcheck_count --contents=file A 2\n '\n@@ -79,7 +86,7 @@ test_expect_success 'blame with --contents' '\n test_expect_success 'blame with --contents changed' '\n \techo \"1A quick brown fox jumps over the\" >contents &&\n \techo \"another lazy dog\" >>contents &&\n-\tcheck_count --contents=contents A 1 \"Not Committed Yet\" 1\n+\tcheck_count --contents=contents A 1 \"External file (--contents)\" 1\n '\n \n test_expect_success 'blame in a bare repo without starting commit' '\n@@ -109,7 +116,7 @@ test_expect_success 'blame 2 authors' '\n '\n \n test_expect_success 'blame with --contents and revision' '\n-\tcheck_count -h testTag --contents=file A 2 \"Not Committed Yet\" 2\n+\tcheck_count -h testTag --contents=file A 2 \"External file (--contents)\" 2\n '\n \n test_expect_success 'setup B1 lines (branch1)' '\n-- \n2.40.0.471.gbd7f14d9353b\n\n"},{"id":"475962","messageId":"c4a99e9c-46c5-31fe-5004-2d741a5bc8a0@intel.com","threadId":"59646","inReplyTo":"20230424193508.2245566-1-jacob.e.keller@intel.com","subject":"Re: [PATCH] blame: use different author name for fake commit generated by --contents","fromName":"Jacob Keller","fromEmail":"jacob.e.keller@intel.com","sentAt":"2023-04-24T19:36:16Z","receivedAt":"2023-04-24T19:36:25Z","isPatch":true,"sender":{"key":"jacob.e.keller@intel.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"\n\nOn 4/24/2023 12:35 PM, Jacob Keller wrote:\n> From: Jacob Keller <jacob.keller@gmail.com>\n> \n\nApologies but I forgot to add -v2 when formatting this patch, so the\nsubject really should be [PATCH v2].\n\nThanks,\nJake\n"}]}