return do_for_each_ref(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);
}
+int for_each_fullref_in(const char *prefix, each_ref_fn fn, void *cb_data, unsigned int broken)
+{
+ unsigned int flag = 0;
+
+ if (broken)
+ flag = DO_FOR_EACH_INCLUDE_BROKEN;
+ return do_for_each_ref(&ref_cache, prefix, fn, 0, flag, cb_data);
+}
+
int for_each_ref_in_submodule(const char *submodule, const char *prefix,
each_ref_fn fn, void *cb_data)
{
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);
}
/*
* to remain.
*/
strbuf_git_path(&orig_ref_file, "%s", orig_refname);
- if (remove_empty_directories(orig_ref_file.buf)) {
+ if (remove_empty_directories(&orig_ref_file)) {
last_errno = errno;
if (!verify_refname_available(orig_refname, extras, skip,
get_loose_refs(&ref_cache), err))
* 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;