From: Junio C Hamano Date: Tue, 20 Dec 2011 21:25:53 +0000 (-0800) Subject: Merge branch 'mh/ref-api' X-Git-Tag: v1.7.9-rc0~35 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=8d68493f20db71abeb77adc251b2a116fe45cdaa;p=git.git Merge branch 'mh/ref-api' * mh/ref-api: add_ref(): take a (struct ref_entry *) parameter create_ref_entry(): extract function from add_ref() repack_without_ref(): remove temporary resolve_gitlink_ref_recursive(): change to work with struct ref_cache Pass a (ref_cache *) to the resolve_gitlink_*() helper functions resolve_gitlink_ref(): improve docstring get_ref_dir(): change signature refs: change signatures of get_packed_refs() and get_loose_refs() is_dup_ref(): extract function from sort_ref_array() add_ref(): add docstring parse_ref_line(): add docstring is_refname_available(): remove the "quiet" argument clear_ref_array(): rename from free_ref_array() refs: rename parameters result -> sha1 refs: rename "refname" variables struct ref_entry: document name member Conflicts: cache.h refs.c --- 8d68493f20db71abeb77adc251b2a116fe45cdaa diff --cc refs.c index 4bf45b197,579e4c3a1..6f436f1cb --- a/refs.c +++ b/refs.c @@@ -497,7 -505,7 +505,7 @@@ static int get_packed_ref(const char *r return -1; } - const char *resolve_ref_unsafe(const char *ref, unsigned char *sha1, int reading, int *flag) -const char *resolve_ref(const char *refname, unsigned char *sha1, int reading, int *flag) ++const char *resolve_ref_unsafe(const char *refname, unsigned char *sha1, int reading, int *flag) { int depth = MAXDEPTH; ssize_t len; @@@ -602,15 -610,9 +610,15 @@@ *flag |= REF_ISBROKEN; return NULL; } - return ref; + return refname; } +char *resolve_refdup(const char *ref, unsigned char *sha1, int reading, int *flag) +{ + const char *ret = resolve_ref_unsafe(ref, sha1, reading, flag); + return ret ? xstrdup(ret) : NULL; +} + /* The argument to filter_refs */ struct ref_filter { const char *pattern; @@@ -618,9 -620,9 +626,9 @@@ void *cb_data; }; - int read_ref_full(const char *ref, unsigned char *sha1, int reading, int *flags) + int read_ref_full(const char *refname, unsigned char *sha1, int reading, int *flags) { - if (resolve_ref_unsafe(ref, sha1, reading, flags)) - if (resolve_ref(refname, sha1, reading, flags)) ++ if (resolve_ref_unsafe(refname, sha1, reading, flags)) return 0; return -1; } @@@ -1183,20 -1194,20 +1200,20 @@@ static struct ref_lock *lock_ref_sha1_b lock = xcalloc(1, sizeof(struct ref_lock)); lock->lock_fd = -1; - ref = resolve_ref_unsafe(ref, lock->old_sha1, mustexist, &type); - if (!ref && errno == EISDIR) { - refname = resolve_ref(refname, lock->old_sha1, mustexist, &type); ++ refname = resolve_ref_unsafe(refname, lock->old_sha1, mustexist, &type); + if (!refname && errno == EISDIR) { /* we are trying to lock foo but we used to * have foo/bar which now does not exist; * it is normal for the empty directory 'foo' * to remain. */ - ref_file = git_path("%s", orig_ref); + ref_file = git_path("%s", orig_refname); if (remove_empty_directories(ref_file)) { last_errno = errno; - error("there are still refs under '%s'", orig_ref); + error("there are still refs under '%s'", orig_refname); goto error_return; } - ref = resolve_ref_unsafe(orig_ref, lock->old_sha1, mustexist, &type); - refname = resolve_ref(orig_refname, lock->old_sha1, mustexist, &type); ++ refname = resolve_ref_unsafe(orig_refname, lock->old_sha1, mustexist, &type); } if (type_p) *type_p = type; @@@ -1353,31 -1362,32 +1368,32 @@@ int rename_ref(const char *oldrefname, int flag = 0, logmoved = 0; struct ref_lock *lock; struct stat loginfo; - int log = !lstat(git_path("logs/%s", oldref), &loginfo); + int log = !lstat(git_path("logs/%s", oldrefname), &loginfo); const char *symref = NULL; + struct ref_cache *refs = get_ref_cache(NULL); if (log && S_ISLNK(loginfo.st_mode)) - return error("reflog for %s is a symlink", oldref); + return error("reflog for %s is a symlink", oldrefname); - symref = resolve_ref_unsafe(oldref, orig_sha1, 1, &flag); - symref = resolve_ref(oldrefname, orig_sha1, 1, &flag); ++ symref = resolve_ref_unsafe(oldrefname, orig_sha1, 1, &flag); if (flag & REF_ISSYMREF) return error("refname %s is a symbolic ref, renaming it is not supported", - oldref); + oldrefname); if (!symref) - return error("refname %s not found", oldref); + return error("refname %s not found", oldrefname); - if (!is_refname_available(newref, oldref, get_packed_refs(NULL), 0)) + if (!is_refname_available(newrefname, oldrefname, get_packed_refs(refs))) return 1; - if (!is_refname_available(newref, oldref, get_loose_refs(NULL), 0)) + if (!is_refname_available(newrefname, oldrefname, get_loose_refs(refs))) return 1; - if (log && rename(git_path("logs/%s", oldref), git_path(TMP_RENAMED_LOG))) + if (log && rename(git_path("logs/%s", oldrefname), git_path(TMP_RENAMED_LOG))) return error("unable to move logfile logs/%s to "TMP_RENAMED_LOG": %s", - oldref, strerror(errno)); + oldrefname, strerror(errno)); - if (delete_ref(oldref, orig_sha1, REF_NODEREF)) { - error("unable to delete old %s", oldref); + if (delete_ref(oldrefname, orig_sha1, REF_NODEREF)) { + error("unable to delete old %s", oldrefname); goto rollback; }