ref_update_reject_duplicates(): expose function to whole refs module
authorMichael Haggerty <mhagger@alum.mit.edu>
Mon, 22 May 2017 14:17:45 +0000 (16:17 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 23 May 2017 05:29:55 +0000 (14:29 +0900)
It will soon have some other users.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
refs.c
refs/files-backend.c
refs/refs-internal.h
diff --git a/refs.c b/refs.c
index b3860a9e333b7b0fc284b7794a2d40ea621eb638..beb49fb2979fe7780e721237cc0e4d7c47c355ee 100644 (file)
--- a/refs.c
+++ b/refs.c
@@ -1702,6 +1702,23 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
                                  refs_heads_master, logmsg);
 }
 
+int ref_update_reject_duplicates(struct string_list *refnames,
+                                struct strbuf *err)
+{
+       int i, n = refnames->nr;
+
+       assert(err);
+
+       for (i = 1; i < n; i++)
+               if (!strcmp(refnames->items[i - 1].string, refnames->items[i].string)) {
+                       strbuf_addf(err,
+                                   "multiple updates for ref '%s' not allowed.",
+                                   refnames->items[i].string);
+                       return 1;
+               }
+       return 0;
+}
+
 int ref_transaction_prepare(struct ref_transaction *transaction,
                            struct strbuf *err)
 {
index 19842d2e5637aa3f40b982ba306d6821d267b929..8d0ce739a602b69df5ea2bc77ecd6b8c9a6ec4e3 100644 (file)
@@ -2512,23 +2512,6 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
        return ref_iterator;
 }
 
-static int ref_update_reject_duplicates(struct string_list *refnames,
-                                       struct strbuf *err)
-{
-       int i, n = refnames->nr;
-
-       assert(err);
-
-       for (i = 1; i < n; i++)
-               if (!strcmp(refnames->items[i - 1].string, refnames->items[i].string)) {
-                       strbuf_addf(err,
-                                   "multiple updates for ref '%s' not allowed.",
-                                   refnames->items[i].string);
-                       return 1;
-               }
-       return 0;
-}
-
 /*
  * If update is a direct update of head_ref (the reference pointed to
  * by HEAD), then add an extra REF_LOG_ONLY update for HEAD.
index 4d3dd17f9ff9029a1d8f5767afbf94998e7cd389..192f9f85c97c0d7ca4e9c933e27ba0686da31dbe 100644 (file)
@@ -169,6 +169,14 @@ int refs_read_raw_ref(struct ref_store *ref_store,
                      const char *refname, unsigned char *sha1,
                      struct strbuf *referent, unsigned int *type);
 
+/*
+ * Write an error to `err` and return a nonzero value iff the same
+ * refname appears multiple times in `refnames`. `refnames` must be
+ * sorted on entry to this function.
+ */
+int ref_update_reject_duplicates(struct string_list *refnames,
+                                struct strbuf *err);
+
 /*
  * Add a ref_update with the specified properties to transaction, and
  * return a pointer to the new object. This function does not verify