ref_update_reject_duplicates(): expose function to whole refs module
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>
Michael Haggerty committed
May 22, 2017 at 16:17 UTC
2ced105cb1df064b9400aef5f4d35e20026ab267
3 files changed
+25
-17
refs.c
+17
@@ -1702,6 +1702,23 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
1702
refs_heads_master, logmsg);
1703
}
1704
1705
+int ref_update_reject_duplicates(struct string_list *refnames,
1706
+ struct strbuf *err)
1707
+{
1708
+ int i, n = refnames->nr;
1709
+
1710
+ assert(err);
1711
+
1712
+ for (i = 1; i < n; i++)
1713
+ if (!strcmp(refnames->items[i - 1].string, refnames->items[i].string)) {
1714
+ strbuf_addf(err,
1715
+ "multiple updates for ref '%s' not allowed.",
1716
+ refnames->items[i].string);
1717
+ return 1;
1718
+ }
1719
+ return 0;
1720
+}
1721
+
1722
int ref_transaction_prepare(struct ref_transaction *transaction,
1723
struct strbuf *err)
1724
{
refs/files-backend.c
-17
@@ -2512,23 +2512,6 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
2512
return ref_iterator;
2513
}
2514
2515
-static int ref_update_reject_duplicates(struct string_list *refnames,
2516
- struct strbuf *err)
2517
-{
2518
- int i, n = refnames->nr;
2519
-
2520
- assert(err);
2521
-
2522
- for (i = 1; i < n; i++)
2523
- if (!strcmp(refnames->items[i - 1].string, refnames->items[i].string)) {
2524
- strbuf_addf(err,
2525
- "multiple updates for ref '%s' not allowed.",
2526
- refnames->items[i].string);
2527
- return 1;
2528
- }
2529
- return 0;
2530
-}
2531
-
2515
/*
2516
* If update is a direct update of head_ref (the reference pointed to
2517
* by HEAD), then add an extra REF_LOG_ONLY update for HEAD.
refs/refs-internal.h
+8
@@ -169,6 +169,14 @@ int refs_read_raw_ref(struct ref_store *ref_store,
169
const char *refname, unsigned char *sha1,
170
struct strbuf *referent, unsigned int *type);
171
172
+/*
173
+ * Write an error to `err` and return a nonzero value iff the same
174
+ * refname appears multiple times in `refnames`. `refnames` must be
175
+ * sorted on entry to this function.
176
+ */
177
+int ref_update_reject_duplicates(struct string_list *refnames,
178
+ struct strbuf *err);
179
+
180
/*
181
* Add a ref_update with the specified properties to transaction, and
182
* return a pointer to the new object. This function does not verify