Skip to content

Commit 2ced105

Browse files
mhaggergitster
authored andcommitted
ref_update_reject_duplicates(): expose function to whole refs module
It will soon have some other users. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 30173b8 commit 2ced105

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

refs.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,6 +1702,23 @@ int create_symref(const char *ref_target, const char *refs_heads_master,
17021702
refs_heads_master, logmsg);
17031703
}
17041704

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+
17051722
int ref_transaction_prepare(struct ref_transaction *transaction,
17061723
struct strbuf *err)
17071724
{

refs/files-backend.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,23 +2512,6 @@ static struct ref_iterator *files_reflog_iterator_begin(struct ref_store *ref_st
25122512
return ref_iterator;
25132513
}
25142514

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-
25322515
/*
25332516
* If update is a direct update of head_ref (the reference pointed to
25342517
* by HEAD), then add an extra REF_LOG_ONLY update for HEAD.

refs/refs-internal.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,14 @@ int refs_read_raw_ref(struct ref_store *ref_store,
169169
const char *refname, unsigned char *sha1,
170170
struct strbuf *referent, unsigned int *type);
171171

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+
172180
/*
173181
* Add a ref_update with the specified properties to transaction, and
174182
* return a pointer to the new object. This function does not verify

0 commit comments

Comments
 (0)