From: Junio C Hamano Date: Fri, 4 Sep 2015 02:18:03 +0000 (-0700) Subject: Merge branch 'jk/log-missing-default-HEAD' into maint X-Git-Tag: v2.5.2~3 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/5af77d13529a332bef99d22d0d983d5378edf534?ds=inline;hp=-c Merge branch 'jk/log-missing-default-HEAD' into maint "git init empty && git -C empty log" said "bad default revision 'HEAD'", which was found to be a bit confusing to new users. * jk/log-missing-default-HEAD: log: diagnose empty HEAD more clearly --- 5af77d13529a332bef99d22d0d983d5378edf534 diff --combined revision.c index ab97ffd459,734494abe6..9b9d77dc43 --- a/revision.c +++ b/revision.c @@@ -361,8 -361,8 +361,8 @@@ static int everybody_uninteresting(stru list = list->next; if (commit->object.flags & UNINTERESTING) continue; - if (interesting_cache) - *interesting_cache = commit; + + *interesting_cache = commit; return 0; } return 1; @@@ -817,7 -817,7 +817,7 @@@ static int add_parents_to_list(struct r parent = parent->next; if (p) p->object.flags |= UNINTERESTING; - if (parse_commit(p) < 0) + if (parse_commit_gently(p, 1) < 0) continue; if (p->parents) mark_parents_uninteresting(p); @@@ -844,7 -844,7 +844,7 @@@ for (parent = commit->parents; parent; parent = parent->next) { struct commit *p = parent->item; - if (parse_commit(p) < 0) + if (parse_commit_gently(p, revs->ignore_missing_links) < 0) return -1; if (revs->show_source && !p->util) p->util = commit->util; @@@ -1218,8 -1218,7 +1218,8 @@@ int ref_excluded(struct string_list *re return 0; } -static int handle_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int handle_one_ref(const char *path, const struct object_id *oid, + int flag, void *cb_data) { struct all_refs_cb *cb = cb_data; struct object *object; @@@ -1227,9 -1226,9 +1227,9 @@@ if (ref_excluded(cb->all_revs->ref_excludes, path)) return 0; - object = get_reference(cb->all_revs, path, sha1, cb->all_flags); + object = get_reference(cb->all_revs, path, oid->hash, cb->all_flags); add_rev_cmdline(cb->all_revs, object, path, REV_CMD_REF, cb->all_flags); - add_pending_sha1(cb->all_revs, path, sha1, cb->all_flags); + add_pending_sha1(cb->all_revs, path, oid->hash, cb->all_flags); return 0; } @@@ -1293,8 -1292,7 +1293,8 @@@ static int handle_one_reflog_ent(unsign return 0; } -static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data) +static int handle_one_reflog(const char *path, const struct object_id *oid, + int flag, void *cb_data) { struct all_refs_cb *cb = cb_data; cb->warned_bad_reflog = 0; @@@ -1306,7 -1304,6 +1306,7 @@@ void add_reflogs_to_pending(struct rev_info *revs, unsigned flags) { struct all_refs_cb cb; + cb.all_revs = revs; cb.all_flags = flags; for_each_reflog(handle_one_reflog, &cb); @@@ -2173,6 -2170,21 +2173,21 @@@ static int handle_revision_pseudo_opt(c return 1; } + static void NORETURN diagnose_missing_default(const char *def) + { + unsigned char sha1[20]; + int flags; + const char *refname; + + refname = resolve_ref_unsafe(def, 0, sha1, &flags); + if (!refname || !(flags & REF_ISSYMREF) || (flags & REF_ISBROKEN)) + die(_("your current branch appears to be broken")); + + skip_prefix(refname, "refs/heads/", &refname); + die(_("your current branch '%s' does not have any commits yet"), + refname); + } + /* * Parse revision information, filling in the "rev_info" structure, * and removing the used arguments from the argument list. @@@ -2302,7 -2314,7 +2317,7 @@@ int setup_revisions(int argc, const cha struct object *object; struct object_context oc; if (get_sha1_with_context(revs->def, 0, sha1, &oc)) - die("bad default revision '%s'", revs->def); + diagnose_missing_default(revs->def); object = get_reference(revs, revs->def, sha1, 0); add_pending_object_with_mode(revs, object, revs->def, oc.mode); }