summaryrefslogtreecommitdiff
path: root/refs.h
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2013-09-04 11:22:43 -0400
committerJunio C Hamano <gitster@pobox.com>2013-09-04 11:10:28 -0700
commit98aee92d5c9e5161a8c11b7666996e4ffffe80ab (patch)
treede4b08360058b244cc3ef5b2858d1da7fc4bad26 /refs.h
parent61cee0dbac84160ad4a1bcc2ecdb15761bd284fc (diff)
downloadgit-98aee92d5c9e5161a8c11b7666996e4ffffe80ab.tar.gz
refs: add update_refs for multiple simultaneous updates
Add 'struct ref_update' to encode the information needed to update or delete a ref (name, new sha1, optional old sha1, no-deref flag). Add function 'update_refs' accepting an array of updates to perform. First sort the input array to order locks consistently everywhere and reject multiple updates to the same ref. Then acquire locks on all refs with verified old values. Then update or delete all refs accordingly. Fail if any one lock cannot be obtained or any one old value does not match. Though the refs themselves cannot be modified together in a single atomic transaction, this function does enable some useful semantics. For example, a caller may create a new branch starting from the head of another branch and rewind the original branch at the same time. This transfers ownership of commits between branches without risk of losing commits added to the original branch by a concurrent process, or risk of a concurrent process creating the new branch first. Signed-off-by: Brad King <brad.king@kitware.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'refs.h')
-rw-r--r--refs.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/refs.h b/refs.h
index 2cd307af25..b113377c48 100644
--- a/refs.h
+++ b/refs.h
@@ -10,6 +10,20 @@ struct ref_lock {
int force_write;
};
+/**
+ * Information needed for a single ref update. Set new_sha1 to the
+ * new value or to zero to delete the ref. To check the old value
+ * while locking the ref, set have_old to 1 and set old_sha1 to the
+ * value or to zero to ensure the ref does not exist before update.
+ */
+struct ref_update {
+ const char *ref_name;
+ unsigned char new_sha1[20];
+ unsigned char old_sha1[20];
+ int flags; /* REF_NODEREF? */
+ int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
+};
+
/*
* Bit values set in the flags argument passed to each_ref_fn():
*/
@@ -214,6 +228,12 @@ int update_ref(const char *action, const char *refname,
const unsigned char *sha1, const unsigned char *oldval,
int flags, enum action_on_err onerr);
+/**
+ * Lock all refs and then perform all modifications.
+ */
+int update_refs(const char *action, const struct ref_update **updates,
+ int n, enum action_on_err onerr);
+
extern int parse_hide_refs_config(const char *var, const char *value, const char *);
extern int ref_is_hidden(const char *);