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;
*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;
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;
}
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;
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;
}