Skip to content

Commit

Permalink
WIP: set GIT_REFLOG_DATE in test_tick
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipwood committed Dec 19, 2024
1 parent 591bd5a commit 7663f9c
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 37 deletions.
4 changes: 1 addition & 3 deletions date.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,12 +1055,10 @@ void date_mode_release(struct date_mode *mode)
void datestamp(struct strbuf *out)
{
time_t now;
struct timeval tv;
int offset;
struct tm tm = { 0 };

get_time(&tv);
now = tv.tv_sec;
time(&now);

offset = tm_to_time_t(localtime_r(&now, &tm)) - now;
offset /= 60;
Expand Down
3 changes: 2 additions & 1 deletion refs/files-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1892,7 +1892,8 @@ static int files_log_ref_write(struct files_ref_store *refs,
result = log_ref_write_fd(logfd, old_oid, new_oid,
fmt_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"),
WANT_COMMITTER_IDENT, NULL, 0),
WANT_COMMITTER_IDENT,
getenv("GIT_REFLOG_DATE"), 0),
msg);
if (result) {
struct strbuf sb = STRBUF_INIT;
Expand Down
10 changes: 8 additions & 2 deletions refs/reftable-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,10 @@ static int write_transaction_table(struct reftable_writer *writer, void *cb_data
const char *committer_info;
int ret = 0;

committer_info = git_committer_info(0);
committer_info = fmt_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"),
WANT_COMMITTER_IDENT,
getenv("GIT_REFLOG_DATE"), 0);
if (split_ident_line(&committer_ident, committer_info, strlen(committer_info)))
BUG("failed splitting committer info");

Expand Down Expand Up @@ -1677,7 +1680,10 @@ static int write_copy_table(struct reftable_writer *writer, void *cb_data)
const char *committer_info;
int ret;

committer_info = git_committer_info(0);
committer_info = fmt_ident(getenv("GIT_COMMITTER_NAME"),
getenv("GIT_COMMITTER_EMAIL"),
WANT_COMMITTER_IDENT,
getenv("GIT_REFLOG_DATE"), 0);
if (split_ident_line(&committer_ident, committer_info, strlen(committer_info)))
BUG("failed splitting committer info");

Expand Down
52 changes: 28 additions & 24 deletions t/t1400-update-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -272,19 +272,19 @@ test_expect_success "clean up reflog" '

test_expect_success "create $m (logged by touch)" '
test_config core.logAllRefUpdates false &&
GIT_TEST_DATE_NOW=1117150200 \
GIT_REFLOG_DATE="2005-05-26 23:30" \
git update-ref --create-reflog HEAD $A -m "Initial Creation" &&
test $A = $(git show-ref -s --verify $m)
'
test_expect_success "update $m (logged by touch)" '
test_config core.logAllRefUpdates false &&
GIT_TEST_DATE_NOW=1117150260 \
GIT_REFLOG_DATE="2005-05-26 23:31" \
git update-ref HEAD $B $A -m "Switch" &&
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "set $m (logged by touch)" '
test_config core.logAllRefUpdates false &&
GIT_TEST_DATE_NOW=1117150860 \
GIT_REFLOG_DATE="2005-05-26 23:41" \
git update-ref HEAD $A &&
test $A = $(git show-ref -s --verify $m)
'
Expand All @@ -302,19 +302,19 @@ test_expect_success "verifying $m's log (logged by touch)" '

test_expect_success "create $m (logged by config)" '
test_config core.logAllRefUpdates true &&
GIT_TEST_DATE_NOW=1117150320 \
GIT_REFLOG_DATE="2005-05-26 23:32" \
git update-ref HEAD $A -m "Initial Creation" &&
test $A = $(git show-ref -s --verify $m)
'
test_expect_success "update $m (logged by config)" '
test_config core.logAllRefUpdates true &&
GIT_TEST_DATE_NOW=1117150380 \
GIT_REFLOG_DATE="2005-05-26 23:33" \
git update-ref HEAD $B $A -m "Switch" &&
test $B = $(git show-ref -s --verify $m)
'
test_expect_success "set $m (logged by config)" '
test_config core.logAllRefUpdates true &&
GIT_TEST_DATE_NOW=1117150980 \
GIT_REFLOG_DATE="2005-05-26 23:43" \
git update-ref HEAD $A &&
test $A = $(git show-ref -s --verify $m)
'
Expand All @@ -334,11 +334,11 @@ test_expect_success 'set up for querying the reflog' '
git update-ref -d $m &&
test-tool ref-store main delete-reflog $m &&
GIT_TEST_DATE_NOW=1117150320 TZ=CDT+5 git update-ref $m $C &&
GIT_TEST_DATE_NOW=1117150350 TZ=CDT+5 git update-ref $m $A &&
GIT_TEST_DATE_NOW=1117150380 TZ=CDT+5 git update-ref $m $B &&
GIT_TEST_DATE_NOW=1117150680 TZ=CDT+5 git update-ref $m $F &&
GIT_TEST_DATE_NOW=1117150980 TZ=CDT+5 git update-ref $m $E &&
GIT_REFLOG_DATE="1117150320 -0500" git update-ref $m $C &&
GIT_REFLOG_DATE="1117150350 -0500" git update-ref $m $A &&
GIT_REFLOG_DATE="1117150380 -0500" git update-ref $m $B &&
GIT_REFLOG_DATE="1117150680 -0500" git update-ref $m $F &&
GIT_REFLOG_DATE="1117150980 -0500" git update-ref $m $E &&
git update-ref $m $D &&
# Delete the last reflog entry so that the tip of m and the reflog for
# it disagree.
Expand Down Expand Up @@ -430,11 +430,11 @@ git update-ref -d $m
test_expect_success 'query reflog with gap' '
test_when_finished "git update-ref -d $m" &&
GIT_TEST_DATE_NOW=1117150320 TZ=CDT+5 git update-ref $m $A &&
GIT_TEST_DATE_NOW=1117150380 TZ=CDT+5 git update-ref $m $B &&
GIT_TEST_DATE_NOW=1117150480 TZ=CDT+5 git update-ref $m $C &&
GIT_TEST_DATE_NOW=1117150580 TZ=CDT+5 git update-ref $m $D &&
GIT_TEST_DATE_NOW=1117150680 TZ=CDT+5 git update-ref $m $F &&
GIT_REFLOG_DATE="1117150320 -0500" git update-ref $m $A &&
GIT_REFLOG_DATE="1117150380 -0500" git update-ref $m $B &&
GIT_REFLOG_DATE="1117150480 -0500" git update-ref $m $C &&
GIT_REFLOG_DATE="1117150580 -0500" git update-ref $m $D &&
GIT_REFLOG_DATE="1117150680 -0500" git update-ref $m $F &&
git reflog delete $m@{2} &&
git rev-parse --verify "main@{2005-05-26 23:33:01}" >actual 2>stderr &&
Expand All @@ -445,24 +445,28 @@ test_expect_success 'query reflog with gap' '

test_expect_success 'creating initial files' '
test_when_finished rm -f M &&
test_tick &&
echo TEST >F &&
git add F &&
GIT_TEST_DATE_NOW=1117150200 git commit -m add -a &&
test_tick &&
GIT_AUTHOR_DATE="2005-05-26 23:30" \
GIT_COMMITTER_DATE="2005-05-26 23:30" \
GIT_REFLOG_DATE="2005-05-26 23:30" git commit -m add -a &&
h_TEST=$(git rev-parse --verify HEAD) &&
echo The other day this did not work. >M &&
echo And then Bob told me how to fix it. >>M &&
echo OTHER >F &&
GIT_TEST_DATE_NOW=1117150860 git commit -F M -a &&
test_tick &&
GIT_AUTHOR_DATE="2005-05-26 23:41" \
GIT_COMMITTER_DATE="2005-05-26 23:41" \
GIT_REFLOG_DATE="2005-05-26 23:41" git commit -F M -a &&
h_OTHER=$(git rev-parse --verify HEAD) &&
GIT_TEST_DATE_NOW=1117151040 git commit --amend &&
test_tick &&
GIT_AUTHOR_DATE="2005-05-26 23:44" \
GIT_COMMITTER_DATE="2005-05-26 23:44" \
GIT_REFLOG_DATE="2005-05-26 23:44" git commit --amend &&
h_FIXED=$(git rev-parse --verify HEAD) &&
echo Merged initial commit and a later commit. >M &&
echo $h_TEST >.git/MERGE_HEAD &&
GIT_TEST_DATE_NOW=1117151100 git commit -F M &&
GIT_AUTHOR_DATE="2005-05-26 23:45" \
GIT_COMMITTER_DATE="2005-05-26 23:45" \
GIT_REFLOG_DATE="2005-05-26 23:45" git commit -F M &&
h_MERGED=$(git rev-parse --verify HEAD)
'

Expand Down
12 changes: 5 additions & 7 deletions t/test-lib-functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ test_tick () {
fi
GIT_COMMITTER_DATE="$test_tick -0700"
GIT_AUTHOR_DATE="$test_tick -0700"
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
GIT_REFLOG_DATE="$test_tick -0700"
export GIT_COMMITTER_DATE GIT_AUTHOR_DATE GIT_REFLOG_DATE
}

# Stop execution and start a shell. This is useful for debugging tests.
Expand Down Expand Up @@ -397,24 +398,21 @@ test_commit () {
then
test_tick
fi &&
GIT_TEST_DATE_NOW=$test_tick TZ=PDT+7 \
git ${indir:+ -C "$indir"} commit \
git ${indir:+ -C "$indir"} commit \
${author:+ --author "$author"} \
$signoff -m "$1" &&
case "$tag" in
none)
;;
light)
GIT_TEST_DATE_NOW=$test_tick TZ=PDT+7 \
git ${indir:+ -C "$indir"} tag "${4:-$1}"
git ${indir:+ -C "$indir"} tag "${4:-$1}"
;;
annotate)
if test -z "$notick"
then
test_tick
fi &&
GIT_TEST_DATE_NOW=$test_tick TZ=PDT+7 \
git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
git ${indir:+ -C "$indir"} tag -a -m "$1" "${4:-$1}"
;;
esac
}
Expand Down

0 comments on commit 7663f9c

Please sign in to comment.