All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Tan <jonathantanmy@google.com>
To: git@vger.kernel.org
Cc: Jonathan Tan <jonathantanmy@google.com>,
	avarab@gmail.com, me@ttaylorr.com, gitster@pobox.com
Subject: [PATCH v2] ls-files: support --recurse-submodules --stage
Date: Wed, 23 Feb 2022 16:23:03 -0800	[thread overview]
Message-ID: <20220224002303.2363189-1-jonathantanmy@google.com> (raw)
In-Reply-To: <20220218223212.1139366-1-jonathantanmy@google.com>

e77aa336f1 ("ls-files: optionally recurse into submodules", 2016-10-10)
taught ls-files the --recurse-submodules argument, but only in a limited
set of circumstances. In particular, --stage was unsupported, perhaps
because there was no repo_find_unique_abbrev(), which was only
introduced in 8bb95572b0 ("sha1-name.c: add
repo_find_unique_abbrev_r()", 2019-04-16). This function is needed for
using --recurse-submodules with --stage.

Now that we have repo_find_unique_abbrev(), teach support for this
combination of arguments.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
Here's version 2 with an updated test.
---
Range-diff against v1:
1:  d61268bcc8 ! 1:  17f3f77b86 ls-files: support --recurse-submodules --stage
    @@ Commit message
     
         Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
         ---
    -    I got the similar-hashing object contents from Ævar's work in [1].
    -
    -    [1] https://lore.kernel.org/git/patch-v7-1.6-28c01b7f8a5-20220111T130811Z-avarab@gmail.com/
    +    Here's version 2 with an updated test.
     
      ## Documentation/git-ls-files.txt ##
     @@ Documentation/git-ls-files.txt: a space) at the start of each line:
    @@ t/t3007-ls-files-recurse-submodules.sh: test_expect_success 'ls-files correctly
      '
      
     +test_expect_success '--stage' '
    -+	# In order to test hash abbreviation, write two objects that have the
    -+	# same first 4 hexadecimal characters in their (SHA-1) hashes.
    -+	echo brocdnra >submodule/c &&
    -+	git -C submodule commit -am "update c" &&
    -+	echo brigddsv >submodule/c &&
    -+	git -C submodule commit -am "update c again" &&
    ++	GITMODULES_HASH=$(git rev-parse HEAD:.gitmodules) &&
    ++	A_HASH=$(git rev-parse HEAD:a) &&
    ++	B_HASH=$(git rev-parse HEAD:b/b) &&
    ++	C_HASH=$(git -C submodule rev-parse HEAD:c) &&
     +
    -+	cat >expect <<-\EOF &&
    -+	100644 6da7 0	.gitmodules
    -+	100644 7898 0	a
    -+	100644 6178 0	b/b
    -+	100644 dead9 0	submodule/c
    ++	cat >expect <<-EOF &&
    ++	100644 $GITMODULES_HASH 0	.gitmodules
    ++	100644 $A_HASH 0	a
    ++	100644 $B_HASH 0	b/b
    ++	100644 $C_HASH 0	submodule/c
     +	EOF
     +
    -+	git ls-files --stage --recurse-submodules --abbrev=4 >actual &&
    ++	git ls-files --stage --recurse-submodules >actual &&
     +	test_cmp expect actual
     +'
     +

 Documentation/git-ls-files.txt         |  2 +-
 builtin/ls-files.c                     |  4 ++--
 t/t3007-ls-files-recurse-submodules.sh | 18 +++++++++++++++++-
 3 files changed, 20 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt
index 48cc7c0b6f..0dabf3f0dd 100644
--- a/Documentation/git-ls-files.txt
+++ b/Documentation/git-ls-files.txt
@@ -156,7 +156,7 @@ a space) at the start of each line:
 
 --recurse-submodules::
 	Recursively calls ls-files on each active submodule in the repository.
-	Currently there is only support for the --cached mode.
+	Currently there is only support for the --cached and --stage modes.
 
 --abbrev[=<n>]::
 	Instead of showing the full 40-byte hexadecimal object
diff --git a/builtin/ls-files.c b/builtin/ls-files.c
index f7ea56cc63..e791b65e7e 100644
--- a/builtin/ls-files.c
+++ b/builtin/ls-files.c
@@ -244,7 +244,7 @@ static void show_ce(struct repository *repo, struct dir_struct *dir,
 			printf("%s%06o %s %d\t",
 			       tag,
 			       ce->ce_mode,
-			       find_unique_abbrev(&ce->oid, abbrev),
+			       repo_find_unique_abbrev(repo, &ce->oid, abbrev),
 			       ce_stage(ce));
 		}
 		write_eolinfo(repo->index, ce, fullname);
@@ -726,7 +726,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
 		setup_work_tree();
 
 	if (recurse_submodules &&
-	    (show_stage || show_deleted || show_others || show_unmerged ||
+	    (show_deleted || show_others || show_unmerged ||
 	     show_killed || show_modified || show_resolve_undo || with_tree))
 		die("ls-files --recurse-submodules unsupported mode");
 
diff --git a/t/t3007-ls-files-recurse-submodules.sh b/t/t3007-ls-files-recurse-submodules.sh
index 4a08000713..dd7770e85d 100755
--- a/t/t3007-ls-files-recurse-submodules.sh
+++ b/t/t3007-ls-files-recurse-submodules.sh
@@ -34,6 +34,23 @@ test_expect_success 'ls-files correctly outputs files in submodule' '
 	test_cmp expect actual
 '
 
+test_expect_success '--stage' '
+	GITMODULES_HASH=$(git rev-parse HEAD:.gitmodules) &&
+	A_HASH=$(git rev-parse HEAD:a) &&
+	B_HASH=$(git rev-parse HEAD:b/b) &&
+	C_HASH=$(git -C submodule rev-parse HEAD:c) &&
+
+	cat >expect <<-EOF &&
+	100644 $GITMODULES_HASH 0	.gitmodules
+	100644 $A_HASH 0	a
+	100644 $B_HASH 0	b/b
+	100644 $C_HASH 0	submodule/c
+	EOF
+
+	git ls-files --stage --recurse-submodules >actual &&
+	test_cmp expect actual
+'
+
 test_expect_success 'ls-files correctly outputs files in submodule with -z' '
 	lf_to_nul >expect <<-\EOF &&
 	.gitmodules
@@ -292,7 +309,6 @@ test_incompatible_with_recurse_submodules () {
 test_incompatible_with_recurse_submodules --deleted
 test_incompatible_with_recurse_submodules --modified
 test_incompatible_with_recurse_submodules --others
-test_incompatible_with_recurse_submodules --stage
 test_incompatible_with_recurse_submodules --killed
 test_incompatible_with_recurse_submodules --unmerged
 
-- 
2.35.1.574.g5d30c73bfb-goog


      parent reply	other threads:[~2022-02-24  0:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-18 22:32 [PATCH] ls-files: support --recurse-submodules --stage Jonathan Tan
2022-02-19  0:33 ` Junio C Hamano
2022-02-19  3:11 ` Ævar Arnfjörð Bjarmason
2022-02-19  3:50   ` Taylor Blau
2022-02-21 18:19   ` Junio C Hamano
2022-02-21 18:51     ` Ævar Arnfjörð Bjarmason
2022-02-24  0:11       ` Jonathan Tan
2022-02-21  1:48 ` Junio C Hamano
2022-02-21  2:45   ` Taylor Blau
2022-02-24  0:23 ` Jonathan Tan [this message]

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=20220224002303.2363189-1-jonathantanmy@google.com \
    --to=jonathantanmy@google.com \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=me@ttaylorr.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.