Merge branch 'hn/reftable' into master

Preliminary clean-up of the refs API in preparation for adding a
new refs backend "reftable".

* hn/reftable:
  reflog: cleanse messages in the refs.c layer
  bisect: treat BISECT_HEAD as a pseudo ref
  t3432: use git-reflog to inspect the reflog for HEAD
  lib-t6000.sh: write tag using git-update-ref
This commit is contained in:
Junio C Hamano
2020-07-30 13:20:32 -07:00
7 changed files with 51 additions and 26 deletions

50
refs.c
View File

@ -902,7 +902,7 @@ int delete_ref(const char *msg, const char *refname,
old_oid, flags);
}
void copy_reflog_msg(struct strbuf *sb, const char *msg)
static void copy_reflog_msg(struct strbuf *sb, const char *msg)
{
char c;
int wasspace = 1;
@ -919,6 +919,15 @@ void copy_reflog_msg(struct strbuf *sb, const char *msg)
strbuf_rtrim(sb);
}
static char *normalize_reflog_message(const char *msg)
{
struct strbuf sb = STRBUF_INIT;
if (msg && *msg)
copy_reflog_msg(&sb, msg);
return strbuf_detach(&sb, NULL);
}
int should_autocreate_reflog(const char *refname)
{
switch (log_all_ref_updates) {
@ -1124,7 +1133,7 @@ struct ref_update *ref_transaction_add_update(
oidcpy(&update->new_oid, new_oid);
if (flags & REF_HAVE_OLD)
oidcpy(&update->old_oid, old_oid);
update->msg = xstrdup_or_null(msg);
update->msg = normalize_reflog_message(msg);
return update;
}
@ -1983,9 +1992,14 @@ int refs_create_symref(struct ref_store *refs,
const char *refs_heads_master,
const char *logmsg)
{
return refs->be->create_symref(refs, ref_target,
refs_heads_master,
logmsg);
char *msg;
int retval;
msg = normalize_reflog_message(logmsg);
retval = refs->be->create_symref(refs, ref_target, refs_heads_master,
msg);
free(msg);
return retval;
}
int create_symref(const char *ref_target, const char *refs_heads_master,
@ -2370,10 +2384,16 @@ int initial_ref_transaction_commit(struct ref_transaction *transaction,
return refs->be->initial_transaction_commit(refs, transaction, err);
}
int refs_delete_refs(struct ref_store *refs, const char *msg,
int refs_delete_refs(struct ref_store *refs, const char *logmsg,
struct string_list *refnames, unsigned int flags)
{
return refs->be->delete_refs(refs, msg, refnames, flags);
char *msg;
int retval;
msg = normalize_reflog_message(logmsg);
retval = refs->be->delete_refs(refs, msg, refnames, flags);
free(msg);
return retval;
}
int delete_refs(const char *msg, struct string_list *refnames,
@ -2385,7 +2405,13 @@ int delete_refs(const char *msg, struct string_list *refnames,
int refs_rename_ref(struct ref_store *refs, const char *oldref,
const char *newref, const char *logmsg)
{
return refs->be->rename_ref(refs, oldref, newref, logmsg);
char *msg;
int retval;
msg = normalize_reflog_message(logmsg);
retval = refs->be->rename_ref(refs, oldref, newref, msg);
free(msg);
return retval;
}
int rename_ref(const char *oldref, const char *newref, const char *logmsg)
@ -2396,7 +2422,13 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg)
int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
const char *newref, const char *logmsg)
{
return refs->be->copy_ref(refs, oldref, newref, logmsg);
char *msg;
int retval;
msg = normalize_reflog_message(logmsg);
retval = refs->be->copy_ref(refs, oldref, newref, msg);
free(msg);
return retval;
}
int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)