Code

Merge branch 'js/rerere'
[git.git] / refs.c
diff --git a/refs.c b/refs.c
index c23561e1582980e01c827540de0e0a43bf2547d3..a101ff3bf88dafa56ac85fcd977c0ae6be1b495e 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1,10 +1,8 @@
-#include "refs.h"
 #include "cache.h"
+#include "refs.h"
 #include "object.h"
 #include "tag.h"
 
-#include <errno.h>
-
 /* ISSYMREF=01 and ISPACKED=02 are public interfaces */
 #define REF_KNOWS_PEELED 04
 
@@ -534,7 +532,7 @@ int check_ref_format(const char *ref)
                level++;
                if (!ch) {
                        if (level < 2)
-                               return -1; /* at least of form "heads/blah" */
+                               return -2; /* at least of form "heads/blah" */
                        return 0;
                }
        }
@@ -784,13 +782,12 @@ int delete_ref(const char *refname, unsigned char *sha1)
        return ret;
 }
 
-int rename_ref(const char *oldref, const char *newref)
+int rename_ref(const char *oldref, const char *newref, const char *logmsg)
 {
        static const char renamed_ref[] = "RENAMED-REF";
        unsigned char sha1[20], orig_sha1[20];
        int flag = 0, logmoved = 0;
        struct ref_lock *lock;
-       char msg[PATH_MAX*2 + 100];
        struct stat loginfo;
        int log = !lstat(git_path("logs/%s", oldref), &loginfo);
 
@@ -806,14 +803,11 @@ int rename_ref(const char *oldref, const char *newref)
        if (!is_refname_available(newref, oldref, get_loose_refs(), 0))
                return 1;
 
-       if (snprintf(msg, sizeof(msg), "renamed %s to %s", oldref, newref) > sizeof(msg))
-               return error("Refnames to long");
-
        lock = lock_ref_sha1_basic(renamed_ref, NULL, NULL);
        if (!lock)
                return error("unable to lock %s", renamed_ref);
        lock->force_write = 1;
-       if (write_ref_sha1(lock, orig_sha1, msg))
+       if (write_ref_sha1(lock, orig_sha1, logmsg))
                return error("unable to save current sha1 in %s", renamed_ref);
 
        if (log && rename(git_path("logs/%s", oldref), git_path("tmp-renamed-log")))
@@ -866,11 +860,21 @@ int rename_ref(const char *oldref, const char *newref)
 
        lock->force_write = 1;
        hashcpy(lock->old_sha1, orig_sha1);
-       if (write_ref_sha1(lock, orig_sha1, msg)) {
+       if (write_ref_sha1(lock, orig_sha1, logmsg)) {
                error("unable to write current sha1 into %s", newref);
                goto rollback;
        }
 
+       if (!strncmp(oldref, "refs/heads/", 11) &&
+                       !strncmp(newref, "refs/heads/", 11)) {
+               char oldsection[1024], newsection[1024];
+
+               snprintf(oldsection, 1024, "branch.%s", oldref + 11);
+               snprintf(newsection, 1024, "branch.%s", newref + 11);
+               if (git_config_rename_section(oldsection, newsection) < 0)
+                       return 1;
+       }
+
        return 0;
 
  rollback: