Merge branch 'js/blame-lib'
authorJunio C Hamano <gitster@pobox.com>
Mon, 31 Jul 2017 20:05:15 +0000 (13:05 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Jul 2017 20:05:15 +0000 (13:05 -0700)
A hotfix to a topic already in 'master'.

* js/blame-lib:
blame: fix memory corruption scrambling revision name in error message

1  2 
blame.c
diff --combined blame.c
index 91e26e93e8a23d0af63e1bc8a74e9f7690276ab4,07f9b75ccef69f5fc9159998e7caf958dd7d998e..f575e9cbf4e3224049fe43b7f794d2dd8770eda7
+++ b/blame.c
@@@ -99,7 -99,7 +99,7 @@@ static struct commit_list **append_pare
  {
        struct commit *parent;
  
 -      parent = lookup_commit_reference(oid->hash);
 +      parent = lookup_commit_reference(oid);
        if (!parent)
                die("no such commit %s", oid_to_hex(oid));
        return &commit_list_insert(parent, tail)->next;
@@@ -229,7 -229,7 +229,7 @@@ static struct commit *fake_working_tree
                if (strbuf_read(&buf, 0, 0) < 0)
                        die_errno("failed to read from stdin");
        }
 -      convert_to_git(path, buf.buf, buf.len, &buf, 0);
 +      convert_to_git(&the_index, path, buf.buf, buf.len, &buf, 0);
        origin->file.ptr = buf.buf;
        origin->file.size = buf.len;
        pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);
@@@ -314,7 -314,8 +314,7 @@@ static void fill_origin_blob(struct dif
  static void drop_origin_blob(struct blame_origin *o)
  {
        if (o->file.ptr) {
 -              free(o->file.ptr);
 -              o->file.ptr = NULL;
 +              FREE_AND_NULL(o->file.ptr);
        }
  }
  
@@@ -553,11 -554,11 +553,11 @@@ static struct blame_origin *find_origin
        diff_setup_done(&diff_opts);
  
        if (is_null_oid(&origin->commit->object.oid))
 -              do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
 +              do_diff_cache(&parent->tree->object.oid, &diff_opts);
        else
 -              diff_tree_sha1(parent->tree->object.oid.hash,
 -                             origin->commit->tree->object.oid.hash,
 -                             "", &diff_opts);
 +              diff_tree_oid(&parent->tree->object.oid,
 +                            &origin->commit->tree->object.oid,
 +                            "", &diff_opts);
        diffcore_std(&diff_opts);
  
        if (!diff_queued_diff.nr) {
@@@ -622,11 -623,11 +622,11 @@@ static struct blame_origin *find_rename
        diff_setup_done(&diff_opts);
  
        if (is_null_oid(&origin->commit->object.oid))
 -              do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
 +              do_diff_cache(&parent->tree->object.oid, &diff_opts);
        else
 -              diff_tree_sha1(parent->tree->object.oid.hash,
 -                             origin->commit->tree->object.oid.hash,
 -                             "", &diff_opts);
 +              diff_tree_oid(&parent->tree->object.oid,
 +                            &origin->commit->tree->object.oid,
 +                            "", &diff_opts);
        diffcore_std(&diff_opts);
  
        for (i = 0; i < diff_queued_diff.nr; i++) {
@@@ -1246,7 -1247,7 +1246,7 @@@ static void find_copy_in_parent(struct 
        /* Try "find copies harder" on new path if requested;
         * we do not want to use diffcore_rename() actually to
         * match things up; find_copies_harder is set only to
 -       * force diff_tree_sha1() to feed all filepairs to diff_queue,
 +       * force diff_tree_oid() to feed all filepairs to diff_queue,
         * and this code needs to be after diff_setup_done(), which
         * usually makes find-copies-harder imply copy detection.
         */
                DIFF_OPT_SET(&diff_opts, FIND_COPIES_HARDER);
  
        if (is_null_oid(&target->commit->object.oid))
 -              do_diff_cache(parent->tree->object.oid.hash, &diff_opts);
 +              do_diff_cache(&parent->tree->object.oid, &diff_opts);
        else
 -              diff_tree_sha1(parent->tree->object.oid.hash,
 -                             target->commit->tree->object.oid.hash,
 -                             "", &diff_opts);
 +              diff_tree_oid(&parent->tree->object.oid,
 +                            &target->commit->tree->object.oid,
 +                            "", &diff_opts);
  
        if (!DIFF_OPT_TST(&diff_opts, FIND_COPIES_HARDER))
                diffcore_std(&diff_opts);
@@@ -1663,7 -1664,7 +1663,7 @@@ static struct commit *find_single_final
                name = revs->pending.objects[i].name;
        }
        if (name_p)
-               *name_p = name;
+               *name_p = xstrdup_or_null(name);
        return found;
  }
  
@@@ -1677,7 -1678,7 +1677,7 @@@ static struct commit *dwim_reverse_init
         */
        struct object *obj;
        struct commit *head_commit;
 -      unsigned char head_sha1[20];
 +      struct object_id head_oid;
  
        if (revs->pending.nr != 1)
                return NULL;
                return NULL;
  
        /* Do we have HEAD? */
 -      if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL))
 +      if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
                return NULL;
 -      head_commit = lookup_commit_reference_gently(head_sha1, 1);
 +      head_commit = lookup_commit_reference_gently(&head_oid, 1);
        if (!head_commit)
                return NULL;
  
@@@ -1735,7 -1736,7 +1735,7 @@@ static struct commit *find_single_initi
                die("No commit to dig up from?");
  
        if (name_p)
-               *name_p = name;
+               *name_p = xstrdup(name);
        return found;
  }
  
@@@ -1843,6 -1844,8 +1843,8 @@@ void setup_scoreboard(struct blame_scor
  
        if (orig)
                *orig = o;
+       free((char *)final_commit_name);
  }