diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-03-05 12:45:39 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-03-05 12:45:39 -0800 |
commit | fd9de868c359a1bbd214e354aefdb0f1eaa898bd (patch) | |
tree | 1f4f619a49a6f6171e56592bb48d2db3ae927600 /builtin | |
parent | Post 2.3 cycle (batch #6) (diff) | |
parent | refs.h: remove duplication in function docstrings (diff) | |
download | tgif-fd9de868c359a1bbd214e354aefdb0f1eaa898bd.tar.xz |
Merge branch 'mh/refs-have-new'
Simplify the ref transaction API around how "the ref should be
pointing at this object" is specified.
* mh/refs-have-new:
refs.h: remove duplication in function docstrings
update_ref(): improve documentation
ref_transaction_verify(): new function to check a reference's value
ref_transaction_delete(): check that old_sha1 is not null_sha1
ref_transaction_create(): check that new_sha1 is valid
commit: avoid race when creating orphan commits
commit: add tests of commit races
ref_transaction_delete(): remove "have_old" parameter
ref_transaction_update(): remove "have_old" parameter
struct ref_update: move "have_old" into "flags"
refs.c: change some "flags" to "unsigned int"
refs: remove the gap in the REF_* constant values
refs: move REF_DELETING to refs.c
Diffstat (limited to 'builtin')
-rw-r--r-- | builtin/commit.c | 4 | ||||
-rw-r--r-- | builtin/fetch.c | 6 | ||||
-rw-r--r-- | builtin/receive-pack.c | 5 | ||||
-rw-r--r-- | builtin/replace.c | 2 | ||||
-rw-r--r-- | builtin/tag.c | 2 | ||||
-rw-r--r-- | builtin/update-ref.c | 20 |
6 files changed, 20 insertions, 19 deletions
diff --git a/builtin/commit.c b/builtin/commit.c index 6055c760f0..961e467242 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1766,8 +1766,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix) if (!transaction || ref_transaction_update(transaction, "HEAD", sha1, current_head - ? current_head->object.sha1 : NULL, - 0, !!current_head, sb.buf, &err) || + ? current_head->object.sha1 : null_sha1, + 0, sb.buf, &err) || ref_transaction_commit(transaction, &err)) { rollback_index_files(); die("%s", err.buf); diff --git a/builtin/fetch.c b/builtin/fetch.c index 75a55e590b..f9512652cf 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -415,8 +415,10 @@ static int s_update_ref(const char *action, transaction = ref_transaction_begin(&err); if (!transaction || - ref_transaction_update(transaction, ref->name, ref->new_sha1, - ref->old_sha1, 0, check_old, msg, &err)) + ref_transaction_update(transaction, ref->name, + ref->new_sha1, + check_old ? ref->old_sha1 : NULL, + 0, msg, &err)) goto fail; ret = ref_transaction_commit(transaction, &err); diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index e0ce78e5a0..70e9ce5f96 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -953,8 +953,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) if (ref_transaction_delete(transaction, namespaced_name, old_sha1, - 0, old_sha1 != NULL, - "push", &err)) { + 0, "push", &err)) { rp_error("%s", err.buf); strbuf_release(&err); return "failed to delete"; @@ -971,7 +970,7 @@ static const char *update(struct command *cmd, struct shallow_info *si) if (ref_transaction_update(transaction, namespaced_name, new_sha1, old_sha1, - 0, 1, "push", + 0, "push", &err)) { rp_error("%s", err.buf); strbuf_release(&err); diff --git a/builtin/replace.c b/builtin/replace.c index 85d39b58d8..54bf01acb4 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -172,7 +172,7 @@ static int replace_object_sha1(const char *object_ref, transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_update(transaction, ref, repl, prev, - 0, 1, NULL, &err) || + 0, NULL, &err) || ref_transaction_commit(transaction, &err)) die("%s", err.buf); diff --git a/builtin/tag.c b/builtin/tag.c index 6dc85a9d5e..4194b9a711 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -733,7 +733,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix) transaction = ref_transaction_begin(&err); if (!transaction || ref_transaction_update(transaction, ref.buf, object, prev, - 0, 1, NULL, &err) || + 0, NULL, &err) || ref_transaction_commit(transaction, &err)) die("%s", err.buf); ref_transaction_free(transaction); diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 2497ba4303..3d79a46b03 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -198,8 +198,9 @@ static const char *parse_cmd_update(struct ref_transaction *transaction, if (*next != line_termination) die("update %s: extra input: %s", refname, next); - if (ref_transaction_update(transaction, refname, new_sha1, old_sha1, - update_flags, have_old, msg, &err)) + if (ref_transaction_update(transaction, refname, + new_sha1, have_old ? old_sha1 : NULL, + update_flags, msg, &err)) die("%s", err.buf); update_flags = 0; @@ -264,8 +265,9 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction, if (*next != line_termination) die("delete %s: extra input: %s", refname, next); - if (ref_transaction_delete(transaction, refname, old_sha1, - update_flags, have_old, msg, &err)) + if (ref_transaction_delete(transaction, refname, + have_old ? old_sha1 : NULL, + update_flags, msg, &err)) die("%s", err.buf); update_flags = 0; @@ -280,7 +282,6 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction, { struct strbuf err = STRBUF_INIT; char *refname; - unsigned char new_sha1[20]; unsigned char old_sha1[20]; refname = parse_refname(input, &next); @@ -291,13 +292,11 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction, PARSE_SHA1_OLD)) hashclr(old_sha1); - hashcpy(new_sha1, old_sha1); - if (*next != line_termination) die("verify %s: extra input: %s", refname, next); - if (ref_transaction_update(transaction, refname, new_sha1, old_sha1, - update_flags, 1, msg, &err)) + if (ref_transaction_verify(transaction, refname, old_sha1, + update_flags, &err)) die("%s", err.buf); update_flags = 0; @@ -353,7 +352,8 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) { const char *refname, *oldval; unsigned char sha1[20], oldsha1[20]; - int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0, flags = 0; + int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0; + unsigned int flags = 0; struct option options[] = { OPT_STRING( 'm', NULL, &msg, N_("reason"), N_("reason of the update")), OPT_BOOL('d', NULL, &delete, N_("delete the reference")), |