return 0;
}
-static int remove_empty_directories(const char *file)
+static int remove_empty_directories(struct strbuf *path)
{
- /* we want to create a file but there is a directory there;
+ /*
+ * we want to create a file but there is a directory there;
* if that is an empty directory (or a directory that contains
* only empty directories), remove them.
*/
- struct strbuf path;
- int result, save_errno;
-
- strbuf_init(&path, 20);
- strbuf_addstr(&path, file);
-
- result = remove_dir_recursively(&path, REMOVE_DIR_EMPTY_ONLY);
- save_errno = errno;
-
- strbuf_release(&path);
- errno = save_errno;
-
- return result;
+ return remove_dir_recursively(path, REMOVE_DIR_EMPTY_ONLY);
}
/*
unsigned int flags, int *type_p,
struct strbuf *err)
{
- const char *ref_file;
+ struct strbuf ref_file = STRBUF_INIT;
+ struct strbuf orig_ref_file = STRBUF_INIT;
const char *orig_refname = refname;
struct ref_lock *lock;
int last_errno = 0;
refname = resolve_ref_unsafe(refname, resolve_flags,
lock->old_oid.hash, &type);
if (!refname && errno == EISDIR) {
- /* we are trying to lock foo but we used to
+ /*
+ * 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_refname);
- if (remove_empty_directories(ref_file)) {
+ strbuf_git_path(&orig_ref_file, "%s", orig_refname);
+ if (remove_empty_directories(&orig_ref_file)) {
last_errno = errno;
-
if (!verify_refname_available(orig_refname, extras, skip,
get_loose_refs(&ref_cache), err))
strbuf_addf(err, "there are still refs under '%s'",
orig_refname);
-
goto error_return;
}
refname = resolve_ref_unsafe(orig_refname, resolve_flags,
}
lock->ref_name = xstrdup(refname);
lock->orig_ref_name = xstrdup(orig_refname);
- ref_file = git_path("%s", refname);
+ strbuf_git_path(&ref_file, "%s", refname);
retry:
- switch (safe_create_leading_directories_const(ref_file)) {
+ switch (safe_create_leading_directories_const(ref_file.buf)) {
case SCLD_OK:
break; /* success */
case SCLD_VANISHED:
/* fall through */
default:
last_errno = errno;
- strbuf_addf(err, "unable to create directory for %s", ref_file);
+ strbuf_addf(err, "unable to create directory for %s",
+ ref_file.buf);
goto error_return;
}
- if (hold_lock_file_for_update(lock->lk, ref_file, lflags) < 0) {
+ if (hold_lock_file_for_update(lock->lk, ref_file.buf, lflags) < 0) {
last_errno = errno;
if (errno == ENOENT && --attempts_remaining > 0)
/*
*/
goto retry;
else {
- unable_to_lock_message(ref_file, errno, err);
+ unable_to_lock_message(ref_file.buf, errno, err);
goto error_return;
}
}
last_errno = errno;
goto error_return;
}
- return lock;
+ goto out;
error_return:
unlock_ref(lock);
+ lock = NULL;
+
+ out:
+ strbuf_release(&ref_file);
+ strbuf_release(&orig_ref_file);
errno = last_errno;
- return NULL;
+ return lock;
}
/*
* directory ought to result in ISDIR, but
* Solaris 5.8 gives ENOTDIR. Sheesh.
*/
- if (remove_empty_directories(path.buf)) {
+ if (remove_empty_directories(&path)) {
error("Directory not empty: logs/%s", newrefname);
goto out;
}
if (!read_ref_full(newrefname, RESOLVE_REF_READING, sha1, NULL) &&
delete_ref(newrefname, sha1, REF_NODEREF)) {
if (errno==EISDIR) {
- if (remove_empty_directories(git_path("%s", newrefname))) {
+ struct strbuf path = STRBUF_INIT;
+ int result;
+
+ strbuf_git_path(&path, "%s", newrefname);
+ result = remove_empty_directories(&path);
+ strbuf_release(&path);
+
+ if (result) {
error("Directory not empty: %s", newrefname);
goto rollback;
}
return 0;
if (errno == EISDIR) {
- if (remove_empty_directories(logfile->buf)) {
+ if (remove_empty_directories(logfile)) {
strbuf_addf(err, "There are still logs under "
"'%s'", logfile->buf);
return -1;