rename_ref_available(): add docstring
And improve the internal variable names. Signed-off-by: David Turner <dturner@twopensource.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
David Turner committed
Sep 4, 2016 at 18:08 UTC
ff3a299c457cb159a83df8382ed76731e03db530
2 files changed
+17
-7
refs.c
+6
-6
@@ -1081,20 +1081,20 @@ const char *find_descendant_ref(const char *dirname,
1081
return NULL;
1082
}
1083
1084
-int rename_ref_available(const char *oldname, const char *newname)
1084
+int rename_ref_available(const char *old_refname, const char *new_refname)
1085
{
1086
struct string_list skip = STRING_LIST_INIT_NODUP;
1087
struct strbuf err = STRBUF_INIT;
1088
- int ret;
1088
+ int ok;
1089
1090
- string_list_insert(&skip, oldname);
1091
- ret = !verify_refname_available(newname, NULL, &skip, &err);
1092
- if (!ret)
1090
+ string_list_insert(&skip, old_refname);
1091
+ ok = !verify_refname_available(new_refname, NULL, &skip, &err);
1092
+ if (!ok)
1093
error("%s", err.buf);
1094
1095
string_list_clear(&skip, 0);
1096
strbuf_release(&err);
1097
- return ret;
1097
+ return ok;
1098
}
1099
1100
int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)
refs/refs-internal.h
+11
-1
@@ -240,7 +240,17 @@ const char *find_descendant_ref(const char *dirname,
240
const struct string_list *extras,
241
const struct string_list *skip);
242
243
-int rename_ref_available(const char *oldname, const char *newname);
243
+/*
244
+ * Check whether an attempt to rename old_refname to new_refname would
245
+ * cause a D/F conflict with any existing reference (other than
246
+ * possibly old_refname). If there would be a conflict, emit an error
247
+ * message and return false; otherwise, return true.
248
+ *
249
+ * Note that this function is not safe against all races with other
250
+ * processes (though rename_ref() catches some races that might get by
251
+ * this check).
252
+ */
253
+int rename_ref_available(const char *old_refname, const char *new_refname);
254
255
/* We allow "recursive" symbolic refs. Only within reason, though */
256
#define SYMREF_MAXDEPTH 5