Re: [PATCH v3 4/4] submodule: port submodule subcommand 'summary' from shell to C

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 2020-08-21 at 12:54 -0700, Junio C Hamano wrote:
> Kaartic Sivaraam <kaartic.sivaraam@xxxxxxxxx> writes:
> 
> > Here's the error message with context of the trash directory of that
> > test:
> > 
> > -- 8< --
> > $ cd t
> > $ ./t7421-submodule-summary-add.sh  -d
> > $ cd trash\ directory.t7421-submodule-summary-add/
> > 
> > $ git submodule summary HEAD^^
> > fatal: exec 'rev-parse': cd to 'my-subm' failed: No such file or directory
> > * my-subm 35b40f1...0000000:
> > 
> > * subm 0000000...dbd5fc8 (2):
> >   > add file2
> > 
> > -- >8 --
> > 
> > That 'fatal' is a consequence of spawning a process in
> > `verify_submodule_committish` of `builtin/submodule--helper.c` even for
> > non-existent submodules.
> 
> Oh, so doing something that would cause the error message to be
> emitted itself is a bug.
> 

Exactly.

> > I don't think that 'fatal: ' message is giving
> > any useful information here. The fact that submodule 'my-subm' doesn't
> > exist can easily be inferred just by looking at the destination mode
> > (0000000). If anything that 'fatal' message is just confusing and
> > unnecessary, IMO.
> 
> Yes, I 100% agree.
> 
> > So, we could easily suppress it by doing something like this (while
> > also fixing the test):
> 
> Yup.  That is a very good idea.  
> 
> Or the caller of verify_submodule_committish() should refrain from
> calling it for the path?  After all, it is checking sm_path is a
> path to where a submodule should be before calling the function
> (instead of calling it for every random path), iow its criteria to
> make the call currently may be "the path in the index says it is a
> submodule", but it should easily be updated to "the path in the
> index says it is a submodule, and the submodule actually is
> populated", right?
> 

Ah, this reminds me of the initial version of the patch which did
exactly that. Quoting it here for reference:

+	strbuf_addstr(&sm_git_dir_sb, p->sm_path);
+	if (is_nonbare_repository_dir(&sm_git_dir_sb))
+		is_sm_git_dir = 1;
+
+	if (is_sm_git_dir && S_ISGITLINK(p->mod_src))
+		missing_src = verify_submodule_object_name(p->sm_path,
+							   oid_to_hex(&p->oid_src));
+
+	if (is_sm_git_dir && S_ISGITLINK(p->mod_dst))
+		missing_dst = verify_submodule_object_name(p->sm_path,
+							   oid_to_hex(&p->oid_dst));
+

Note: `verify_submodule_object_name` is now renamed to
`verify_submodule_committish`.

That does sound like a sane approach to me. There's not much point in
invoking `rev-parse` in a non-populated (a.k.a. de-initialized) or non-
existent submodule but we removed that check as we thought it was
unnecessary redundant because `capture_command` would fail anyway.
Looks like we failed to notice the additional `fatal` message fallout
then.

Also, I think it would be better to something like the following in
t7421 to ensure that `fatal` doesn't sneak up accidentally in the
future:

-- 8< --
diff --git t/t7421-submodule-summary-add.sh t/t7421-submodule-summary-add.sh
index 59a9b00467..b070f13714 100755
--- t/t7421-submodule-summary-add.sh
+++ t/t7421-submodule-summary-add.sh
@@ -58,7 +58,7 @@ test_expect_success 'submodule summary output for submodules with changed paths'
        git commit -m "change submodule path" &&
        rev=$(git -C sm rev-parse --short HEAD^) &&
        git submodule summary HEAD^^ -- my-subm >actual 2>err &&
-       grep "fatal:.*my-subm" err &&
+       test_must_be_empty err &&
        cat >expected <<-EOF &&
        * my-subm ${rev}...0000000:
 
-- >8 --

-- 
Sivaraam





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux