submodule--helper: refactor "errmsg_str" to be a "struct strbuf"
Refactor code added in e83e3333b5
(submodule: port submodule
subcommand 'summary' from shell to C, 2020-08-13) so that "errmsg" and
"errmsg_str" are folded into one. The distinction between the empty
string and NULL is something that's tested for by
e.g. "t/t7401-submodule-summary.sh".
This is in preparation for fixing a memory leak the "struct strbuf" in
the pre-image.
Let's also pass a "const char *" to print_submodule_summary(), as it
should not be modifying the "errmsg".
Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Reviewed-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
a253be682f
commit
9d02f9499f
@ -761,7 +761,7 @@ static char *verify_submodule_committish(const char *sm_path,
|
|||||||
return strbuf_detach(&result, NULL);
|
return strbuf_detach(&result, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void print_submodule_summary(struct summary_cb *info, char *errmsg,
|
static void print_submodule_summary(struct summary_cb *info, const char *errmsg,
|
||||||
int total_commits, const char *displaypath,
|
int total_commits, const char *displaypath,
|
||||||
const char *src_abbrev, const char *dst_abbrev,
|
const char *src_abbrev, const char *dst_abbrev,
|
||||||
struct module_cb *p)
|
struct module_cb *p)
|
||||||
@ -819,7 +819,7 @@ static void generate_submodule_summary(struct summary_cb *info,
|
|||||||
{
|
{
|
||||||
char *displaypath, *src_abbrev = NULL, *dst_abbrev;
|
char *displaypath, *src_abbrev = NULL, *dst_abbrev;
|
||||||
int missing_src = 0, missing_dst = 0;
|
int missing_src = 0, missing_dst = 0;
|
||||||
char *errmsg = NULL;
|
struct strbuf errmsg = STRBUF_INIT;
|
||||||
int total_commits = -1;
|
int total_commits = -1;
|
||||||
|
|
||||||
if (!info->cached && oideq(&p->oid_dst, null_oid())) {
|
if (!info->cached && oideq(&p->oid_dst, null_oid())) {
|
||||||
@ -920,23 +920,21 @@ static void generate_submodule_summary(struct summary_cb *info,
|
|||||||
* submodule, i.e., deleted or changed to blob
|
* submodule, i.e., deleted or changed to blob
|
||||||
*/
|
*/
|
||||||
if (S_ISGITLINK(p->mod_dst)) {
|
if (S_ISGITLINK(p->mod_dst)) {
|
||||||
struct strbuf errmsg_str = STRBUF_INIT;
|
|
||||||
if (missing_src && missing_dst) {
|
if (missing_src && missing_dst) {
|
||||||
strbuf_addf(&errmsg_str, " Warn: %s doesn't contain commits %s and %s\n",
|
strbuf_addf(&errmsg, " Warn: %s doesn't contain commits %s and %s\n",
|
||||||
displaypath, oid_to_hex(&p->oid_src),
|
displaypath, oid_to_hex(&p->oid_src),
|
||||||
oid_to_hex(&p->oid_dst));
|
oid_to_hex(&p->oid_dst));
|
||||||
} else {
|
} else {
|
||||||
strbuf_addf(&errmsg_str, " Warn: %s doesn't contain commit %s\n",
|
strbuf_addf(&errmsg, " Warn: %s doesn't contain commit %s\n",
|
||||||
displaypath, missing_src ?
|
displaypath, missing_src ?
|
||||||
oid_to_hex(&p->oid_src) :
|
oid_to_hex(&p->oid_src) :
|
||||||
oid_to_hex(&p->oid_dst));
|
oid_to_hex(&p->oid_dst));
|
||||||
}
|
}
|
||||||
errmsg = strbuf_detach(&errmsg_str, NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print_submodule_summary(info, errmsg, total_commits,
|
print_submodule_summary(info, errmsg.len ? errmsg.buf : NULL,
|
||||||
displaypath, src_abbrev,
|
total_commits, displaypath, src_abbrev,
|
||||||
dst_abbrev, p);
|
dst_abbrev, p);
|
||||||
|
|
||||||
free(displaypath);
|
free(displaypath);
|
||||||
|
Loading…
Reference in New Issue
Block a user