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 <peff@peff.net> Helped-by: Junio C Hamano <gitster@pobox.com> Mentored-by: Christian Couder <christian.couder@gmail.com> Mentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Karthik Nayak committed Sep 24, 2015 at 23:39 UTC ca41799068e101e908544d4e2000a747b1389ebc
1 file changed +4 -14
builtin/branch.c
+4 -14
@@ -313,7 +313,6 @@ static char *resolve_symref(const char *src, const char *prefix)
313 struct append_ref_cb {
314 struct ref_list *ref_list;
315 const char **pattern;
316 - int ret;
316 };
317
318 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
369 commit = NULL;
370 if (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {
371 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)
373 return 0;
376 - }
374
375 /* Filter with with_commit if specified */
376 if (!is_descendant_of(commit, ref_list->with_commit))
@@ -617,7 +614,7 @@ static int calc_maxwidth(struct ref_list *refs, int remote_bonus)
614 return max;
615 }
616
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)
618 {
619 int i;
620 struct append_ref_cb cb;
@@ -642,7 +639,6 @@ static int print_ref_list(int kinds, int detached, int verbose, int abbrev, stru
639 init_revisions(&ref_list.revs, NULL);
640 cb.ref_list = &ref_list;
641 cb.pattern = pattern;
645 - cb.ret = 0;
642 /*
643 * First we obtain all regular branch refs and if the HEAD is
644 * 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
689 abbrev, detached, remote_prefix);
690
691 free_ref_list(&ref_list);
696 -
697 - if (cb.ret)
698 - error(_("some refs could not be read"));
699 -
700 - return cb.ret;
692 }
693
694 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)
904 die(_("branch name required"));
905 return delete_branches(argc, argv, delete > 1, kinds, quiet);
906 } else if (list) {
916 - int ret;
907 /* git branch --local also shows HEAD when it is detached */
908 if (kinds & REF_LOCAL_BRANCH)
909 kinds |= REF_DETACHED_HEAD;
920 - ret = print_ref_list(kinds, detached, verbose, abbrev,
910 + print_ref_list(kinds, detached, verbose, abbrev,
911 with_commit, argv);
912 print_columns(&output, colopts, NULL);
913 string_list_clear(&output, 0);
924 - return ret;
914 + return 0;
915 }
916 else if (edit_description) {
917 const char *branch_name;