Merge branch 'js/emu-write-epipe-on-windows'
[gitweb.git] / refs / files-backend.c
index 14ec506c1783f0821f751a4ebda8e0b03c2b7362..c648b5e853c347f0978d835cb057a9a2831bf0dd 100644 (file)
@@ -728,6 +728,7 @@ static int verify_refname_available_dir(const char *refname,
                                        struct strbuf *err)
 {
        const char *slash;
+       const char *extra_refname;
        int pos;
        struct strbuf dirname = STRBUF_INIT;
        int ret = -1;
@@ -833,32 +834,12 @@ static int verify_refname_available_dir(const char *refname,
                }
        }
 
-       if (extras) {
-               /*
-                * Check for entries in extras that start with
-                * "$refname/". We do that by looking for the place
-                * where "$refname/" would be inserted in extras. If
-                * there is an entry at that position that starts with
-                * "$refname/" and is not in skip, then we have a
-                * conflict.
-                */
-               for (pos = string_list_find_insert_index(extras, dirname.buf, 0);
-                    pos < extras->nr; pos++) {
-                       const char *extra_refname = extras->items[pos].string;
-
-                       if (!starts_with(extra_refname, dirname.buf))
-                               break;
-
-                       if (!skip || !string_list_has_string(skip, extra_refname)) {
-                               strbuf_addf(err, "cannot process '%s' and '%s' at the same time",
-                                           refname, extra_refname);
-                               goto cleanup;
-                       }
-               }
-       }
-
-       /* No conflicts were found */
-       ret = 0;
+       extra_refname = find_descendant_ref(dirname.buf, extras, skip);
+       if (extra_refname)
+               strbuf_addf(err, "cannot process '%s' and '%s' at the same time",
+                           refname, extra_refname);
+       else
+               ret = 0;
 
 cleanup:
        strbuf_release(&dirname);
@@ -2473,22 +2454,6 @@ int verify_refname_available(const char *newname,
        return 0;
 }
 
-static int rename_ref_available(const char *oldname, const char *newname)
-{
-       struct string_list skip = STRING_LIST_INIT_NODUP;
-       struct strbuf err = STRBUF_INIT;
-       int ret;
-
-       string_list_insert(&skip, oldname);
-       ret = !verify_refname_available(newname, NULL, &skip, &err);
-       if (!ret)
-               error("%s", err.buf);
-
-       string_list_clear(&skip, 0);
-       strbuf_release(&err);
-       return ret;
-}
-
 static int write_ref_to_lockfile(struct ref_lock *lock,
                                 const unsigned char *sha1, struct strbuf *err);
 static int commit_ref_update(struct ref_lock *lock,
@@ -2733,6 +2698,14 @@ static int log_ref_write_1(const char *refname, const unsigned char *old_sha1,
 static int log_ref_write(const char *refname, const unsigned char *old_sha1,
                         const unsigned char *new_sha1, const char *msg,
                         int flags, struct strbuf *err)
+{
+       return files_log_ref_write(refname, old_sha1, new_sha1, msg, flags,
+                                  err);
+}
+
+int files_log_ref_write(const char *refname, const unsigned char *old_sha1,
+                       const unsigned char *new_sha1, const char *msg,
+                       int flags, struct strbuf *err)
 {
        struct strbuf sb = STRBUF_INIT;
        int ret = log_ref_write_1(refname, old_sha1, new_sha1, msg, &sb, flags,
@@ -3521,7 +3494,7 @@ int reflog_expire(const char *refname, const unsigned char *sha1,
                                        get_lock_file_path(lock->lk));
                        rollback_lock_file(&reflog_lock);
                } else if (commit_lock_file(&reflog_lock)) {
-                       status |= error("unable to commit reflog '%s' (%s)",
+                       status |= error("unable to write reflog '%s' (%s)",
                                        log_file, strerror(errno));
                } else if (update && commit_ref(lock)) {
                        status |= error("couldn't set %s", lock->ref_name);