Re: [PATCH v3 4/4] submodule: port submodule subcommand 'summary' from shell to C
- From
Shourya Shukla <shouryashukla.oo@gmail.com>
- Date
- Aug 24, 2020, 08:46 UTC
- Message-ID
- <20200824084634.GA377527@konoha>
- In-Reply-To
- <20200824072633.GA38870@konoha>
Or rather, we can do this:
-----8<-----
if (S_ISGITLINK(p->mod_src)) {
struct strbuf sb = STRBUF_INIT;
strbuf_addstr(&sb, p->sm_path);
if (is_nonbare_repository_dir(&sb))
src_abbrev = verify_submodule_committish(p->sm_path,
oid_to_hex(&p->oid_src));
strbuf_release(&sb);
if (!src_abbrev) {
missing_src = 1;
/*
* As `rev-parse` failed, we fallback to getting
* the abbreviated hash using oid_src. We do
* this as we might still need the abbreviated
* hash in cases like a submodule type change, etc.
*/
src_abbrev = xstrndup(oid_to_hex(&p->oid_src), 7);
}
} else {
/*
* The source does not point to a submodule.
* So, we fallback to getting the abbreviation using
* oid_src as we might still need the abbreviated
* hash in cases like submodule add, etc.
*/
src_abbrev = xstrndup(oid_to_hex(&p->oid_src), 7);
}
----->8-----Similarly for dst as well. This solution passes all the tests and does not call 'verify_submodule_committish()' all the time. The previous approach failed a couple of tests, this one seems fine to me.
How is this one?