Update "update-ref --stdin [-z]" and then introduce a transactional
support for (multi-)reference updates.
* mh/ref-transaction: (27 commits)
ref_transaction_commit(): work with transaction->updates in place
struct ref_update: add a type field
struct ref_update: add a lock field
ref_transaction_commit(): simplify code using temporary variables
struct ref_update: store refname as a FLEX_ARRAY
struct ref_update: rename field "ref_name" to "refname"
refs: remove API function update_refs()
update-ref --stdin: reimplement using reference transactions
refs: add a concept of a reference transaction
update-ref --stdin: harmonize error messages
update-ref --stdin: improve the error message for unexpected EOF
t1400: test one mistake at a time
update-ref --stdin -z: deprecate interpreting the empty string as zeros
update-ref.c: extract a new function, parse_next_sha1()
t1400: test that stdin -z update treats empty <newvalue> as zeros
update-ref --stdin: simplify error messages for missing oldvalues
update-ref --stdin: make error messages more consistent
update-ref --stdin: improve error messages for invalid values
update-ref.c: extract a new function, parse_refname()
parse_cmd_verify(): copy old_sha1 instead of evaluating <oldvalue> twice
...
@ -68,7 +68,12 @@ performs all modifications together. Specify commands of the form:
@@ -68,7 +68,12 @@ performs all modifications together. Specify commands of the form:
option SP <opt> LF
Quote fields containing whitespace as if they were strings in C source
code. Alternatively, use `-z` to specify commands without quoting:
code; i.e., surrounded by double-quotes and with backslash escapes.
Use 40 "0" characters or the empty string to specify a zero value. To
specify a missing value, omit the value and its preceding SP entirely.
Alternatively, use `-z` to specify in NUL-terminated format, without
@ -76,8 +81,12 @@ code. Alternatively, use `-z` to specify commands without quoting:
@@ -76,8 +81,12 @@ code. Alternatively, use `-z` to specify commands without quoting:
verify SP <ref> NUL [<oldvalue>] NUL
option SP <opt> NUL
Lines of any other format or a repeated <ref> produce an error.
Command meanings are:
In this format, use 40 "0" to specify a zero value, and use the empty
string to specify a missing value.
In either format, values can be specified in any form that Git
recognizes as an object name. Commands in any other format or a
repeated <ref> produce an error. Command meanings are:
update::
Set <ref> to <newvalue> after verifying <oldvalue>, if given.
static int ref_update_reject_duplicates(struct ref_update **updates, int n,
@ -3290,15 +3393,15 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
@@ -3290,15 +3393,15 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
{
int i;
for (i = 1; i < n; i++)
if (!strcmp(updates[i - 1]->ref_name, updates[i]->ref_name)) {
if (!strcmp(updates[i - 1]->refname, updates[i]->refname)) {
const char *str =
"Multiple updates for ref '%s' not allowed.";
switch (onerr) {
case MSG_ON_ERR:
error(str, updates[i]->ref_name); break;
case DIE_ON_ERR:
die(str, updates[i]->ref_name); break;
case QUIET_ON_ERR:
case UPDATE_REFS_MSG_ON_ERR:
error(str, updates[i]->refname); break;
case UPDATE_REFS_DIE_ON_ERR:
die(str, updates[i]->refname); break;
case UPDATE_REFS_QUIET_ON_ERR:
break;
}
return 1;
@ -3306,26 +3409,21 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
@@ -3306,26 +3409,21 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
return 0;
}
int update_refs(const char *action, const struct ref_update **updates_orig,
int n, enum action_on_err onerr)
int ref_transaction_commit(struct ref_transaction *transaction,
grep "fatal: create $a: unexpected end of input when reading <newvalue>" err
'
test_expect_success 'stdin -z fails create with too many arguments' '
@ -697,25 +721,39 @@ test_expect_success 'stdin -z fails create with too many arguments' '
@@ -697,25 +721,39 @@ test_expect_success 'stdin -z fails create with too many arguments' '
test_expect_success 'stdin -z fails update with no ref' '
grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err
'
test_expect_success 'stdin -z fails update with too many arguments' '
@ -727,7 +765,7 @@ test_expect_success 'stdin -z fails update with too many arguments' '
@@ -727,7 +765,7 @@ test_expect_success 'stdin -z fails update with too many arguments' '
test_expect_success 'stdin -z fails delete with no ref' '
grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err
'
test_expect_success 'stdin -z fails delete with too many arguments' '
@ -757,7 +795,7 @@ test_expect_success 'stdin -z fails verify with too many arguments' '
@@ -757,7 +795,7 @@ test_expect_success 'stdin -z fails verify with too many arguments' '
test_expect_success 'stdin -z fails verify with no old value' '
@ -834,14 +872,14 @@ test_expect_success 'stdin -z create ref fails with bad new value' '
@@ -834,14 +872,14 @@ test_expect_success 'stdin -z create ref fails with bad new value' '