Merge branch 'jc/request-pull-show-head-4'
[gitweb.git] / builtin / merge.c
index 98ed54a5f5722aba1146cbf627e3b95cc8c14f30..24579409c08f2e24ef3e5f2599a6af1aab8d28cd 100644 (file)
@@ -1100,6 +1100,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        struct commit_list *common = NULL;
        const char *best_strategy = NULL, *wt_strategy = NULL;
        struct commit_list **remotes = &remoteheads;
+       void *branch_to_free;
 
        if (argc == 2 && !strcmp(argv[1], "-h"))
                usage_with_options(builtin_merge_usage, builtin_merge_options);
@@ -1108,12 +1109,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * Check if we are _not_ on a detached HEAD, i.e. if there is a
         * current branch.
         */
-       branch = resolve_ref("HEAD", head_sha1, 0, &flag);
-       if (branch) {
-               if (!prefixcmp(branch, "refs/heads/"))
-                       branch += 11;
-               branch = xstrdup(branch);
-       }
+       branch = branch_to_free = resolve_refdup("HEAD", head_sha1, 0, &flag);
+       if (branch && !prefixcmp(branch, "refs/heads/"))
+               branch += 11;
        if (!branch || is_null_sha1(head_sha1))
                head_commit = NULL;
        else
@@ -1524,6 +1522,6 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                ret = suggest_conflicts(option_renormalize);
 
 done:
-       free((char *)branch);
+       free(branch_to_free);
        return ret;
 }