use skip_prefix to avoid repeating strings
[gitweb.git] / builtin / checkout.c
index ff4492162d9543598c1cdc8951f8604a4712516d..463cfeea5067fe02d8eb1414018c97ff9a757176 100644 (file)
@@ -651,12 +651,8 @@ static void update_refs_for_switch(const struct checkout_opts *opts,
                        }
                }
                if (old->path && old->name) {
-                       char log_file[PATH_MAX], ref_file[PATH_MAX];
-
-                       git_snpath(log_file, sizeof(log_file), "logs/%s", old->path);
-                       git_snpath(ref_file, sizeof(ref_file), "%s", old->path);
-                       if (!file_exists(ref_file) && file_exists(log_file))
-                               remove_path(log_file);
+                       if (!ref_exists(old->path) && reflog_exists(old->path))
+                               delete_reflog(old->path);
                }
        }
        remove_branch_state();
@@ -780,8 +776,8 @@ static int switch_branches(const struct checkout_opts *opts,
        if (!(flag & REF_ISSYMREF))
                old.path = NULL;
 
-       if (old.path && starts_with(old.path, "refs/heads/"))
-               old.name = old.path + strlen("refs/heads/");
+       if (old.path)
+               skip_prefix(old.path, "refs/heads/", &old.name);
 
        if (!new->name) {
                new->name = "HEAD";