Add test-chmtime: a utility to change mtime on files
PATCH 1/1 Add test-chmtime: a utility to change mtime on files
This is intended to be a portable replacement for our usage of date(1), touch(1), and Perl one-liners in tests.
Usage: test-chtime (+|=|-)<seconds> <file_1> [<file_2>]"
'+' increments the mtime on the file by <seconds> '-' decrements the mtime on the file by <seconds> '=' sets the mtime on the file to exactly <seconds>
--- .gitignore | 1 + Makefile | 4 +++- test-chmtime.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletions(-) create mode 100644 test-chmtime.c
.gitignore +1 -0
@@ -139,6 +139,7 @@ git-whatchanged git-write-tree git-core-*/?* gitweb/gitweb.cgi +test-chmtime test-date test-delta test-dump-cache-tree
Makefile +3 -1
@@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS export NO_SVN_TESTS -test: all +test: all test-chmtime$X $(MAKE) -C t/ all test-date$X: test-date.c date.o ctype.o
@@ -844,6 +844,8 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS) test-sha1$X: test-sha1.o $(GITLIBS) $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +test-chmtime$X: test-chmtime.o + check-sha1:: test-sha1$X ./test-sha1.sh
test-chmtime.c new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.5.0.137.ge6502
PATCH 1/1 Update tests to use test-chmtime
t4200-rerere:
Removed non-portable date dependency and avoid touch Avoid "test -a" which isn't portable, either
lib-git-svn:
Use test-chmtime instead of Perl one-liner to poke
--- t/lib-git-svn.sh | 2 +- t/t4200-rerere.sh | 54 ++++++++++++++++++++-------------------------------- 2 files changed, 22 insertions(+), 34 deletions(-)
t/lib-git-svn.sh +1 -1
@@ -46,5 +46,5 @@ rawsvnrepo="$svnrepo" svnrepo="file://$svnrepo" poke() { - perl -e '@x = stat($ARGV[0]); utime($x[8], $x[9] + 1, $ARGV[0])' "$1" + test-chmtime +1 "$1" }
t/t4200-rerere.sh +21 -33
60 lines not on this page · raw message
Signature · 1 line
1.5.0.137.ge6502
Re: [PATCH] Update tests to use test-chmtime
Quoted 5 lines · Eric Wong
(quoted diff) +0
-4-case "$(date -d @11111111 +%s 2>/dev/null)" in -11111111) - touch -m -t "$predate1" $rr/preimage - touch -m -t "$predate2" $rr2/preimage
Review
Quoted 10 lines
(quoted diff) +8
-1-esac +now=$(date +%s) +almost_15_days_ago=$(($now+60-15*86400)) +just_over_15_days_ago=$(($now-1-15*86400)) +almost_60_days_ago=$(($now+60-60*86400)) +just_over_60_days_ago=$(($now-1-60*86400)) + +test-chmtime =$almost_60_days_ago $rr/preimage +test-chmtime =$almost_15_days_ago $rr2/preimage
Very nice.
I've been wanting to get rid of this part for quite a while.
However, is '+%s' output portable enough for this change to be an improvement?
I would suggest changing "test-chmtime =-200 file" to set the mtime of the file to 200 seconds in the past, relative to present.
---
t/t4200-rerere.sh +4 -5
@@ -112,11 +112,10 @@ rr2=.git/rr-cache/$sha2 mkdir $rr2 echo Hello > $rr2/preimage -now=$(date +%s) -almost_15_days_ago=$(($now+60-15*86400)) -just_over_15_days_ago=$(($now-1-15*86400)) -almost_60_days_ago=$(($now+60-60*86400)) -just_over_60_days_ago=$(($now-1-60*86400)) +almost_15_days_ago=$((60-15*86400)) +just_over_15_days_ago=$((-1-15*86400)) +almost_60_days_ago=$((60-60*86400)) +just_over_60_days_ago=$((-1-60*86400)) test-chmtime =$almost_60_days_ago $rr/preimage test-chmtime =$almost_15_days_ago $rr2/preimage
test-chmtime.c +5 -1
@@ -1,7 +1,7 @@#include "git-compat-util.h" #include <utime.h> -static const char usage_str[] ="(+|=|-)<seconds> <file_1> [<file_2>]" ; +static const char usage_str[] ="(+|=|-)<seconds> <file_1>..." ;int main (int argc,const char *argv[]) {
@@ -19,6 +19,10 @@ int main(int argc, const char *argv[])fprintf (stderr,"Not a base-10 integer: %s\n" , argv[1 ] +1 ); goto usage; } +if (set_eq && set_time <0 ) { +time_t now =time (NULL ); + set_time += now; + }for (i =2 ; i < argc; i++) {struct stat sb;
Re: [PATCH] Update tests to use test-chmtime
Quoted 21 lines · Junio C Hamano
Quoted 5 lines · Eric Wong
(quoted diff) +0
-4-case "$(date -d @11111111 +%s 2>/dev/null)" in -11111111) - touch -m -t "$predate1" $rr/preimage - touch -m -t "$predate2" $rr2/preimageReview
Quoted 10 lines
(quoted diff) +8
-1-esac +now=$(date +%s) +almost_15_days_ago=$(($now+60-15*86400)) +just_over_15_days_ago=$(($now-1-15*86400)) +almost_60_days_ago=$(($now+60-60*86400)) +just_over_60_days_ago=$(($now-1-60*86400)) + +test-chmtime =$almost_60_days_ago $rr/preimage +test-chmtime =$almost_15_days_ago $rr2/preimageVery nice.
I've been wanting to get rid of this part for quite a while.
Quoted 2 lines
However, is '+%s' output portable enough for this change to be an improvement?
Looks like not.
t/t4200-rerere.sh
Quoted 7 lines
I would suggest changing "test-chmtime =-200 file" to set the mtime of the file to 200 seconds in the past, relative to present.
---
t/t4200-rerere.sh +0
-0
Your patch looks good to me.
Signature · 1 line
Eric Wong
Re: [PATCH] Update tests to use test-chmtime
Quoted 11 lines · Eric Wong
t/t4200-rerere.sh
Quoted 8 lines · Junio C Hamano
...
I would suggest changing "test-chmtime =-200 file" to set the mtime of the file to 200 seconds in the past, relative to present.---
t/t4200-rerere.sh +0
-0Your patch looks good to me.
Thanks. Here is the final version I'll push out in 'master' shortly.
-- >8 --
From: Eric Wong <[email protected]>
Date: Sat, 24 Feb 2007 18:18:22 -0800
Subject: [PATCH] Add test-chmtime: a utility to change mtime on files
This is intended to be a portable replacement for our usage of date(1), touch(1), and Perl one-liners in tests.
Usage: test-chtime (+|=|-|=+|=-)<seconds> <file>..."
'+' increments the mtime on the files by <seconds> '-' decrements the mtime on the files by <seconds> '=' sets the mtime on the file to exactly <seconds> '=+' and '=-' sets the mtime on the file to <seconds> after or
before the current time.
--- .gitignore | 1 + Makefile | 5 +++- test-chmtime.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletions(-) create mode 100644 test-chmtime.c
.gitignore +1 -0
@@ -139,6 +139,7 @@ git-whatchanged git-write-tree git-core-*/?* gitweb/gitweb.cgi +test-chmtime test-date test-delta test-dump-cache-tree
Makefile +4 -1
@@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS export NO_SVN_TESTS -test: all +test: all test-chmtime$X $(MAKE) -C t/ all test-date$X: test-date.c date.o ctype.o
@@ -844,6 +844,9 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS) test-sha1$X: test-sha1.o $(GITLIBS) $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +test-chmtime$X: test-chmtime.c + $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $< + check-sha1:: test-sha1$X ./test-sha1.sh
test-chmtime.c new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
1.5.0.1.791.g4c9a
Re: [PATCH] Update tests to use test-chmtime
In reply to Junio C HamanoHi,
Quoted 21 lines · Junio C Hamano
Quoted 5 lines · Eric Wong
(quoted diff) +0
-4-case "$(date -d @11111111 +%s 2>/dev/null)" in -11111111) - touch -m -t "$predate1" $rr/preimage - touch -m -t "$predate2" $rr2/preimageReview
Quoted 10 lines
(quoted diff) +8
-1-esac +now=$(date +%s) +almost_15_days_ago=$(($now+60-15*86400)) +just_over_15_days_ago=$(($now-1-15*86400)) +almost_60_days_ago=$(($now+60-60*86400)) +just_over_60_days_ago=$(($now-1-60*86400)) + +test-chmtime =$almost_60_days_ago $rr/preimage +test-chmtime =$almost_15_days_ago $rr2/preimageVery nice.
I've been wanting to get rid of this part for quite a while.
Quoted 2 lines
However, is '+%s' output portable enough for this change to be an improvement?
It is not portable, but according to the man page:
%s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)
Quoted 2 lines
I would suggest changing "test-chmtime =-200 file" to set the mtime of the file to 200 seconds in the past, relative to present.
I wanted to propose the same, but without a patch :-)
Ciao,
Dscho
PATCH 1/1 Add test-chmtime: a utility to change mtime on files
In reply to Eric WongThis is intended to be a portable replacement for our usage of date(1), touch(1), and Perl one-liners in tests.
Usage: test-chtime (+|=|-)<seconds> <file_1> [<file_2>]"
'+' increments the mtime on the file by <seconds> '-' decrements the mtime on the file by <seconds> '=' sets the mtime on the file to exactly <seconds>
---
Fixing an ugly dependency in the original, the .o file is never used.
Makefile test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS) · line 851
Quoted 11 lines · Eric Wong
Makefile +2
-0@@ -844,6 +844,8 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS) test-sha1$X: test-sha1.o $(GITLIBS) $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +test-chmtime$X: test-chmtime.o + check-sha1:: test-sha1$X ./test-sha1.sh
.gitignore | 1 + Makefile | 5 ++++- test-chmtime.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 1 deletions(-) create mode 100644 test-chmtime.c
.gitignore +1 -0
@@ -139,6 +139,7 @@ git-whatchanged git-write-tree git-core-*/?* gitweb/gitweb.cgi +test-chmtime test-date test-delta test-dump-cache-tree
Makefile +4 -1
@@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS export NO_SVN_TESTS -test: all +test: all test-chmtime$X $(MAKE) -C t/ all test-date$X: test-date.c date.o ctype.o
@@ -844,6 +844,9 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS) test-sha1$X: test-sha1.o $(GITLIBS) $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) +test-chmtime$X: test-chmtime.c + $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $< + check-sha1:: test-sha1$X ./test-sha1.sh
test-chmtime.c new file +48 -0
48 lines not on this page · raw message
Signature · 1 line
1.5.0.137.ge6502
Hi,
Quoted 2 lines · Eric Wong
This is intended to be a portable replacement for our usage of date(1), touch(1), and Perl one-liners in tests.
This is a cute idea!
Makefile GIT-CFLAGS: .FORCE-GIT-CFLAGS · line 832
Quoted 10 lines
Makefile +1
-1@@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS export NO_SVN_TESTS -test: all +test: all test-chmtime$X
That is nice! This says that the program should be only compiled before running the tests. However, you can run the tests also by "cd t; make", and even by "cd t; sh tDDDD-*.sh", so I think a check in the tests should be added, which tests for executability of test-chmtime.
Ciao,
Dscho
As brought up by Johannes Schindelin, some people run tests within the t/ directory and often without make. We need to check and inform those users to build test-chmtime before running those tests.
--- t/test-lib.sh | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
t/test-lib.sh +6 -0
@@ -264,6 +264,12 @@ test -d ../templates/blt || { error "You haven't built things yet, have you?" } +if ! test -x ../test-chmtime; then + echo >&2 'You need to build test-chmtime:' + echo >&2 'Run "make test-chmtime" in the source (toplevel) directory' + exit 1 +fi + # Test repository test=trash rm -fr "$test"
Signature · 1 line
1.5.0.137.ge6502