Merge branch 'nh/empty-rebase'
authorJunio C Hamano <gitster@pobox.com>
Mon, 7 May 2012 20:29:16 +0000 (13:29 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 7 May 2012 20:29:16 +0000 (13:29 -0700)
By Neil Horman
* nh/empty-rebase:
git cherry-pick: do not dereference a potential NULL pointer

1  2 
sequencer.c
diff --combined sequencer.c
index f83cdfd63764b6c20432b2226648f4fd9eda62fe,72cb4ff82ca0b98f4074e1af3fb491df691a7268..3c384b94d24e3099cb149c66347386d1430fadef
@@@ -165,7 -165,7 +165,7 @@@ static void write_message(struct strbu
  
  static struct tree *empty_tree(void)
  {
 -      return lookup_tree((const unsigned char *)EMPTY_TREE_SHA1_BIN);
 +      return lookup_tree(EMPTY_TREE_SHA1_BIN);
  }
  
  static int error_dirty_index(struct replay_opts *opts)
@@@ -235,7 -235,7 +235,7 @@@ static int do_recursive_merge(struct co
  
        if (!clean) {
                int i;
 -              strbuf_addstr(msgbuf, "\nConflicts:\n\n");
 +              strbuf_addstr(msgbuf, "\nConflicts:\n");
                for (i = 0; i < active_nr;) {
                        struct cache_entry *ce = active_cache[i++];
                        if (ce_stage(ce)) {
@@@ -261,9 -261,17 +261,17 @@@ static int is_index_unchanged(void
                return error(_("Could not resolve HEAD commit\n"));
  
        head_commit = lookup_commit(head_sha1);
-       if (!head_commit || parse_commit(head_commit))
-               return error(_("could not parse commit %s\n"),
-                            sha1_to_hex(head_commit->object.sha1));
+       /*
+        * If head_commit is NULL, check_commit, called from
+        * lookup_commit, would have indicated that head_commit is not
+        * a commit object already.  parse_commit() will return failure
+        * without further complaints in such a case.  Otherwise, if
+        * the commit is invalid, parse_commit() will complain.  So
+        * there is nothing for us to say here.  Just return failure.
+        */
+       if (parse_commit(head_commit))
+               return -1;
  
        if (!active_cache_tree)
                active_cache_tree = cache_tree();
@@@ -543,6 -551,33 +551,6 @@@ static void read_and_refresh_cache(stru
        rollback_lock_file(&index_lock);
  }
  
 -/*
 - * Append a commit to the end of the commit_list.
 - *
 - * next starts by pointing to the variable that holds the head of an
 - * empty commit_list, and is updated to point to the "next" field of
 - * the last item on the list as new commits are appended.
 - *
 - * Usage example:
 - *
 - *     struct commit_list *list;
 - *     struct commit_list **next = &list;
 - *
 - *     next = commit_list_append(c1, next);
 - *     next = commit_list_append(c2, next);
 - *     assert(commit_list_count(list) == 2);
 - *     return list;
 - */
 -static struct commit_list **commit_list_append(struct commit *commit,
 -                                             struct commit_list **next)
 -{
 -      struct commit_list *new = xmalloc(sizeof(struct commit_list));
 -      new->item = commit;
 -      *next = new;
 -      new->next = NULL;
 -      return &new->next;
 -}
 -
  static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
                struct replay_opts *opts)
  {