From patchwork Fri Apr 21 22:30:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Keller X-Patchwork-Id: 13220748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77554C77B7F for ; Fri, 21 Apr 2023 22:30:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233821AbjDUWa1 (ORCPT ); Fri, 21 Apr 2023 18:30:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233591AbjDUWaY (ORCPT ); Fri, 21 Apr 2023 18:30:24 -0400 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB9441BF5 for ; Fri, 21 Apr 2023 15:30:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1682116223; x=1713652223; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=UCoDuds6VVa9GHIu2e0l/huwb1xLJeOydSd3csLBhzA=; b=MLoMmkA5B7PUjIn++erCBjr7YTXpjqIEPSJ9WAwwBTFZ1LpQdT6F2v3p jc6opaK0M1ZxBxvg+zQDj9GlscsJokJe1LzJUOfbLwi12sROXxvbX1pSV idpMPQgWVK8AWLoy5rBdX7fCcY2JOhLlK3Ji+6U++GBkRYMl6kactVaDV xNNX/YnhVbal4gJh58HudoeaNxlIMGL8Rk6uy4dIgDXWlhYBI08zL2Lw1 BCFAbjo8q66czMGLiGhoUqccDfByjrL6z3C7K+eh3vtLund4IXEQtdTNE OCXhem4e/MRRjMKDfQfodxRXcjDphjgvde6aQiPWTytSkg0CHsbt8T80H w==; X-IronPort-AV: E=McAfee;i="6600,9927,10687"; a="325693229" X-IronPort-AV: E=Sophos;i="5.99,216,1677571200"; d="scan'208";a="325693229" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2023 15:30:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10687"; a="722912529" X-IronPort-AV: E=Sophos;i="5.99,216,1677571200"; d="scan'208";a="722912529" Received: from jekeller-desk.amr.corp.intel.com (HELO jekeller-desk.jekeller.internal) ([10.166.241.1]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Apr 2023 15:30:22 -0700 From: Jacob Keller To: git@vger.kernel.org Cc: Jacob Keller , Junio C Hamano , Glen Choo Subject: [PATCH] blame: use different author name for fake commit generated by --contents Date: Fri, 21 Apr 2023 15:30:13 -0700 Message-ID: <20230421223013.467142-1-jacob.e.keller@intel.com> X-Mailer: git-send-email 2.40.0.471.gbd7f14d9353b MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jacob Keller 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 Suggested-by: Glen Choo Signed-off-by: Jacob Keller --- 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 :: - Pretend the file being annotated has a commit with the - contents from the named file and a parent of , - defaulting to HEAD when no 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 + if it is specified, and HEAD otherwise. You may specify '-' to make + the command read from the standard input for the file contents. --date :: 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..859693949b94 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" >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)' '