зеркало из https://github.com/microsoft/git.git
refs.c: pass the ref log message to _create/delete/update instead of _commit
Change the ref transaction API so that we pass the reflog message to the create/delete/update functions instead of to ref_transaction_commit. This allows different reflog messages for each ref update in a multi-ref transaction. Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
dbdcac7d5c
Коммит
db7516ab9f
4
branch.c
4
branch.c
|
@ -285,8 +285,8 @@ void create_branch(const char *head,
|
|||
transaction = ref_transaction_begin(&err);
|
||||
if (!transaction ||
|
||||
ref_transaction_update(transaction, ref.buf, sha1,
|
||||
null_sha1, 0, !forcing, &err) ||
|
||||
ref_transaction_commit(transaction, msg, &err))
|
||||
null_sha1, 0, !forcing, msg, &err) ||
|
||||
ref_transaction_commit(transaction, &err))
|
||||
die("%s", err.buf);
|
||||
ref_transaction_free(transaction);
|
||||
strbuf_release(&err);
|
||||
|
|
|
@ -1811,8 +1811,8 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
|
|||
ref_transaction_update(transaction, "HEAD", sha1,
|
||||
current_head
|
||||
? current_head->object.sha1 : NULL,
|
||||
0, !!current_head, &err) ||
|
||||
ref_transaction_commit(transaction, sb.buf, &err)) {
|
||||
0, !!current_head, sb.buf, &err) ||
|
||||
ref_transaction_commit(transaction, &err)) {
|
||||
rollback_index_files();
|
||||
die("%s", err.buf);
|
||||
}
|
||||
|
|
|
@ -842,8 +842,9 @@ static const char *update(struct command *cmd, struct shallow_info *si)
|
|||
transaction = ref_transaction_begin(&err);
|
||||
if (!transaction ||
|
||||
ref_transaction_update(transaction, namespaced_name,
|
||||
new_sha1, old_sha1, 0, 1, &err) ||
|
||||
ref_transaction_commit(transaction, "push", &err)) {
|
||||
new_sha1, old_sha1, 0, 1, "push",
|
||||
&err) ||
|
||||
ref_transaction_commit(transaction, &err)) {
|
||||
ref_transaction_free(transaction);
|
||||
|
||||
rp_error("%s", err.buf);
|
||||
|
|
|
@ -171,8 +171,9 @@ 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, &err) ||
|
||||
ref_transaction_commit(transaction, NULL, &err))
|
||||
ref_transaction_update(transaction, ref, repl, prev,
|
||||
0, 1, NULL, &err) ||
|
||||
ref_transaction_commit(transaction, &err))
|
||||
die("%s", err.buf);
|
||||
|
||||
ref_transaction_free(transaction);
|
||||
|
|
|
@ -733,8 +733,8 @@ 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, &err) ||
|
||||
ref_transaction_commit(transaction, NULL, &err))
|
||||
0, 1, NULL, &err) ||
|
||||
ref_transaction_commit(transaction, &err))
|
||||
die("%s", err.buf);
|
||||
ref_transaction_free(transaction);
|
||||
if (force && !is_null_sha1(prev) && hashcmp(prev, object))
|
||||
|
|
|
@ -14,6 +14,7 @@ static const char * const git_update_ref_usage[] = {
|
|||
|
||||
static char line_termination = '\n';
|
||||
static int update_flags;
|
||||
static const char *msg;
|
||||
|
||||
/*
|
||||
* Parse one whitespace- or NUL-terminated, possibly C-quoted argument
|
||||
|
@ -198,7 +199,7 @@ static const char *parse_cmd_update(struct ref_transaction *transaction,
|
|||
die("update %s: extra input: %s", refname, next);
|
||||
|
||||
if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
|
||||
update_flags, have_old, &err))
|
||||
update_flags, have_old, msg, &err))
|
||||
die("%s", err.buf);
|
||||
|
||||
update_flags = 0;
|
||||
|
@ -229,7 +230,7 @@ static const char *parse_cmd_create(struct ref_transaction *transaction,
|
|||
die("create %s: extra input: %s", refname, next);
|
||||
|
||||
if (ref_transaction_create(transaction, refname, new_sha1,
|
||||
update_flags, &err))
|
||||
update_flags, msg, &err))
|
||||
die("%s", err.buf);
|
||||
|
||||
update_flags = 0;
|
||||
|
@ -264,7 +265,7 @@ static const char *parse_cmd_delete(struct ref_transaction *transaction,
|
|||
die("delete %s: extra input: %s", refname, next);
|
||||
|
||||
if (ref_transaction_delete(transaction, refname, old_sha1,
|
||||
update_flags, have_old, &err))
|
||||
update_flags, have_old, msg, &err))
|
||||
die("%s", err.buf);
|
||||
|
||||
update_flags = 0;
|
||||
|
@ -300,7 +301,7 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
|
|||
die("verify %s: extra input: %s", refname, next);
|
||||
|
||||
if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
|
||||
update_flags, have_old, &err))
|
||||
update_flags, have_old, msg, &err))
|
||||
die("%s", err.buf);
|
||||
|
||||
update_flags = 0;
|
||||
|
@ -354,7 +355,7 @@ static void update_refs_stdin(struct ref_transaction *transaction)
|
|||
|
||||
int cmd_update_ref(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
const char *refname, *oldval, *msg = NULL;
|
||||
const char *refname, *oldval;
|
||||
unsigned char sha1[20], oldsha1[20];
|
||||
int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0, flags = 0;
|
||||
struct option options[] = {
|
||||
|
@ -385,7 +386,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
|
|||
if (end_null)
|
||||
line_termination = '\0';
|
||||
update_refs_stdin(transaction);
|
||||
if (ref_transaction_commit(transaction, msg, &err))
|
||||
if (ref_transaction_commit(transaction, &err))
|
||||
die("%s", err.buf);
|
||||
ref_transaction_free(transaction);
|
||||
strbuf_release(&err);
|
||||
|
|
|
@ -1716,8 +1716,8 @@ static int update_branch(struct branch *b)
|
|||
transaction = ref_transaction_begin(&err);
|
||||
if (!transaction ||
|
||||
ref_transaction_update(transaction, b->name, b->sha1, old_sha1,
|
||||
0, 1, &err) ||
|
||||
ref_transaction_commit(transaction, msg, &err)) {
|
||||
0, 1, msg, &err) ||
|
||||
ref_transaction_commit(transaction, &err)) {
|
||||
ref_transaction_free(transaction);
|
||||
error("%s", err.buf);
|
||||
strbuf_release(&err);
|
||||
|
@ -1757,12 +1757,12 @@ static void dump_tags(void)
|
|||
strbuf_addf(&ref_name, "refs/tags/%s", t->name);
|
||||
|
||||
if (ref_transaction_update(transaction, ref_name.buf, t->sha1,
|
||||
NULL, 0, 0, &err)) {
|
||||
NULL, 0, 0, msg, &err)) {
|
||||
failure |= error("%s", err.buf);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
if (ref_transaction_commit(transaction, msg, &err))
|
||||
if (ref_transaction_commit(transaction, &err))
|
||||
failure |= error("%s", err.buf);
|
||||
|
||||
cleanup:
|
||||
|
|
34
refs.c
34
refs.c
|
@ -2445,8 +2445,8 @@ static void prune_ref(struct ref_to_prune *r)
|
|||
transaction = ref_transaction_begin(&err);
|
||||
if (!transaction ||
|
||||
ref_transaction_delete(transaction, r->name, r->sha1,
|
||||
REF_ISPRUNING, 1, &err) ||
|
||||
ref_transaction_commit(transaction, NULL, &err)) {
|
||||
REF_ISPRUNING, 1, NULL, &err) ||
|
||||
ref_transaction_commit(transaction, &err)) {
|
||||
ref_transaction_free(transaction);
|
||||
error("%s", err.buf);
|
||||
strbuf_release(&err);
|
||||
|
@ -2621,8 +2621,8 @@ int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
|
|||
transaction = ref_transaction_begin(&err);
|
||||
if (!transaction ||
|
||||
ref_transaction_delete(transaction, refname, sha1, delopt,
|
||||
sha1 && !is_null_sha1(sha1), &err) ||
|
||||
ref_transaction_commit(transaction, NULL, &err)) {
|
||||
sha1 && !is_null_sha1(sha1), NULL, &err) ||
|
||||
ref_transaction_commit(transaction, &err)) {
|
||||
error("%s", err.buf);
|
||||
ref_transaction_free(transaction);
|
||||
strbuf_release(&err);
|
||||
|
@ -3404,6 +3404,7 @@ struct ref_update {
|
|||
int have_old; /* 1 if old_sha1 is valid, 0 otherwise */
|
||||
struct ref_lock *lock;
|
||||
int type;
|
||||
char *msg;
|
||||
const char refname[FLEX_ARRAY];
|
||||
};
|
||||
|
||||
|
@ -3446,9 +3447,10 @@ void ref_transaction_free(struct ref_transaction *transaction)
|
|||
if (!transaction)
|
||||
return;
|
||||
|
||||
for (i = 0; i < transaction->nr; i++)
|
||||
for (i = 0; i < transaction->nr; i++) {
|
||||
free(transaction->updates[i]->msg);
|
||||
free(transaction->updates[i]);
|
||||
|
||||
}
|
||||
free(transaction->updates);
|
||||
free(transaction);
|
||||
}
|
||||
|
@ -3469,7 +3471,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
|||
const char *refname,
|
||||
const unsigned char *new_sha1,
|
||||
const unsigned char *old_sha1,
|
||||
int flags, int have_old,
|
||||
int flags, int have_old, const char *msg,
|
||||
struct strbuf *err)
|
||||
{
|
||||
struct ref_update *update;
|
||||
|
@ -3486,13 +3488,15 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
|||
update->have_old = have_old;
|
||||
if (have_old)
|
||||
hashcpy(update->old_sha1, old_sha1);
|
||||
if (msg)
|
||||
update->msg = xstrdup(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ref_transaction_create(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const unsigned char *new_sha1,
|
||||
int flags,
|
||||
int flags, const char *msg,
|
||||
struct strbuf *err)
|
||||
{
|
||||
struct ref_update *update;
|
||||
|
@ -3509,13 +3513,15 @@ int ref_transaction_create(struct ref_transaction *transaction,
|
|||
hashclr(update->old_sha1);
|
||||
update->flags = flags;
|
||||
update->have_old = 1;
|
||||
if (msg)
|
||||
update->msg = xstrdup(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ref_transaction_delete(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const unsigned char *old_sha1,
|
||||
int flags, int have_old,
|
||||
int flags, int have_old, const char *msg,
|
||||
struct strbuf *err)
|
||||
{
|
||||
struct ref_update *update;
|
||||
|
@ -3533,6 +3539,8 @@ int ref_transaction_delete(struct ref_transaction *transaction,
|
|||
assert(!is_null_sha1(old_sha1));
|
||||
hashcpy(update->old_sha1, old_sha1);
|
||||
}
|
||||
if (msg)
|
||||
update->msg = xstrdup(msg);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -3546,8 +3554,8 @@ int update_ref(const char *action, const char *refname,
|
|||
t = ref_transaction_begin(&err);
|
||||
if (!t ||
|
||||
ref_transaction_update(t, refname, sha1, oldval, flags,
|
||||
!!oldval, &err) ||
|
||||
ref_transaction_commit(t, action, &err)) {
|
||||
!!oldval, action, &err) ||
|
||||
ref_transaction_commit(t, &err)) {
|
||||
const char *str = "update_ref failed for ref '%s': %s";
|
||||
|
||||
ref_transaction_free(t);
|
||||
|
@ -3593,7 +3601,7 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n,
|
|||
}
|
||||
|
||||
int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
const char *msg, struct strbuf *err)
|
||||
struct strbuf *err)
|
||||
{
|
||||
int ret = 0, delnum = 0, i;
|
||||
const char **delnames;
|
||||
|
@ -3642,7 +3650,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,
|
|||
|
||||
if (!is_null_sha1(update->new_sha1)) {
|
||||
ret = write_ref_sha1(update->lock, update->new_sha1,
|
||||
msg);
|
||||
update->msg);
|
||||
update->lock = NULL; /* freed by write_ref_sha1 */
|
||||
if (ret) {
|
||||
if (err)
|
||||
|
|
12
refs.h
12
refs.h
|
@ -274,8 +274,8 @@ struct ref_transaction *ref_transaction_begin(struct strbuf *err);
|
|||
* The following functions add a reference check or update to a
|
||||
* ref_transaction. In all of them, refname is the name of the
|
||||
* reference to be affected. The functions make internal copies of
|
||||
* refname, so the caller retains ownership of the parameter. flags
|
||||
* can be REF_NODEREF; it is passed to update_ref_lock().
|
||||
* refname and msg, so the caller retains ownership of these parameters.
|
||||
* flags can be REF_NODEREF; it is passed to update_ref_lock().
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -292,7 +292,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
|||
const char *refname,
|
||||
const unsigned char *new_sha1,
|
||||
const unsigned char *old_sha1,
|
||||
int flags, int have_old,
|
||||
int flags, int have_old, const char *msg,
|
||||
struct strbuf *err);
|
||||
|
||||
/*
|
||||
|
@ -307,7 +307,7 @@ int ref_transaction_update(struct ref_transaction *transaction,
|
|||
int ref_transaction_create(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const unsigned char *new_sha1,
|
||||
int flags,
|
||||
int flags, const char *msg,
|
||||
struct strbuf *err);
|
||||
|
||||
/*
|
||||
|
@ -321,7 +321,7 @@ int ref_transaction_create(struct ref_transaction *transaction,
|
|||
int ref_transaction_delete(struct ref_transaction *transaction,
|
||||
const char *refname,
|
||||
const unsigned char *old_sha1,
|
||||
int flags, int have_old,
|
||||
int flags, int have_old, const char *msg,
|
||||
struct strbuf *err);
|
||||
|
||||
/*
|
||||
|
@ -330,7 +330,7 @@ int ref_transaction_delete(struct ref_transaction *transaction,
|
|||
* problem.
|
||||
*/
|
||||
int ref_transaction_commit(struct ref_transaction *transaction,
|
||||
const char *msg, struct strbuf *err);
|
||||
struct strbuf *err);
|
||||
|
||||
/*
|
||||
* Free an existing transaction and all associated data.
|
||||
|
|
|
@ -252,8 +252,8 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
|
|||
if (!transaction ||
|
||||
ref_transaction_update(transaction, "HEAD",
|
||||
to, unborn ? null_sha1 : from,
|
||||
0, 1, &err) ||
|
||||
ref_transaction_commit(transaction, sb.buf, &err)) {
|
||||
0, 1, sb.buf, &err) ||
|
||||
ref_transaction_commit(transaction, &err)) {
|
||||
ref_transaction_free(transaction);
|
||||
error("%s", err.buf);
|
||||
strbuf_release(&sb);
|
||||
|
|
5
walker.c
5
walker.c
|
@ -300,14 +300,13 @@ int walker_fetch(struct walker *walker, int targets, char **target,
|
|||
strbuf_addf(&refname, "refs/%s", write_ref[i]);
|
||||
if (ref_transaction_update(transaction, refname.buf,
|
||||
&sha1[20 * i], NULL, 0, 0,
|
||||
msg ? msg : "fetch (unknown)",
|
||||
&err)) {
|
||||
error("%s", err.buf);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
if (ref_transaction_commit(transaction,
|
||||
msg ? msg : "fetch (unknown)",
|
||||
&err)) {
|
||||
if (ref_transaction_commit(transaction, &err)) {
|
||||
error("%s", err.buf);
|
||||
goto done;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче