refs: include committer info in `ref_update` struct
The reference backends obtain the committer information from `git_committer_info(0)` when adding a reflog. The upcoming patches introduce support for migrating reflogs between the reference backends. This requires an interface to creating reflogs, including custom committer information. Add a new field `committer_info` to the `ref_update` struct, which is then used by the reference backends. If there is no `committer_info` provided, the reference backends default to using `git_committer_info(0)`. The field itself cannot be set to `git_committer_info(0)` since the values are dynamic and must be obtained right when the reflog is being committed. Signed-off-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>maint
parent
df5d7a7ba5
commit
1a83e26d72
1
refs.c
1
refs.c
|
|
@ -1151,6 +1151,7 @@ void ref_transaction_free(struct ref_transaction *transaction)
|
||||||
|
|
||||||
for (i = 0; i < transaction->nr; i++) {
|
for (i = 0; i < transaction->nr; i++) {
|
||||||
free(transaction->updates[i]->msg);
|
free(transaction->updates[i]->msg);
|
||||||
|
free(transaction->updates[i]->committer_info);
|
||||||
free((char *)transaction->updates[i]->new_target);
|
free((char *)transaction->updates[i]->new_target);
|
||||||
free((char *)transaction->updates[i]->old_target);
|
free((char *)transaction->updates[i]->old_target);
|
||||||
free(transaction->updates[i]);
|
free(transaction->updates[i]);
|
||||||
|
|
|
||||||
|
|
@ -1858,6 +1858,9 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
if (!committer)
|
||||||
|
committer = git_committer_info(0);
|
||||||
|
|
||||||
strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
|
strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
|
||||||
if (msg && *msg) {
|
if (msg && *msg) {
|
||||||
strbuf_addch(&sb, '\t');
|
strbuf_addch(&sb, '\t');
|
||||||
|
|
@ -1871,8 +1874,10 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
|
||||||
}
|
}
|
||||||
|
|
||||||
static int files_log_ref_write(struct files_ref_store *refs,
|
static int files_log_ref_write(struct files_ref_store *refs,
|
||||||
const char *refname, const struct object_id *old_oid,
|
const char *refname,
|
||||||
const struct object_id *new_oid, const char *msg,
|
const struct object_id *old_oid,
|
||||||
|
const struct object_id *new_oid,
|
||||||
|
const char *committer_info, const char *msg,
|
||||||
int flags, struct strbuf *err)
|
int flags, struct strbuf *err)
|
||||||
{
|
{
|
||||||
int logfd, result;
|
int logfd, result;
|
||||||
|
|
@ -1889,8 +1894,7 @@ static int files_log_ref_write(struct files_ref_store *refs,
|
||||||
|
|
||||||
if (logfd < 0)
|
if (logfd < 0)
|
||||||
return 0;
|
return 0;
|
||||||
result = log_ref_write_fd(logfd, old_oid, new_oid,
|
result = log_ref_write_fd(logfd, old_oid, new_oid, committer_info, msg);
|
||||||
git_committer_info(0), msg);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
struct strbuf sb = STRBUF_INIT;
|
struct strbuf sb = STRBUF_INIT;
|
||||||
int save_errno = errno;
|
int save_errno = errno;
|
||||||
|
|
@ -1974,8 +1978,7 @@ static int commit_ref_update(struct files_ref_store *refs,
|
||||||
files_assert_main_repository(refs, "commit_ref_update");
|
files_assert_main_repository(refs, "commit_ref_update");
|
||||||
|
|
||||||
clear_loose_ref_cache(refs);
|
clear_loose_ref_cache(refs);
|
||||||
if (files_log_ref_write(refs, lock->ref_name,
|
if (files_log_ref_write(refs, lock->ref_name, &lock->old_oid, oid, NULL,
|
||||||
&lock->old_oid, oid,
|
|
||||||
logmsg, flags, err)) {
|
logmsg, flags, err)) {
|
||||||
char *old_msg = strbuf_detach(err, NULL);
|
char *old_msg = strbuf_detach(err, NULL);
|
||||||
strbuf_addf(err, "cannot update the ref '%s': %s",
|
strbuf_addf(err, "cannot update the ref '%s': %s",
|
||||||
|
|
@ -2007,9 +2010,9 @@ static int commit_ref_update(struct files_ref_store *refs,
|
||||||
if (head_ref && (head_flag & REF_ISSYMREF) &&
|
if (head_ref && (head_flag & REF_ISSYMREF) &&
|
||||||
!strcmp(head_ref, lock->ref_name)) {
|
!strcmp(head_ref, lock->ref_name)) {
|
||||||
struct strbuf log_err = STRBUF_INIT;
|
struct strbuf log_err = STRBUF_INIT;
|
||||||
if (files_log_ref_write(refs, "HEAD",
|
if (files_log_ref_write(refs, "HEAD", &lock->old_oid,
|
||||||
&lock->old_oid, oid,
|
oid, NULL, logmsg, flags,
|
||||||
logmsg, flags, &log_err)) {
|
&log_err)) {
|
||||||
error("%s", log_err.buf);
|
error("%s", log_err.buf);
|
||||||
strbuf_release(&log_err);
|
strbuf_release(&log_err);
|
||||||
}
|
}
|
||||||
|
|
@ -2969,7 +2972,8 @@ static int parse_and_write_reflog(struct files_ref_store *refs,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (files_log_ref_write(refs, lock->ref_name, &lock->old_oid,
|
if (files_log_ref_write(refs, lock->ref_name, &lock->old_oid,
|
||||||
&update->new_oid, update->msg, update->flags, err)) {
|
&update->new_oid, update->committer_info,
|
||||||
|
update->msg, update->flags, err)) {
|
||||||
char *old_msg = strbuf_detach(err, NULL);
|
char *old_msg = strbuf_detach(err, NULL);
|
||||||
|
|
||||||
strbuf_addf(err, "cannot update the ref '%s': %s",
|
strbuf_addf(err, "cannot update the ref '%s': %s",
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,7 @@ struct ref_update {
|
||||||
void *backend_data;
|
void *backend_data;
|
||||||
unsigned int type;
|
unsigned int type;
|
||||||
char *msg;
|
char *msg;
|
||||||
|
char *committer_info;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If this ref_update was split off of a symref update via
|
* If this ref_update was split off of a symref update via
|
||||||
|
|
|
||||||
|
|
@ -1379,11 +1379,21 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
|
||||||
}
|
}
|
||||||
|
|
||||||
if (create_reflog) {
|
if (create_reflog) {
|
||||||
|
struct ident_split c;
|
||||||
|
|
||||||
ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
|
ALLOC_GROW(logs, logs_nr + 1, logs_alloc);
|
||||||
log = &logs[logs_nr++];
|
log = &logs[logs_nr++];
|
||||||
memset(log, 0, sizeof(*log));
|
memset(log, 0, sizeof(*log));
|
||||||
|
|
||||||
fill_reftable_log_record(log, &committer_ident);
|
if (u->committer_info) {
|
||||||
|
if (split_ident_line(&c, u->committer_info,
|
||||||
|
strlen(u->committer_info)))
|
||||||
|
BUG("failed splitting committer info");
|
||||||
|
} else {
|
||||||
|
c = committer_ident;
|
||||||
|
}
|
||||||
|
|
||||||
|
fill_reftable_log_record(log, &c);
|
||||||
log->update_index = ts;
|
log->update_index = ts;
|
||||||
log->refname = xstrdup(u->refname);
|
log->refname = xstrdup(u->refname);
|
||||||
memcpy(log->value.update.new_hash,
|
memcpy(log->value.update.new_hash,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue