delete_ref(): move declaration to refs.h
Also * Add a docstring * Rename the second parameter to "old_sha1", to be consistent with the convention used elsewhere in the refs module Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jun 22, 2015 at 16:02 UTC
fc1c21689d6d82551f6136a3116876005b4e00a4
3 files changed
+13
-4
cache.h
-2
@@ -585,8 +585,6 @@ extern void update_index_if_able(struct index_state *, struct lock_file *);
585
extern int hold_locked_index(struct lock_file *, int);
586
extern void set_alternate_index_output(const char *);
587
588
-extern int delete_ref(const char *, const unsigned char *sha1, unsigned int flags);
589
-
588
/* Environment bits from configuration mechanism */
589
extern int trust_executable_bit;
590
extern int trust_ctime;
refs.c
+3
-2
@@ -2801,7 +2801,8 @@ static int delete_ref_loose(struct ref_lock *lock, int flag, struct strbuf *err)
2801
return 0;
2802
}
2803
2804
-int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flags)
2804
+int delete_ref(const char *refname, const unsigned char *old_sha1,
2805
+ unsigned int flags)
2806
{
2807
struct ref_transaction *transaction;
2808
struct strbuf err = STRBUF_INIT;
@@ -2809,7 +2810,7 @@ int delete_ref(const char *refname, const unsigned char *sha1, unsigned int flag
2810
transaction = ref_transaction_begin(&err);
2811
if (!transaction ||
2812
ref_transaction_delete(transaction, refname,
2812
- (sha1 && !is_null_sha1(sha1)) ? sha1 : NULL,
2813
+ (old_sha1 && !is_null_sha1(old_sha1)) ? old_sha1 : NULL,
2814
flags, NULL, &err) ||
2815
ref_transaction_commit(transaction, &err)) {
2816
error("%s", err.buf);
refs.h
+10
@@ -202,6 +202,16 @@ extern int read_ref_at(const char *refname, unsigned int flags,
202
/** Check if a particular reflog exists */
203
extern int reflog_exists(const char *refname);
204
205
+/*
206
+ * Delete the specified reference. If old_sha1 is non-NULL and not
207
+ * NULL_SHA1, then verify that the current value of the reference is
208
+ * old_sha1 before deleting it. If old_sha1 is NULL or NULL_SHA1,
209
+ * delete the reference if it exists, regardless of its old value.
210
+ * flags is passed through to ref_transaction_delete().
211
+ */
212
+extern int delete_ref(const char *refname, const unsigned char *old_sha1,
213
+ unsigned int flags);
214
+
215
/** Delete a reflog */
216
extern int delete_reflog(const char *refname);
217