summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 2c7ca1f)
raw | patch | inline | side by side (parent: 2c7ca1f)
author | Eric Wong <normalperson@yhbt.net> | |
Sun, 25 Feb 2007 02:18:22 +0000 (18:18 -0800) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sun, 25 Feb 2007 19:09:56 +0000 (11:09 -0800) |
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>
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 | patch | blob | history | |
Makefile | patch | blob | history | |
test-chmtime.c | [new file with mode: 0644] | patch | blob |
diff --git a/.gitignore b/.gitignore
index f15155d1b7bcb45db6a8d67eab51b535102353c1..eb8a1f860678ff86f3b9ca95f618226551c884cf 100644 (file)
--- a/.gitignore
+++ b/.gitignore
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 e51b448c78827dfc9563cda309a67281b29b873b..8a42be9babb04a2a9f6eb0fba24a5fc8b5fe59a1 100644 (file)
--- a/Makefile
+++ b/Makefile
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
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
--- /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;
+}