git-svn: enable --minimize to simplify the config and connections
[gitweb.git] / builtin-branch.c
index 76f174fd89b6841ba395d25cb089d2c615f5dd37..d0179b00a2f78ddf875cf7ea98e712b152664e94 100644 (file)
@@ -59,7 +59,7 @@ int git_branch_config(const char *var, const char *value)
                branch_use_color = git_config_colorbool(var, value);
                return 0;
        }
-       if (!strncmp(var, "color.branch.", 13)) {
+       if (!prefixcmp(var, "color.branch.")) {
                int slot = parse_branch_color_slot(var, 13);
                color_parse(value, var, branch_colors[slot]);
                return 0;
@@ -134,7 +134,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds)
                 */
 
                if (!force &&
-                   !in_merge_bases(rev, head_rev)) {
+                   !in_merge_bases(rev, &head_rev, 1)) {
                        error("The branch '%s' is not a strict subset of "
                                "your current HEAD.\n"
                                "If you are sure you want to delete it, "
@@ -178,13 +178,13 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,
        int len;
 
        /* Detect kind */
-       if (!strncmp(refname, "refs/heads/", 11)) {
+       if (!prefixcmp(refname, "refs/heads/")) {
                kind = REF_LOCAL_BRANCH;
                refname += 11;
-       } else if (!strncmp(refname, "refs/remotes/", 13)) {
+       } else if (!prefixcmp(refname, "refs/remotes/")) {
                kind = REF_REMOTE_BRANCH;
                refname += 13;
-       } else if (!strncmp(refname, "refs/tags/", 10)) {
+       } else if (!prefixcmp(refname, "refs/tags/")) {
                kind = REF_TAG;
                refname += 10;
        }
@@ -316,6 +316,7 @@ static void create_branch(const char *name, const char *start_name,
        struct commit *commit;
        unsigned char sha1[20];
        char ref[PATH_MAX], msg[PATH_MAX + 20];
+       int forcing = 0;
 
        snprintf(ref, sizeof ref, "refs/heads/%s", name);
        if (check_ref_format(ref))
@@ -326,6 +327,7 @@ static void create_branch(const char *name, const char *start_name,
                        die("A branch named '%s' already exists.", name);
                else if (!is_bare_repository() && !strcmp(head, name))
                        die("Cannot force update the current branch.");
+               forcing = 1;
        }
 
        if (start_sha1)
@@ -342,11 +344,15 @@ static void create_branch(const char *name, const char *start_name,
        if (!lock)
                die("Failed to lock ref for update: %s.", strerror(errno));
 
-       if (reflog) {
+       if (reflog)
                log_all_ref_updates = 1;
+
+       if (forcing)
+               snprintf(msg, sizeof msg, "branch: Reset from %s",
+                        start_name);
+       else
                snprintf(msg, sizeof msg, "branch: Created from %s",
                         start_name);
-       }
 
        if (write_ref_sha1(lock, sha1, msg) < 0)
                die("Failed to write ref: %s.", strerror(errno));
@@ -358,7 +364,7 @@ static void rename_branch(const char *oldname, const char *newname, int force)
        unsigned char sha1[20];
 
        if (!oldname)
-               die("cannot rename the curren branch while not on any.");
+               die("cannot rename the current branch while not on any.");
 
        if (snprintf(oldref, sizeof(oldref), "refs/heads/%s", oldname) > sizeof(oldref))
                die("Old branchname too long");
@@ -440,7 +446,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                        reflog = 1;
                        continue;
                }
-               if (!strncmp(arg, "--abbrev=", 9)) {
+               if (!prefixcmp(arg, "--abbrev=")) {
                        abbrev = atoi(arg+9);
                        continue;
                }
@@ -470,7 +476,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
                detached = 1;
        }
        else {
-               if (strncmp(head, "refs/heads/", 11))
+               if (prefixcmp(head, "refs/heads/"))
                        die("HEAD not found below refs/heads!");
                head += 11;
        }