* [PATCH] Add test-chmtime: a utility to change mtime on files
@ 2007-02-25 0:59 Eric Wong
2007-02-25 0:59 ` [PATCH] Update tests to use test-chmtime Eric Wong
` (2 more replies)
0 siblings, 3 replies; 9+ messages in thread
From: Eric Wong @ 2007-02-25 0:59 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Eric Wong
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>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
.gitignore | 1 +
Makefile | 4 +++-
test-chmtime.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 52 insertions(+), 1 deletions(-)
create mode 100644 test-chmtime.c
diff --git a/.gitignore b/.gitignore
index f15155d..eb8a1f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -139,6 +139,7 @@ git-whatchanged
git-write-tree
git-core-*/?*
gitweb/gitweb.cgi
+test-chmtime
test-date
test-delta
test-dump-cache-tree
diff --git a/Makefile b/Makefile
index e51b448..105f3ec 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/test-chmtime.c b/test-chmtime.c
new file mode 100644
index 0000000..69b3ba9
--- /dev/null
+++ b/test-chmtime.c
@@ -0,0 +1,48 @@
+#include "git-compat-util.h"
+#include <utime.h>
+
+static const char usage_str[] = "(+|=|-)<seconds> <file_1> [<file_2>]";
+
+int main(int argc, const char *argv[])
+{
+ int i;
+ int set_eq;
+ long int set_time;
+ char *test;
+
+ if (argc < 3)
+ goto usage;
+
+ set_eq = (argv[1][0] == '=') ? 1 : 0;
+ set_time = strtol(argv[1] + set_eq, &test, 10);
+ if (*test) {
+ fprintf(stderr, "Not a base-10 integer: %s\n", argv[1] + 1);
+ goto usage;
+ }
+
+ for (i = 2; i < argc; i++) {
+ struct stat sb;
+ struct utimbuf utb;
+
+ if (stat(argv[i], &sb) < 0) {
+ fprintf(stderr, "Failed to stat %s: %s\n",
+ argv[i], strerror(errno));
+ return -1;
+ }
+
+ utb.actime = sb.st_atime;
+ utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
+
+ if (utime(argv[i], &utb) < 0) {
+ fprintf(stderr, "Failed to modify time on %s: %s\n",
+ argv[i], strerror(errno));
+ return -1;
+ }
+ }
+
+ return 0;
+
+usage:
+ fprintf(stderr, "Usage: %s %s\n", argv[0], usage_str);
+ return -1;
+}
--
1.5.0.137.ge6502
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH] Update tests to use test-chmtime
2007-02-25 0:59 [PATCH] Add test-chmtime: a utility to change mtime on files Eric Wong
@ 2007-02-25 0:59 ` Eric Wong
2007-02-25 7:09 ` Junio C Hamano
2007-02-25 1:27 ` [PATCH] Add test-chmtime: a utility to change mtime on files Johannes Schindelin
2007-02-25 2:18 ` [PATCH (try 2)] " Eric Wong
2 siblings, 1 reply; 9+ messages in thread
From: Eric Wong @ 2007-02-25 0:59 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Eric Wong
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
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
t/lib-git-svn.sh | 2 +-
t/t4200-rerere.sh | 54 ++++++++++++++++++++--------------------------------
2 files changed, 22 insertions(+), 34 deletions(-)
diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh
index 27ad3b7..f6fe78c 100644
--- a/t/lib-git-svn.sh
+++ b/t/lib-git-svn.sh
@@ -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"
}
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index c571a1b..d5bb6ec 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -112,39 +112,27 @@ rr2=.git/rr-cache/$sha2
mkdir $rr2
echo Hello > $rr2/preimage
-case "$(date -d @11111111 +%s 2>/dev/null)" in
-11111111)
- # 'date' must be able to take arbitrary input with @11111111 notation.
- # for this test to succeed. We should fix this part using more
- # portable script someday.
-
- 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))
- predate1="$(date -d "@$almost_60_days_ago" +%Y%m%d%H%M.%S)"
- predate2="$(date -d "@$almost_15_days_ago" +%Y%m%d%H%M.%S)"
- postdate1="$(date -d "@$just_over_60_days_ago" +%Y%m%d%H%M.%S)"
- postdate2="$(date -d "@$just_over_15_days_ago" +%Y%m%d%H%M.%S)"
-
- touch -m -t "$predate1" $rr/preimage
- touch -m -t "$predate2" $rr2/preimage
-
- test_expect_success 'garbage collection (part1)' 'git rerere gc'
-
- test_expect_success 'young records still live' \
- "test -f $rr/preimage -a -f $rr2/preimage"
-
- touch -m -t "$postdate1" $rr/preimage
- touch -m -t "$postdate2" $rr2/preimage
-
- test_expect_success 'garbage collection (part2)' 'git rerere gc'
-
- test_expect_success 'old records rest in peace' \
- "test ! -f $rr/preimage -a ! -f $rr2/preimage"
- ;;
-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
+
+test_expect_success 'garbage collection (part1)' 'git rerere gc'
+
+test_expect_success 'young records still live' \
+ "test -f $rr/preimage && test -f $rr2/preimage"
+
+test-chmtime =$just_over_60_days_ago $rr/preimage
+test-chmtime =$just_over_15_days_ago $rr2/preimage
+
+test_expect_success 'garbage collection (part2)' 'git rerere gc'
+
+test_expect_success 'old records rest in peace' \
+ "test ! -f $rr/preimage && test ! -f $rr2/preimage"
test_done
--
1.5.0.137.ge6502
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] Add test-chmtime: a utility to change mtime on files
2007-02-25 0:59 [PATCH] Add test-chmtime: a utility to change mtime on files Eric Wong
2007-02-25 0:59 ` [PATCH] Update tests to use test-chmtime Eric Wong
@ 2007-02-25 1:27 ` Johannes Schindelin
2007-02-25 2:15 ` Eric Wong
2007-02-25 2:18 ` [PATCH (try 2)] " Eric Wong
2 siblings, 1 reply; 9+ messages in thread
From: Johannes Schindelin @ 2007-02-25 1:27 UTC (permalink / raw)
To: Eric Wong; +Cc: Junio C Hamano, git
Hi,
On Sat, 24 Feb 2007, Eric Wong wrote:
> 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!
> diff --git a/Makefile b/Makefile
> index e51b448..105f3ec 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Add test-chmtime: a utility to change mtime on files
2007-02-25 1:27 ` [PATCH] Add test-chmtime: a utility to change mtime on files Johannes Schindelin
@ 2007-02-25 2:15 ` Eric Wong
0 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2007-02-25 2:15 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Johannes Schindelin, git
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.
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
t/test-lib.sh | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/t/test-lib.sh b/t/test-lib.sh
index a403fe0..c075474 100755
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -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"
--
1.5.0.137.ge6502
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH (try 2)] Add test-chmtime: a utility to change mtime on files
2007-02-25 0:59 [PATCH] Add test-chmtime: a utility to change mtime on files Eric Wong
2007-02-25 0:59 ` [PATCH] Update tests to use test-chmtime Eric Wong
2007-02-25 1:27 ` [PATCH] Add test-chmtime: a utility to change mtime on files Johannes Schindelin
@ 2007-02-25 2:18 ` Eric Wong
2 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2007-02-25 2:18 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
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>
Signed-off-by: Eric Wong <normalperson@yhbt.net>
---
Fixing an ugly dependency in the original, the .o file is never used.
Eric Wong <normalperson@yhbt.net> wrote:
> --- a/Makefile
> +++ b/Makefile
> @@ -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
diff --git a/.gitignore b/.gitignore
index f15155d..eb8a1f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -139,6 +139,7 @@ git-whatchanged
git-write-tree
git-core-*/?*
gitweb/gitweb.cgi
+test-chmtime
test-date
test-delta
test-dump-cache-tree
diff --git a/Makefile b/Makefile
index e51b448..8a42be9 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/test-chmtime.c b/test-chmtime.c
new file mode 100644
index 0000000..69b3ba9
--- /dev/null
+++ b/test-chmtime.c
@@ -0,0 +1,48 @@
+#include "git-compat-util.h"
+#include <utime.h>
+
+static const char usage_str[] = "(+|=|-)<seconds> <file_1> [<file_2>]";
+
+int main(int argc, const char *argv[])
+{
+ int i;
+ int set_eq;
+ long int set_time;
+ char *test;
+
+ if (argc < 3)
+ goto usage;
+
+ set_eq = (argv[1][0] == '=') ? 1 : 0;
+ set_time = strtol(argv[1] + set_eq, &test, 10);
+ if (*test) {
+ fprintf(stderr, "Not a base-10 integer: %s\n", argv[1] + 1);
+ goto usage;
+ }
+
+ for (i = 2; i < argc; i++) {
+ struct stat sb;
+ struct utimbuf utb;
+
+ if (stat(argv[i], &sb) < 0) {
+ fprintf(stderr, "Failed to stat %s: %s\n",
+ argv[i], strerror(errno));
+ return -1;
+ }
+
+ utb.actime = sb.st_atime;
+ utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
+
+ if (utime(argv[i], &utb) < 0) {
+ fprintf(stderr, "Failed to modify time on %s: %s\n",
+ argv[i], strerror(errno));
+ return -1;
+ }
+ }
+
+ return 0;
+
+usage:
+ fprintf(stderr, "Usage: %s %s\n", argv[0], usage_str);
+ return -1;
+}
--
1.5.0.137.ge6502
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] Update tests to use test-chmtime
2007-02-25 0:59 ` [PATCH] Update tests to use test-chmtime Eric Wong
@ 2007-02-25 7:09 ` Junio C Hamano
2007-02-25 15:20 ` Johannes Schindelin
2007-02-25 19:23 ` Eric Wong
0 siblings, 2 replies; 9+ messages in thread
From: Junio C Hamano @ 2007-02-25 7:09 UTC (permalink / raw)
To: Eric Wong; +Cc: git
Eric Wong <normalperson@yhbt.net> writes:
> -case "$(date -d @11111111 +%s 2>/dev/null)" in
> -11111111)
> ...
> - touch -m -t "$predate1" $rr/preimage
> - touch -m -t "$predate2" $rr2/preimage
> ...
> -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.
---
diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
index d5bb6ec..639d45f 100755
--- a/t/t4200-rerere.sh
+++ b/t/t4200-rerere.sh
@@ -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
diff --git a/test-chmtime.c b/test-chmtime.c
index 69b3ba9..2a1d00d 100644
--- a/test-chmtime.c
+++ b/test-chmtime.c
@@ -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;
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] Update tests to use test-chmtime
2007-02-25 7:09 ` Junio C Hamano
@ 2007-02-25 15:20 ` Johannes Schindelin
2007-02-25 19:23 ` Eric Wong
1 sibling, 0 replies; 9+ messages in thread
From: Johannes Schindelin @ 2007-02-25 15:20 UTC (permalink / raw)
To: Junio C Hamano; +Cc: Eric Wong, git
Hi,
On Sat, 24 Feb 2007, Junio C Hamano wrote:
> Eric Wong <normalperson@yhbt.net> writes:
>
> > -case "$(date -d @11111111 +%s 2>/dev/null)" in
> > -11111111)
> > ...
> > - touch -m -t "$predate1" $rr/preimage
> > - touch -m -t "$predate2" $rr2/preimage
> > ...
> > -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?
It is not portable, but according to the man page:
%s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)
> 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
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Update tests to use test-chmtime
2007-02-25 7:09 ` Junio C Hamano
2007-02-25 15:20 ` Johannes Schindelin
@ 2007-02-25 19:23 ` Eric Wong
2007-02-25 19:33 ` Junio C Hamano
1 sibling, 1 reply; 9+ messages in thread
From: Eric Wong @ 2007-02-25 19:23 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Junio C Hamano <junkio@cox.net> wrote:
> Eric Wong <normalperson@yhbt.net> writes:
>
> > -case "$(date -d @11111111 +%s 2>/dev/null)" in
> > -11111111)
> > ...
> > - touch -m -t "$predate1" $rr/preimage
> > - touch -m -t "$predate2" $rr2/preimage
> > ...
> > -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?
Looks like not.
> I would suggest changing "test-chmtime =-200 file" to set the
> mtime of the file to 200 seconds in the past, relative to
> present.
>
> ---
> diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
> index d5bb6ec..639d45f 100755
Your patch looks good to me.
--
Eric Wong
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] Update tests to use test-chmtime
2007-02-25 19:23 ` Eric Wong
@ 2007-02-25 19:33 ` Junio C Hamano
0 siblings, 0 replies; 9+ messages in thread
From: Junio C Hamano @ 2007-02-25 19:33 UTC (permalink / raw)
To: Eric Wong; +Cc: git
Eric Wong <normalperson@yhbt.net> writes:
> Junio C Hamano <junkio@cox.net> wrote:
>> ...
>> I would suggest changing "test-chmtime =-200 file" to set the
>> mtime of the file to 200 seconds in the past, relative to
>> present.
>>
>> ---
>> diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh
>> index d5bb6ec..639d45f 100755
>
> Your patch looks good to me.
Thanks. Here is the final version I'll push out in 'master'
shortly.
-- >8 --
From: Eric Wong <normalperson@yhbt.net>
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.
Signed-off-by: Eric Wong <normalperson@yhbt.net>
Signed-off-by: Junio C Hamano <junkio@cox.net>
---
.gitignore | 1 +
Makefile | 5 +++-
test-chmtime.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 66 insertions(+), 1 deletions(-)
create mode 100644 test-chmtime.c
diff --git a/.gitignore b/.gitignore
index f15155d..eb8a1f8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -139,6 +139,7 @@ git-whatchanged
git-write-tree
git-core-*/?*
gitweb/gitweb.cgi
+test-chmtime
test-date
test-delta
test-dump-cache-tree
diff --git a/Makefile b/Makefile
index e51b448..8a42be9 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/test-chmtime.c b/test-chmtime.c
new file mode 100644
index 0000000..90da448
--- /dev/null
+++ b/test-chmtime.c
@@ -0,0 +1,61 @@
+#include "git-compat-util.h"
+#include <utime.h>
+
+static const char usage_str[] = "(+|=|=+|=-|-)<seconds> <file>...";
+
+int main(int argc, const char *argv[])
+{
+ int i;
+ int set_eq;
+ long int set_time;
+ char *test;
+ const char *timespec;
+
+ if (argc < 3)
+ goto usage;
+
+ timespec = argv[1];
+ set_eq = (*timespec == '=') ? 1 : 0;
+ if (set_eq) {
+ timespec++;
+ if (*timespec == '+') {
+ set_eq = 2; /* relative "in the future" */
+ timespec++;
+ }
+ }
+ set_time = strtol(timespec, &test, 10);
+ if (*test) {
+ fprintf(stderr, "Not a base-10 integer: %s\n", argv[1] + 1);
+ goto usage;
+ }
+ if ((set_eq && set_time < 0) || set_eq == 2) {
+ time_t now = time(NULL);
+ set_time += now;
+ }
+
+ for (i = 2; i < argc; i++) {
+ struct stat sb;
+ struct utimbuf utb;
+
+ if (stat(argv[i], &sb) < 0) {
+ fprintf(stderr, "Failed to stat %s: %s\n",
+ argv[i], strerror(errno));
+ return -1;
+ }
+
+ utb.actime = sb.st_atime;
+ utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
+
+ if (utime(argv[i], &utb) < 0) {
+ fprintf(stderr, "Failed to modify time on %s: %s\n",
+ argv[i], strerror(errno));
+ return -1;
+ }
+ }
+
+ return 0;
+
+usage:
+ fprintf(stderr, "Usage: %s %s\n", argv[0], usage_str);
+ return -1;
+}
--
1.5.0.1.791.g4c9a
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2007-02-25 19:33 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-25 0:59 [PATCH] Add test-chmtime: a utility to change mtime on files Eric Wong
2007-02-25 0:59 ` [PATCH] Update tests to use test-chmtime Eric Wong
2007-02-25 7:09 ` Junio C Hamano
2007-02-25 15:20 ` Johannes Schindelin
2007-02-25 19:23 ` Eric Wong
2007-02-25 19:33 ` Junio C Hamano
2007-02-25 1:27 ` [PATCH] Add test-chmtime: a utility to change mtime on files Johannes Schindelin
2007-02-25 2:15 ` Eric Wong
2007-02-25 2:18 ` [PATCH (try 2)] " Eric Wong
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.