{"thread":{"id":"6944","subject":"[PATCH] Add test-chmtime: a utility to change mtime on files","startedAt":"2007-02-25T00:59:51Z","lastAt":"2007-02-25T19:33:14Z","messageCount":9,"participants":["Eric Wong","Johannes Schindelin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"35408","messageId":"11723651923476-git-send-email-normalperson@yhbt.net","threadId":"6944","inReplyTo":null,"subject":"[PATCH] Add test-chmtime: a utility to change mtime on files","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-02-25T00:59:51Z","receivedAt":"2007-02-25T00:59:51Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"This is intended to be a portable replacement for our usage\nof date(1), touch(1), and Perl one-liners in tests.\n\nUsage: test-chtime (+|=|-)<seconds> <file_1> [<file_2>]\"\n\n  '+' increments the mtime on the file by <seconds>\n  '-' decrements the mtime on the file by <seconds>\n  '=' sets the mtime on the file to exactly <seconds>\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n .gitignore     |    1 +\n Makefile       |    4 +++-\n test-chmtime.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 52 insertions(+), 1 deletions(-)\n create mode 100644 test-chmtime.c\n\ndiff --git a/.gitignore b/.gitignore\nindex f15155d..eb8a1f8 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -139,6 +139,7 @@ git-whatchanged\n git-write-tree\n git-core-*/?*\n gitweb/gitweb.cgi\n+test-chmtime\n test-date\n test-delta\n test-dump-cache-tree\ndiff --git a/Makefile b/Makefile\nindex e51b448..105f3ec 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS\n \n export NO_SVN_TESTS\n \n-test: all\n+test: all test-chmtime$X\n \t$(MAKE) -C t/ all\n \n test-date$X: test-date.c date.o ctype.o\n@@ -844,6 +844,8 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)\n test-sha1$X: test-sha1.o $(GITLIBS)\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n \n+test-chmtime$X: test-chmtime.o\n+\n check-sha1:: test-sha1$X\n \t./test-sha1.sh\n \ndiff --git a/test-chmtime.c b/test-chmtime.c\nnew file mode 100644\nindex 0000000..69b3ba9\n--- /dev/null\n+++ b/test-chmtime.c\n@@ -0,0 +1,48 @@\n+#include \"git-compat-util.h\"\n+#include <utime.h>\n+\n+static const char usage_str[] = \"(+|=|-)<seconds> <file_1> [<file_2>]\";\n+\n+int main(int argc, const char *argv[])\n+{\n+\tint i;\n+\tint set_eq;\n+\tlong int set_time;\n+\tchar *test;\n+\n+\tif (argc < 3)\n+\t\tgoto usage;\n+\n+\tset_eq = (argv[1][0] == '=') ? 1 : 0;\n+\tset_time = strtol(argv[1] + set_eq, &test, 10);\n+\tif (*test) {\n+\t\tfprintf(stderr, \"Not a base-10 integer: %s\\n\", argv[1] + 1);\n+\t\tgoto usage;\n+\t}\n+\n+\tfor (i = 2; i < argc; i++) {\n+\t\tstruct stat sb;\n+\t\tstruct utimbuf utb;\n+\n+\t\tif (stat(argv[i], &sb) < 0) {\n+\t\t\tfprintf(stderr, \"Failed to stat %s: %s\\n\",\n+\t\t\t        argv[i], strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tutb.actime = sb.st_atime;\n+\t\tutb.modtime = set_eq ? set_time : sb.st_mtime + set_time;\n+\n+\t\tif (utime(argv[i], &utb) < 0) {\n+\t\t\tfprintf(stderr, \"Failed to modify time on %s: %s\\n\",\n+\t\t\t        argv[i], strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+\n+usage:\n+\tfprintf(stderr, \"Usage: %s %s\\n\", argv[0], usage_str);\n+\treturn -1;\n+}\n-- \n1.5.0.137.ge6502\n"},{"id":"35409","messageId":"11723651934078-git-send-email-normalperson@yhbt.net","threadId":"6944","inReplyTo":"11723651923476-git-send-email-normalperson@yhbt.net","subject":"[PATCH] Update tests to use test-chmtime","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-02-25T00:59:52Z","receivedAt":"2007-02-25T00:59:52Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"t4200-rerere:\n  Removed non-portable date dependency and avoid touch\n  Avoid \"test -a\" which isn't portable, either\n\nlib-git-svn:\n  Use test-chmtime instead of Perl one-liner to poke\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n t/lib-git-svn.sh  |    2 +-\n t/t4200-rerere.sh |   54 ++++++++++++++++++++--------------------------------\n 2 files changed, 22 insertions(+), 34 deletions(-)\n\ndiff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh\nindex 27ad3b7..f6fe78c 100644\n--- a/t/lib-git-svn.sh\n+++ b/t/lib-git-svn.sh\n@@ -46,5 +46,5 @@ rawsvnrepo=\"$svnrepo\"\n svnrepo=\"file://$svnrepo\"\n \n poke() {\n-\tperl -e '@x = stat($ARGV[0]); utime($x[8], $x[9] + 1, $ARGV[0])' \"$1\"\n+\ttest-chmtime +1 \"$1\"\n }\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex c571a1b..d5bb6ec 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -112,39 +112,27 @@ rr2=.git/rr-cache/$sha2\n mkdir $rr2\n echo Hello > $rr2/preimage\n \n-case \"$(date -d @11111111 +%s 2>/dev/null)\" in\n-11111111)\n-\t# 'date' must be able to take arbitrary input with @11111111 notation.\n-\t# for this test to succeed.  We should fix this part using more\n-\t# portable script someday.\n-\n-\tnow=$(date +%s)\n-\talmost_15_days_ago=$(($now+60-15*86400))\n-\tjust_over_15_days_ago=$(($now-1-15*86400))\n-\talmost_60_days_ago=$(($now+60-60*86400))\n-\tjust_over_60_days_ago=$(($now-1-60*86400))\n-\tpredate1=\"$(date -d \"@$almost_60_days_ago\" +%Y%m%d%H%M.%S)\"\n-\tpredate2=\"$(date -d \"@$almost_15_days_ago\" +%Y%m%d%H%M.%S)\"\n-\tpostdate1=\"$(date -d \"@$just_over_60_days_ago\" +%Y%m%d%H%M.%S)\"\n-\tpostdate2=\"$(date -d \"@$just_over_15_days_ago\" +%Y%m%d%H%M.%S)\"\n-\n-\ttouch -m -t \"$predate1\" $rr/preimage\n-\ttouch -m -t \"$predate2\" $rr2/preimage\n-\n-\ttest_expect_success 'garbage collection (part1)' 'git rerere gc'\n-\n-\ttest_expect_success 'young records still live' \\\n-\t\t\"test -f $rr/preimage -a -f $rr2/preimage\"\n-\n-\ttouch -m -t \"$postdate1\" $rr/preimage\n-\ttouch -m -t \"$postdate2\" $rr2/preimage\n-\n-\ttest_expect_success 'garbage collection (part2)' 'git rerere gc'\n-\n-\ttest_expect_success 'old records rest in peace' \\\n-\t\t\"test ! -f $rr/preimage -a ! -f $rr2/preimage\"\n-\t;;\n-esac\n+now=$(date +%s)\n+almost_15_days_ago=$(($now+60-15*86400))\n+just_over_15_days_ago=$(($now-1-15*86400))\n+almost_60_days_ago=$(($now+60-60*86400))\n+just_over_60_days_ago=$(($now-1-60*86400))\n+\n+test-chmtime =$almost_60_days_ago $rr/preimage\n+test-chmtime =$almost_15_days_ago $rr2/preimage\n+\n+test_expect_success 'garbage collection (part1)' 'git rerere gc'\n+\n+test_expect_success 'young records still live' \\\n+\t\"test -f $rr/preimage && test -f $rr2/preimage\"\n+\n+test-chmtime =$just_over_60_days_ago $rr/preimage\n+test-chmtime =$just_over_15_days_ago $rr2/preimage\n+\n+test_expect_success 'garbage collection (part2)' 'git rerere gc'\n+\n+test_expect_success 'old records rest in peace' \\\n+\t\"test ! -f $rr/preimage && test ! -f $rr2/preimage\"\n \n test_done\n \n-- \n1.5.0.137.ge6502\n"},{"id":"35410","messageId":"Pine.LNX.4.63.0702250220130.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6944","inReplyTo":"11723651923476-git-send-email-normalperson@yhbt.net","subject":"Re: [PATCH] Add test-chmtime: a utility to change mtime on files","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-25T01:27:28Z","receivedAt":"2007-02-25T01:27:28Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 24 Feb 2007, Eric Wong wrote:\n\n> This is intended to be a portable replacement for our usage\n> of date(1), touch(1), and Perl one-liners in tests.\n\nThis is a cute idea!\n\n> diff --git a/Makefile b/Makefile\n> index e51b448..105f3ec 100644\n> --- a/Makefile\n> +++ b/Makefile\n> @@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS\n>  \n>  export NO_SVN_TESTS\n>  \n> -test: all\n> +test: all test-chmtime$X\n\nThat is nice! This says that the program should be only compiled before \nrunning the tests. However, you can run the tests also by \"cd t; make\", \nand even by \"cd t; sh tDDDD-*.sh\", so I think a check in the tests should \nbe added, which tests for executability of test-chmtime.\n\nCiao,\nDscho\n"},{"id":"35411","messageId":"20070225021512.GA31849@mayonaise.dyndns.org","threadId":"6944","inReplyTo":"Pine.LNX.4.63.0702250220130.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] Add test-chmtime: a utility to change mtime on files","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-02-25T02:15:12Z","receivedAt":"2007-02-25T02:15:12Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"As brought up by Johannes Schindelin, some people run tests\nwithin the t/ directory and often without make.  We need to\ncheck and inform those users to build test-chmtime before\nrunning those tests.\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n t/test-lib.sh |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/t/test-lib.sh b/t/test-lib.sh\nindex a403fe0..c075474 100755\n--- a/t/test-lib.sh\n+++ b/t/test-lib.sh\n@@ -264,6 +264,12 @@ test -d ../templates/blt || {\n \terror \"You haven't built things yet, have you?\"\n }\n \n+if ! test -x ../test-chmtime; then\n+\techo >&2 'You need to build test-chmtime:'\n+\techo >&2 'Run \"make test-chmtime\" in the source (toplevel) directory'\n+\texit 1\n+fi\n+\n # Test repository\n test=trash\n rm -fr \"$test\"\n-- \n1.5.0.137.ge6502\n"},{"id":"35412","messageId":"20070225021822.GA31876@mayonaise.dyndns.org","threadId":"6944","inReplyTo":"11723651923476-git-send-email-normalperson@yhbt.net","subject":"[PATCH (try 2)] Add test-chmtime: a utility to change mtime on files","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-02-25T02:18:22Z","receivedAt":"2007-02-25T02:18:22Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"This is intended to be a portable replacement for our usage\nof date(1), touch(1), and Perl one-liners in tests.\n\nUsage: test-chtime (+|=|-)<seconds> <file_1> [<file_2>]\"\n\n  '+' increments the mtime on the file by <seconds>\n  '-' decrements the mtime on the file by <seconds>\n  '=' sets the mtime on the file to exactly <seconds>\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\n---\n Fixing an ugly dependency in the original, the .o file is never used.\n\n Eric Wong <normalperson@yhbt.net> wrote:\n > --- a/Makefile\n > +++ b/Makefile\n > @@ -844,6 +844,8 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)\n >  test-sha1$X: test-sha1.o $(GITLIBS)\n >  \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n >  \n > +test-chmtime$X: test-chmtime.o\n > +\n >  check-sha1:: test-sha1$X\n >  \t./test-sha1.sh\n > \n\n .gitignore     |    1 +\n Makefile       |    5 ++++-\n test-chmtime.c |   48 ++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 53 insertions(+), 1 deletions(-)\n create mode 100644 test-chmtime.c\n\ndiff --git a/.gitignore b/.gitignore\nindex f15155d..eb8a1f8 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -139,6 +139,7 @@ git-whatchanged\n git-write-tree\n git-core-*/?*\n gitweb/gitweb.cgi\n+test-chmtime\n test-date\n test-delta\n test-dump-cache-tree\ndiff --git a/Makefile b/Makefile\nindex e51b448..8a42be9 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS\n \n export NO_SVN_TESTS\n \n-test: all\n+test: all test-chmtime$X\n \t$(MAKE) -C t/ all\n \n test-date$X: test-date.c date.o ctype.o\n@@ -844,6 +844,9 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)\n test-sha1$X: test-sha1.o $(GITLIBS)\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n \n+test-chmtime$X: test-chmtime.c\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<\n+\n check-sha1:: test-sha1$X\n \t./test-sha1.sh\n \ndiff --git a/test-chmtime.c b/test-chmtime.c\nnew file mode 100644\nindex 0000000..69b3ba9\n--- /dev/null\n+++ b/test-chmtime.c\n@@ -0,0 +1,48 @@\n+#include \"git-compat-util.h\"\n+#include <utime.h>\n+\n+static const char usage_str[] = \"(+|=|-)<seconds> <file_1> [<file_2>]\";\n+\n+int main(int argc, const char *argv[])\n+{\n+\tint i;\n+\tint set_eq;\n+\tlong int set_time;\n+\tchar *test;\n+\n+\tif (argc < 3)\n+\t\tgoto usage;\n+\n+\tset_eq = (argv[1][0] == '=') ? 1 : 0;\n+\tset_time = strtol(argv[1] + set_eq, &test, 10);\n+\tif (*test) {\n+\t\tfprintf(stderr, \"Not a base-10 integer: %s\\n\", argv[1] + 1);\n+\t\tgoto usage;\n+\t}\n+\n+\tfor (i = 2; i < argc; i++) {\n+\t\tstruct stat sb;\n+\t\tstruct utimbuf utb;\n+\n+\t\tif (stat(argv[i], &sb) < 0) {\n+\t\t\tfprintf(stderr, \"Failed to stat %s: %s\\n\",\n+\t\t\t        argv[i], strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tutb.actime = sb.st_atime;\n+\t\tutb.modtime = set_eq ? set_time : sb.st_mtime + set_time;\n+\n+\t\tif (utime(argv[i], &utb) < 0) {\n+\t\t\tfprintf(stderr, \"Failed to modify time on %s: %s\\n\",\n+\t\t\t        argv[i], strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+\n+usage:\n+\tfprintf(stderr, \"Usage: %s %s\\n\", argv[0], usage_str);\n+\treturn -1;\n+}\n-- \n1.5.0.137.ge6502\n"},{"id":"35420","messageId":"7vzm72vhl4.fsf@assigned-by-dhcp.cox.net","threadId":"6944","inReplyTo":"11723651934078-git-send-email-normalperson@yhbt.net","subject":"Re: [PATCH] Update tests to use test-chmtime","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-25T07:09:43Z","receivedAt":"2007-02-25T07:09:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Wong <normalperson@yhbt.net> writes:\n\n> -case \"$(date -d @11111111 +%s 2>/dev/null)\" in\n> -11111111)\n> ...\n> -\ttouch -m -t \"$predate1\" $rr/preimage\n> -\ttouch -m -t \"$predate2\" $rr2/preimage\n> ...\n> -esac\n> +now=$(date +%s)\n> +almost_15_days_ago=$(($now+60-15*86400))\n> +just_over_15_days_ago=$(($now-1-15*86400))\n> +almost_60_days_ago=$(($now+60-60*86400))\n> +just_over_60_days_ago=$(($now-1-60*86400))\n> +\n> +test-chmtime =$almost_60_days_ago $rr/preimage\n> +test-chmtime =$almost_15_days_ago $rr2/preimage\n\nVery nice.\nI've been wanting to get rid of this part for quite a while.\n\nHowever, is '+%s' output portable enough for this change to be\nan improvement?\n\nI would suggest changing \"test-chmtime =-200 file\" to set the\nmtime of the file to 200 seconds in the past, relative to\npresent.\n\n---\ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex d5bb6ec..639d45f 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -112,11 +112,10 @@ rr2=.git/rr-cache/$sha2\n mkdir $rr2\n echo Hello > $rr2/preimage\n \n-now=$(date +%s)\n-almost_15_days_ago=$(($now+60-15*86400))\n-just_over_15_days_ago=$(($now-1-15*86400))\n-almost_60_days_ago=$(($now+60-60*86400))\n-just_over_60_days_ago=$(($now-1-60*86400))\n+almost_15_days_ago=$((60-15*86400))\n+just_over_15_days_ago=$((-1-15*86400))\n+almost_60_days_ago=$((60-60*86400))\n+just_over_60_days_ago=$((-1-60*86400))\n \n test-chmtime =$almost_60_days_ago $rr/preimage\n test-chmtime =$almost_15_days_ago $rr2/preimage\ndiff --git a/test-chmtime.c b/test-chmtime.c\nindex 69b3ba9..2a1d00d 100644\n--- a/test-chmtime.c\n+++ b/test-chmtime.c\n@@ -1,7 +1,7 @@\n #include \"git-compat-util.h\"\n #include <utime.h>\n \n-static const char usage_str[] = \"(+|=|-)<seconds> <file_1> [<file_2>]\";\n+static const char usage_str[] = \"(+|=|-)<seconds> <file_1>...\";\n \n int main(int argc, const char *argv[])\n {\n@@ -19,6 +19,10 @@ int main(int argc, const char *argv[])\n \t\tfprintf(stderr, \"Not a base-10 integer: %s\\n\", argv[1] + 1);\n \t\tgoto usage;\n \t}\n+\tif (set_eq && set_time < 0) {\n+\t\ttime_t now = time(NULL);\n+\t\tset_time += now;\n+\t}\n \n \tfor (i = 2; i < argc; i++) {\n \t\tstruct stat sb;\n"},{"id":"35431","messageId":"Pine.LNX.4.63.0702251618380.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6944","inReplyTo":"7vzm72vhl4.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Update tests to use test-chmtime","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-25T15:20:04Z","receivedAt":"2007-02-25T15:20:04Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 24 Feb 2007, Junio C Hamano wrote:\n\n> Eric Wong <normalperson@yhbt.net> writes:\n> \n> > -case \"$(date -d @11111111 +%s 2>/dev/null)\" in\n> > -11111111)\n> > ...\n> > -\ttouch -m -t \"$predate1\" $rr/preimage\n> > -\ttouch -m -t \"$predate2\" $rr2/preimage\n> > ...\n> > -esac\n> > +now=$(date +%s)\n> > +almost_15_days_ago=$(($now+60-15*86400))\n> > +just_over_15_days_ago=$(($now-1-15*86400))\n> > +almost_60_days_ago=$(($now+60-60*86400))\n> > +just_over_60_days_ago=$(($now-1-60*86400))\n> > +\n> > +test-chmtime =$almost_60_days_ago $rr/preimage\n> > +test-chmtime =$almost_15_days_ago $rr2/preimage\n> \n> Very nice.\n> I've been wanting to get rid of this part for quite a while.\n> \n> However, is '+%s' output portable enough for this change to be\n> an improvement?\n\nIt is not portable, but according to the man page:\n\n\t%s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)\n\n> I would suggest changing \"test-chmtime =-200 file\" to set the mtime of \n> the file to 200 seconds in the past, relative to present.\n\nI wanted to propose the same, but without a patch :-)\n\nCiao,\nDscho\n"},{"id":"35447","messageId":"20070225192329.GA13535@localdomain","threadId":"6944","inReplyTo":"7vzm72vhl4.fsf@assigned-by-dhcp.cox.net","subject":"Re: [PATCH] Update tests to use test-chmtime","fromName":"Eric Wong","fromEmail":"normalperson@yhbt.net","sentAt":"2007-02-25T19:23:29Z","receivedAt":"2007-02-25T19:23:29Z","isPatch":true,"sender":{"key":"e@80x24.org","avatar":null},"body":"Junio C Hamano <junkio@cox.net> wrote:\n> Eric Wong <normalperson@yhbt.net> writes:\n> \n> > -case \"$(date -d @11111111 +%s 2>/dev/null)\" in\n> > -11111111)\n> > ...\n> > -\ttouch -m -t \"$predate1\" $rr/preimage\n> > -\ttouch -m -t \"$predate2\" $rr2/preimage\n> > ...\n> > -esac\n> > +now=$(date +%s)\n> > +almost_15_days_ago=$(($now+60-15*86400))\n> > +just_over_15_days_ago=$(($now-1-15*86400))\n> > +almost_60_days_ago=$(($now+60-60*86400))\n> > +just_over_60_days_ago=$(($now-1-60*86400))\n> > +\n> > +test-chmtime =$almost_60_days_ago $rr/preimage\n> > +test-chmtime =$almost_15_days_ago $rr2/preimage\n> \n> Very nice.\n> I've been wanting to get rid of this part for quite a while.\n> \n> However, is '+%s' output portable enough for this change to be\n> an improvement?\n\nLooks like not.\n\n> I would suggest changing \"test-chmtime =-200 file\" to set the\n> mtime of the file to 200 seconds in the past, relative to\n> present.\n> \n> ---\n> diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\n> index d5bb6ec..639d45f 100755\n\nYour patch looks good to me.\n\n-- \nEric Wong\n"},{"id":"35449","messageId":"7vps7yrq11.fsf@assigned-by-dhcp.cox.net","threadId":"6944","inReplyTo":"20070225192329.GA13535@localdomain","subject":"Re: [PATCH] Update tests to use test-chmtime","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-25T19:33:14Z","receivedAt":"2007-02-25T19:33:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Eric Wong <normalperson@yhbt.net> writes:\n\n> Junio C Hamano <junkio@cox.net> wrote:\n>> ...\n>> I would suggest changing \"test-chmtime =-200 file\" to set the\n>> mtime of the file to 200 seconds in the past, relative to\n>> present.\n>> \n>> ---\n>> diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\n>> index d5bb6ec..639d45f 100755\n>\n> Your patch looks good to me.\n\nThanks.  Here is the final version I'll push out in 'master'\nshortly.\n\n-- >8 --\nFrom: Eric Wong <normalperson@yhbt.net>\nDate: Sat, 24 Feb 2007 18:18:22 -0800\nSubject: [PATCH] Add test-chmtime: a utility to change mtime on files\n\nThis is intended to be a portable replacement for our usage\nof date(1), touch(1), and Perl one-liners in tests.\n\nUsage: test-chtime (+|=|-|=+|=-)<seconds> <file>...\"\n\n  '+' increments the mtime on the files by <seconds>\n  '-' decrements the mtime on the files by <seconds>\n  '=' sets the mtime on the file to exactly <seconds>\n  '=+' and '=-' sets the mtime on the file to <seconds> after or\n      before the current time.\n\nSigned-off-by: Eric Wong <normalperson@yhbt.net>\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n .gitignore     |    1 +\n Makefile       |    5 +++-\n test-chmtime.c |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 66 insertions(+), 1 deletions(-)\n create mode 100644 test-chmtime.c\n\ndiff --git a/.gitignore b/.gitignore\nindex f15155d..eb8a1f8 100644\n--- a/.gitignore\n+++ b/.gitignore\n@@ -139,6 +139,7 @@ git-whatchanged\n git-write-tree\n git-core-*/?*\n gitweb/gitweb.cgi\n+test-chmtime\n test-date\n test-delta\n test-dump-cache-tree\ndiff --git a/Makefile b/Makefile\nindex e51b448..8a42be9 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -829,7 +829,7 @@ GIT-CFLAGS: .FORCE-GIT-CFLAGS\n \n export NO_SVN_TESTS\n \n-test: all\n+test: all test-chmtime$X\n \t$(MAKE) -C t/ all\n \n test-date$X: test-date.c date.o ctype.o\n@@ -844,6 +844,9 @@ test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)\n test-sha1$X: test-sha1.o $(GITLIBS)\n \t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)\n \n+test-chmtime$X: test-chmtime.c\n+\t$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $<\n+\n check-sha1:: test-sha1$X\n \t./test-sha1.sh\n \ndiff --git a/test-chmtime.c b/test-chmtime.c\nnew file mode 100644\nindex 0000000..90da448\n--- /dev/null\n+++ b/test-chmtime.c\n@@ -0,0 +1,61 @@\n+#include \"git-compat-util.h\"\n+#include <utime.h>\n+\n+static const char usage_str[] = \"(+|=|=+|=-|-)<seconds> <file>...\";\n+\n+int main(int argc, const char *argv[])\n+{\n+\tint i;\n+\tint set_eq;\n+\tlong int set_time;\n+\tchar *test;\n+\tconst char *timespec;\n+\n+\tif (argc < 3)\n+\t\tgoto usage;\n+\n+\ttimespec = argv[1];\n+\tset_eq = (*timespec == '=') ? 1 : 0;\n+\tif (set_eq) {\n+\t\ttimespec++;\n+\t\tif (*timespec == '+') {\n+\t\t\tset_eq = 2; /* relative \"in the future\" */\n+\t\t\ttimespec++;\n+\t\t}\n+\t}\n+\tset_time = strtol(timespec, &test, 10);\n+\tif (*test) {\n+\t\tfprintf(stderr, \"Not a base-10 integer: %s\\n\", argv[1] + 1);\n+\t\tgoto usage;\n+\t}\n+\tif ((set_eq && set_time < 0) || set_eq == 2) {\n+\t\ttime_t now = time(NULL);\n+\t\tset_time += now;\n+\t}\n+\n+\tfor (i = 2; i < argc; i++) {\n+\t\tstruct stat sb;\n+\t\tstruct utimbuf utb;\n+\n+\t\tif (stat(argv[i], &sb) < 0) {\n+\t\t\tfprintf(stderr, \"Failed to stat %s: %s\\n\",\n+\t\t\t        argv[i], strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\n+\t\tutb.actime = sb.st_atime;\n+\t\tutb.modtime = set_eq ? set_time : sb.st_mtime + set_time;\n+\n+\t\tif (utime(argv[i], &utb) < 0) {\n+\t\t\tfprintf(stderr, \"Failed to modify time on %s: %s\\n\",\n+\t\t\t        argv[i], strerror(errno));\n+\t\t\treturn -1;\n+\t\t}\n+\t}\n+\n+\treturn 0;\n+\n+usage:\n+\tfprintf(stderr, \"Usage: %s %s\\n\", argv[0], usage_str);\n+\treturn -1;\n+}\n-- \n1.5.0.1.791.g4c9a\n"}]}