delete_refs(): new function for the refs API
Move the function remove_branches() from builtin/remote.c to refs.c, rename it to delete_refs(), and make it public. 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
98ffd5ff67d1097280e3c16accde6de86d3ece3d
3 files changed
+27
-20
builtin/remote.c
+1
-20
@@ -746,25 +746,6 @@ static int mv(int argc, const char **argv)
746
return 0;
747
}
748
749
-static int remove_branches(struct string_list *branches)
750
-{
751
- struct strbuf err = STRBUF_INIT;
752
- int i, result = 0;
753
-
754
- if (repack_without_refs(branches, &err))
755
- result |= error("%s", err.buf);
756
- strbuf_release(&err);
757
-
758
- for (i = 0; i < branches->nr; i++) {
759
- const char *refname = branches->items[i].string;
760
-
761
- if (delete_ref(refname, NULL, 0))
762
- result |= error(_("Could not remove branch %s"), refname);
763
- }
764
-
765
- return result;
766
-}
767
-
749
static int rm(int argc, const char **argv)
750
{
751
struct option options[] = {
@@ -821,7 +802,7 @@ static int rm(int argc, const char **argv)
802
strbuf_release(&buf);
803
804
if (!result)
824
- result = remove_branches(&branches);
805
+ result = delete_refs(&branches);
806
string_list_clear(&branches, 0);
807
808
if (skipped.nr) {
refs.c
+19
@@ -2830,6 +2830,25 @@ int delete_ref(const char *refname, const unsigned char *old_sha1,
2830
return 0;
2831
}
2832
2833
+int delete_refs(struct string_list *refnames)
2834
+{
2835
+ struct strbuf err = STRBUF_INIT;
2836
+ int i, result = 0;
2837
+
2838
+ if (repack_without_refs(refnames, &err))
2839
+ result |= error("%s", err.buf);
2840
+ strbuf_release(&err);
2841
+
2842
+ for (i = 0; i < refnames->nr; i++) {
2843
+ const char *refname = refnames->items[i].string;
2844
+
2845
+ if (delete_ref(refname, NULL, 0))
2846
+ result |= error(_("Could not remove branch %s"), refname);
2847
+ }
2848
+
2849
+ return result;
2850
+}
2851
+
2852
/*
2853
* People using contrib's git-new-workdir have .git/logs/refs ->
2854
* /some/other/path/.git/logs/refs, and that may live on another device.
refs.h
+7
@@ -212,6 +212,13 @@ extern int reflog_exists(const char *refname);
212
extern int delete_ref(const char *refname, const unsigned char *old_sha1,
213
unsigned int flags);
214
215
+/*
216
+ * Delete the specified references. If there are any problems, emit
217
+ * errors but attempt to keep going (i.e., the deletes are not done in
218
+ * an all-or-nothing transaction).
219
+ */
220
+extern int delete_refs(struct string_list *refnames);
221
+
222
/** Delete a reflog */
223
extern int delete_reflog(const char *refname);
224