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

View File

@ -13,7 +13,6 @@ static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK") static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START") static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
static GIT_PATH_FUNC(git_path_bisect_head, "BISECT_HEAD")
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG") static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
static GIT_PATH_FUNC(git_path_head_name, "head-name") static GIT_PATH_FUNC(git_path_head_name, "head-name")
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES") static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
@ -164,7 +163,7 @@ static int bisect_reset(const char *commit)
strbuf_addstr(&branch, commit); strbuf_addstr(&branch, commit);
} }
if (!file_exists(git_path_bisect_head())) { if (!ref_exists("BISECT_HEAD")) {
struct argv_array argv = ARGV_ARRAY_INIT; struct argv_array argv = ARGV_ARRAY_INIT;
argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL); argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);

View File

@ -41,7 +41,7 @@ TERM_GOOD=good
bisect_head() bisect_head()
{ {
if test -f "$GIT_DIR/BISECT_HEAD" if git rev-parse --verify -q BISECT_HEAD > /dev/null
then then
echo BISECT_HEAD echo BISECT_HEAD
else else
@ -153,7 +153,7 @@ bisect_next() {
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
# Perform all bisection computation, display and checkout # Perform all bisection computation, display and checkout
git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout) git bisect--helper --next-all $(git rev-parse --verify -q BISECT_HEAD > /dev/null && echo --no-checkout)
res=$? res=$?
# Check if we should exit because bisection is finished # Check if we should exit because bisection is finished

50
refs.c
View File

@ -902,7 +902,7 @@ int delete_ref(const char *msg, const char *refname,
old_oid, flags); 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; char c;
int wasspace = 1; int wasspace = 1;
@ -919,6 +919,15 @@ void copy_reflog_msg(struct strbuf *sb, const char *msg)
strbuf_rtrim(sb); 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) int should_autocreate_reflog(const char *refname)
{ {
switch (log_all_ref_updates) { switch (log_all_ref_updates) {
@ -1124,7 +1133,7 @@ struct ref_update *ref_transaction_add_update(
oidcpy(&update->new_oid, new_oid); oidcpy(&update->new_oid, new_oid);
if (flags & REF_HAVE_OLD) if (flags & REF_HAVE_OLD)
oidcpy(&update->old_oid, old_oid); oidcpy(&update->old_oid, old_oid);
update->msg = xstrdup_or_null(msg); update->msg = normalize_reflog_message(msg);
return update; return update;
} }
@ -1983,9 +1992,14 @@ int refs_create_symref(struct ref_store *refs,
const char *refs_heads_master, const char *refs_heads_master,
const char *logmsg) const char *logmsg)
{ {
return refs->be->create_symref(refs, ref_target, char *msg;
refs_heads_master, int retval;
logmsg);
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, 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); 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) 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, 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, int refs_rename_ref(struct ref_store *refs, const char *oldref,
const char *newref, const char *logmsg) 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) 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, int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
const char *newref, const char *logmsg) 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) int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)

View File

@ -1629,7 +1629,7 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
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)
copy_reflog_msg(&sb, msg); strbuf_addstr(&sb, msg);
strbuf_addch(&sb, '\n'); strbuf_addch(&sb, '\n');
if (write_in_full(fd, sb.buf, sb.len) < 0) if (write_in_full(fd, sb.buf, sb.len) < 0)
ret = -1; ret = -1;

View File

@ -96,12 +96,6 @@ enum peel_status {
*/ */
enum peel_status peel_object(const struct object_id *name, struct object_id *oid); enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
/*
* Copy the reflog message msg to sb while cleaning up the whitespaces.
* Especially, convert LF to space, because reflog file is one line per entry.
*/
void copy_reflog_msg(struct strbuf *sb, const char *msg);
/** /**
* Information needed for a single ref update. Set new_oid to the new * Information needed for a single ref update. Set new_oid to the new
* value or to null_oid to delete the ref. To check the old value * value or to null_oid to delete the ref. To check the old value

View File

@ -1,7 +1,5 @@
: included from 6002 and others : included from 6002 and others
mkdir -p .git/refs/tags
>sed.script >sed.script
# Answer the sha1 has associated with the tag. The tag must exist under refs/tags # Answer the sha1 has associated with the tag. The tag must exist under refs/tags
@ -26,7 +24,8 @@ save_tag () {
_tag=$1 _tag=$1
test -n "$_tag" || error "usage: save_tag tag commit-args ..." test -n "$_tag" || error "usage: save_tag tag commit-args ..."
shift 1 shift 1
"$@" >".git/refs/tags/$_tag"
git update-ref "refs/tags/$_tag" $("$@")
echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
cat sed.script >>sed.script.tmp cat sed.script >>sed.script.tmp

View File

@ -60,15 +60,16 @@ test_rebase_same_head_ () {
fi && fi &&
oldhead=\$(git rev-parse HEAD) && oldhead=\$(git rev-parse HEAD) &&
test_when_finished 'git reset --hard \$oldhead' && test_when_finished 'git reset --hard \$oldhead' &&
cp .git/logs/HEAD expect && git reflog HEAD >expect &&
git rebase$flag $* >stdout && git rebase$flag $* >stdout &&
git reflog HEAD >actual &&
if test $what = work if test $what = work
then then
old=\$(wc -l <expect) && old=\$(wc -l <expect) &&
test_line_count '-gt' \$old .git/logs/HEAD test_line_count '-gt' \$old actual
elif test $what = noop elif test $what = noop
then then
test_cmp expect .git/logs/HEAD test_cmp expect actual
fi && fi &&
newhead=\$(git rev-parse HEAD) && newhead=\$(git rev-parse HEAD) &&
if test $cmp = same if test $cmp = same