Merge branch 'jk/log-missing-default-HEAD' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 4 Sep 2015 02:18:03 +0000 (19:18 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 4 Sep 2015 02:18:04 +0000 (19:18 -0700)
"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

1  2 
revision.c
diff --combined revision.c
index ab97ffd4590cc41743d4bb828a9c5bdb1a00cce9,734494abe6af2288e2f0bf6ad31eb5b74db9ea9c..9b9d77dc439d6a6c8e25c58454833804116db14a
@@@ -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);
        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;
        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;
  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);
        }