Merge branch 'jc/for-each-ref-with-lt-refs' into jc/ref-locking
authorJunio C Hamano <junkio@cox.net>
Wed, 27 Sep 2006 07:53:16 +0000 (00:53 -0700)
committerJunio C Hamano <junkio@cox.net>
Wed, 27 Sep 2006 07:53:16 +0000 (00:53 -0700)
* jc/for-each-ref-with-lt-refs:
Add git-for-each-ref: helper for language bindings

builtin-pack-refs.c
builtin-show-branch.c
builtin-update-index.c
refs.c
index 246dd6372ea9eafbd8326662f053ed547631ab20..db57fee72d55e9c54ee1a938e24703ebbdc12a90 100644 (file)
@@ -56,7 +56,7 @@ static void prune_ref(struct ref_to_prune *r)
        struct ref_lock *lock = lock_ref_sha1(r->name + 5, r->sha1, 1);
 
        if (lock) {
-               unlink(git_path(r->name));
+               unlink(git_path("%s", r->name));
                unlock_ref(lock);
        }
 }
index 5d6ce568360629f3844513b81f97e4412002b88b..fb1a4000d98e27389904578309b935cbda2a85fe 100644 (file)
@@ -443,6 +443,12 @@ static int rev_is_head(char *head, int headlen, char *name,
        if ((!head[0]) ||
            (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
                return 0;
+       if (!strncmp(head, "refs/heads/", 11))
+               head += 11;
+       if (!strncmp(name, "refs/heads/", 11))
+               name += 11;
+       else if (!strncmp(name, "heads/", 6))
+               name += 6;
        return !strcmp(head, name);
 }
 
index 0620e779b04146a01f9e06cbbcd535b106034bd6..09214c8a11e6afb927ab6da1aa3f0be5e50888c8 100644 (file)
@@ -404,9 +404,9 @@ static int unresolve_one(const char *path)
 
 static void read_head_pointers(void)
 {
-       if (read_ref(git_path("HEAD"), head_sha1))
+       if (read_ref("HEAD", head_sha1))
                die("No HEAD -- no initial commit yet?\n");
-       if (read_ref(git_path("MERGE_HEAD"), merge_head_sha1)) {
+       if (read_ref("MERGE_HEAD", merge_head_sha1)) {
                fprintf(stderr, "Not in the middle of a merge.\n");
                exit(0);
        }
@@ -443,7 +443,7 @@ static int do_reupdate(int ac, const char **av,
        int has_head = 1;
        const char **pathspec = get_pathspec(prefix, av + 1);
 
-       if (read_ref(git_path("HEAD"), head_sha1))
+       if (read_ref("HEAD", head_sha1))
                /* If there is no HEAD, that means it is an initial
                 * commit.  Update everything in the index.
                 */
diff --git a/refs.c b/refs.c
index 40f16af18562dbe3e32be2dfe7c700c295ed744e..2cef2b4f0e8da19049c30a57199c27b100998c90 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -447,9 +447,7 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,
        return lock;
 }
 
-static struct ref_lock *lock_ref_sha1_basic(const char *ref,
-       int plen,
-       const unsigned char *old_sha1, int mustexist)
+static struct ref_lock *lock_ref_sha1_basic(const char *ref, const unsigned char *old_sha1, int mustexist)
 {
        char *ref_file;
        const char *orig_ref = ref;
@@ -472,7 +470,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *ref,
 
        lock->ref_name = xstrdup(ref);
        lock->log_file = xstrdup(git_path("logs/%s", ref));
-       ref_file = git_path(ref);
+       ref_file = git_path("%s", ref);
        lock->force_write = lstat(ref_file, &st) && errno == ENOENT;
 
        if (safe_create_leading_directories(ref_file))
@@ -489,14 +487,13 @@ struct ref_lock *lock_ref_sha1(const char *ref,
        if (check_ref_format(ref))
                return NULL;
        strcpy(refpath, mkpath("refs/%s", ref));
-       return lock_ref_sha1_basic(refpath, strlen(refpath),
-               old_sha1, mustexist);
+       return lock_ref_sha1_basic(refpath, old_sha1, mustexist);
 }
 
 struct ref_lock *lock_any_ref_for_update(const char *ref,
        const unsigned char *old_sha1, int mustexist)
 {
-       return lock_ref_sha1_basic(ref, strlen(ref), old_sha1, mustexist);
+       return lock_ref_sha1_basic(ref, old_sha1, mustexist);
 }
 
 void unlock_ref(struct ref_lock *lock)