Skip to content

Commit 3161cc6

Browse files
committed
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
2 parents f175e9b + 523fa69 commit 3161cc6

File tree

7 files changed

+51
-26
lines changed

7 files changed

+51
-26
lines changed

builtin/bisect--helper.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
1313
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
1414
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
1515
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
16-
static GIT_PATH_FUNC(git_path_bisect_head, "BISECT_HEAD")
1716
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
1817
static GIT_PATH_FUNC(git_path_head_name, "head-name")
1918
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
@@ -164,7 +163,7 @@ static int bisect_reset(const char *commit)
164163
strbuf_addstr(&branch, commit);
165164
}
166165

167-
if (!file_exists(git_path_bisect_head())) {
166+
if (!ref_exists("BISECT_HEAD")) {
168167
struct argv_array argv = ARGV_ARRAY_INIT;
169168

170169
argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);

git-bisect.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ TERM_GOOD=good
4141

4242
bisect_head()
4343
{
44-
if test -f "$GIT_DIR/BISECT_HEAD"
44+
if git rev-parse --verify -q BISECT_HEAD > /dev/null
4545
then
4646
echo BISECT_HEAD
4747
else
@@ -153,7 +153,7 @@ bisect_next() {
153153
git bisect--helper --bisect-next-check $TERM_GOOD $TERM_BAD $TERM_GOOD|| exit
154154

155155
# Perform all bisection computation, display and checkout
156-
git bisect--helper --next-all $(test -f "$GIT_DIR/BISECT_HEAD" && echo --no-checkout)
156+
git bisect--helper --next-all $(git rev-parse --verify -q BISECT_HEAD > /dev/null && echo --no-checkout)
157157
res=$?
158158

159159
# Check if we should exit because bisection is finished

refs.c

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ int delete_ref(const char *msg, const char *refname,
902902
old_oid, flags);
903903
}
904904

905-
void copy_reflog_msg(struct strbuf *sb, const char *msg)
905+
static void copy_reflog_msg(struct strbuf *sb, const char *msg)
906906
{
907907
char c;
908908
int wasspace = 1;
@@ -919,6 +919,15 @@ void copy_reflog_msg(struct strbuf *sb, const char *msg)
919919
strbuf_rtrim(sb);
920920
}
921921

922+
static char *normalize_reflog_message(const char *msg)
923+
{
924+
struct strbuf sb = STRBUF_INIT;
925+
926+
if (msg && *msg)
927+
copy_reflog_msg(&sb, msg);
928+
return strbuf_detach(&sb, NULL);
929+
}
930+
922931
int should_autocreate_reflog(const char *refname)
923932
{
924933
switch (log_all_ref_updates) {
@@ -1124,7 +1133,7 @@ struct ref_update *ref_transaction_add_update(
11241133
oidcpy(&update->new_oid, new_oid);
11251134
if (flags & REF_HAVE_OLD)
11261135
oidcpy(&update->old_oid, old_oid);
1127-
update->msg = xstrdup_or_null(msg);
1136+
update->msg = normalize_reflog_message(msg);
11281137
return update;
11291138
}
11301139

@@ -1983,9 +1992,14 @@ int refs_create_symref(struct ref_store *refs,
19831992
const char *refs_heads_master,
19841993
const char *logmsg)
19851994
{
1986-
return refs->be->create_symref(refs, ref_target,
1987-
refs_heads_master,
1988-
logmsg);
1995+
char *msg;
1996+
int retval;
1997+
1998+
msg = normalize_reflog_message(logmsg);
1999+
retval = refs->be->create_symref(refs, ref_target, refs_heads_master,
2000+
msg);
2001+
free(msg);
2002+
return retval;
19892003
}
19902004

19912005
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,
23702384
return refs->be->initial_transaction_commit(refs, transaction, err);
23712385
}
23722386

2373-
int refs_delete_refs(struct ref_store *refs, const char *msg,
2387+
int refs_delete_refs(struct ref_store *refs, const char *logmsg,
23742388
struct string_list *refnames, unsigned int flags)
23752389
{
2376-
return refs->be->delete_refs(refs, msg, refnames, flags);
2390+
char *msg;
2391+
int retval;
2392+
2393+
msg = normalize_reflog_message(logmsg);
2394+
retval = refs->be->delete_refs(refs, msg, refnames, flags);
2395+
free(msg);
2396+
return retval;
23772397
}
23782398

23792399
int delete_refs(const char *msg, struct string_list *refnames,
@@ -2385,7 +2405,13 @@ int delete_refs(const char *msg, struct string_list *refnames,
23852405
int refs_rename_ref(struct ref_store *refs, const char *oldref,
23862406
const char *newref, const char *logmsg)
23872407
{
2388-
return refs->be->rename_ref(refs, oldref, newref, logmsg);
2408+
char *msg;
2409+
int retval;
2410+
2411+
msg = normalize_reflog_message(logmsg);
2412+
retval = refs->be->rename_ref(refs, oldref, newref, msg);
2413+
free(msg);
2414+
return retval;
23892415
}
23902416

23912417
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)
23962422
int refs_copy_existing_ref(struct ref_store *refs, const char *oldref,
23972423
const char *newref, const char *logmsg)
23982424
{
2399-
return refs->be->copy_ref(refs, oldref, newref, logmsg);
2425+
char *msg;
2426+
int retval;
2427+
2428+
msg = normalize_reflog_message(logmsg);
2429+
retval = refs->be->copy_ref(refs, oldref, newref, msg);
2430+
free(msg);
2431+
return retval;
24002432
}
24012433

24022434
int copy_existing_ref(const char *oldref, const char *newref, const char *logmsg)

refs/files-backend.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1629,7 +1629,7 @@ static int log_ref_write_fd(int fd, const struct object_id *old_oid,
16291629

16301630
strbuf_addf(&sb, "%s %s %s", oid_to_hex(old_oid), oid_to_hex(new_oid), committer);
16311631
if (msg && *msg)
1632-
copy_reflog_msg(&sb, msg);
1632+
strbuf_addstr(&sb, msg);
16331633
strbuf_addch(&sb, '\n');
16341634
if (write_in_full(fd, sb.buf, sb.len) < 0)
16351635
ret = -1;

refs/refs-internal.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ enum peel_status {
9696
*/
9797
enum peel_status peel_object(const struct object_id *name, struct object_id *oid);
9898

99-
/*
100-
* Copy the reflog message msg to sb while cleaning up the whitespaces.
101-
* Especially, convert LF to space, because reflog file is one line per entry.
102-
*/
103-
void copy_reflog_msg(struct strbuf *sb, const char *msg);
104-
10599
/**
106100
* Information needed for a single ref update. Set new_oid to the new
107101
* value or to null_oid to delete the ref. To check the old value

t/lib-t6000.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
: included from 6002 and others
22

3-
mkdir -p .git/refs/tags
4-
53
>sed.script
64

75
# Answer the sha1 has associated with the tag. The tag must exist under refs/tags
@@ -26,7 +24,8 @@ save_tag () {
2624
_tag=$1
2725
test -n "$_tag" || error "usage: save_tag tag commit-args ..."
2826
shift 1
29-
"$@" >".git/refs/tags/$_tag"
27+
28+
git update-ref "refs/tags/$_tag" $("$@")
3029

3130
echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp
3231
cat sed.script >>sed.script.tmp

t/t3432-rebase-fast-forward.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,16 @@ test_rebase_same_head_ () {
6060
fi &&
6161
oldhead=\$(git rev-parse HEAD) &&
6262
test_when_finished 'git reset --hard \$oldhead' &&
63-
cp .git/logs/HEAD expect &&
63+
git reflog HEAD >expect &&
6464
git rebase$flag $* >stdout &&
65+
git reflog HEAD >actual &&
6566
if test $what = work
6667
then
6768
old=\$(wc -l <expect) &&
68-
test_line_count '-gt' \$old .git/logs/HEAD
69+
test_line_count '-gt' \$old actual
6970
elif test $what = noop
7071
then
71-
test_cmp expect .git/logs/HEAD
72+
test_cmp expect actual
7273
fi &&
7374
newhead=\$(git rev-parse HEAD) &&
7475
if test $cmp = same

0 commit comments

Comments
 (0)