Skip to content

Commit ca41799

Browse files
KarthikNayakgitster
authored andcommitted
branch: drop non-commit error reporting
Remove the error "branch '%s' does not point at a commit" in append_ref(), which reports branch refs which do not point to commits. Also remove the error "some refs could not be read" in print_ref_list() which is triggered as a consequence of the first error. The purpose of these codepaths is not to diagnose and report a repository corruption. If we care about such a corruption, we should report it from fsck instead, which we already do. This also helps in a smooth port of branch.c to use ref-filter APIs over the following patches. On the other hand, ref-filter ignores refs which do not point at commits silently. Based-on-patch-by: Jeff King <[email protected]> Helped-by: Junio C Hamano <[email protected]> Mentored-by: Christian Couder <[email protected]> Mentored-by: Matthieu Moy <[email protected]> Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f65f139 commit ca41799

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed

builtin/branch.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,6 @@ static char *resolve_symref(const char *src, const char *prefix)
313313
struct append_ref_cb {
314314
struct ref_list *ref_list;
315315
const char **pattern;
316-
int ret;
317316
};
318317

319318
static int match_patterns(const char **pattern, const char *refname)
@@ -370,10 +369,8 @@ static int append_ref(const char *refname, const struct object_id *oid, int flag
370369
commit = NULL;
371370
if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
372371
commit = lookup_commit_reference_gently(oid->hash, 1);
373-
if (!commit) {
374-
cb->ret = error(_("branch '%s' does not point at a commit"), refname);
372+
if (!commit)
375373
return 0;
376-
}
377374

378375
/* Filter with with_commit if specified */
379376
if (!is_descendant_of(commit, ref_list->with_commit))
@@ -617,7 +614,7 @@ static int calc_maxwidth(struct ref_list *refs, int remote_bonus)
617614
return max;
618615
}
619616

620-
static int print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char **pattern)
617+
static void print_ref_list(int kinds, int detached, int verbose, int abbrev, struct commit_list *with_commit, const char **pattern)
621618
{
622619
int i;
623620
struct append_ref_cb cb;
@@ -642,7 +639,6 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
642639
init_revisions(&ref_list.revs, NULL);
643640
cb.ref_list = &ref_list;
644641
cb.pattern = pattern;
645-
cb.ret = 0;
646642
/*
647643
* First we obtain all regular branch refs and if the HEAD is
648644
* detached then we insert that ref to the end of the ref_fist
@@ -693,11 +689,6 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
693689
abbrev, detached, remote_prefix);
694690

695691
free_ref_list(&ref_list);
696-
697-
if (cb.ret)
698-
error(_("some refs could not be read"));
699-
700-
return cb.ret;
701692
}
702693

703694
static void rename_branch(const char *oldname, const char *newname, int force)
@@ -913,15 +904,14 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
913904
die(_("branch name required"));
914905
return delete_branches(argc, argv, delete > 1, kinds, quiet);
915906
} else if (list) {
916-
int ret;
917907
/* git branch --local also shows HEAD when it is detached */
918908
if (kinds & REF_LOCAL_BRANCH)
919909
kinds |= REF_DETACHED_HEAD;
920-
ret = print_ref_list(kinds, detached, verbose, abbrev,
910+
print_ref_list(kinds, detached, verbose, abbrev,
921911
with_commit, argv);
922912
print_columns(&output, colopts, NULL);
923913
string_list_clear(&output, 0);
924-
return ret;
914+
return 0;
925915
}
926916
else if (edit_description) {
927917
const char *branch_name;

0 commit comments

Comments
 (0)