{"thread":{"id":"16094","subject":"[PATCH 1/2] Add --verbose|-v to test-chmtime","startedAt":"2008-10-30T11:26:24Z","lastAt":"2008-10-30T22:58:51Z","messageCount":2,"participants":["Alex Riesen","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"94274","messageId":"81b0412b0810300426u2ccbe51at1bf5f989b6333ed1@mail.gmail.com","threadId":"16094","inReplyTo":null,"subject":"[PATCH 1/2] Add --verbose|-v to test-chmtime","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2008-10-30T11:26:24Z","receivedAt":"2008-10-30T11:26:24Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"This allows us replace perl when getting the mtime of a file because\nof time zone conversions, though at the moment only one platform which\ndoes this has been identified: Cygwin when used with ActiveState Perl\n(as usual).\n\nThe output format is:\n\n    <mtime1> TAB <filename1> <LF>\n    <mtime2> TAB <filename2> <LF>\n    ...\n\nwhich, if only mtime is needed can be parsed with cut(1):\n\n    test-chmtime -v +0 filename1 | cut -f 1\n\nAlso, the change adds a description of programs features, with examples.\n\nSigned-off-by: Alex Riesen <ariesen@harmanbecker.com>\n---\n test-chmtime.c |   91 +++++++++++++++++++++++++++++++++++++++++++-------------\n 1 files changed, 70 insertions(+), 21 deletions(-)\n\n\nFrom a59f17013cc54112d0bd11550b273baa6e312776 Mon Sep 17 00:00:00 2001\nFrom: Alex Riesen <raa.lkml@gmail.com>\nDate: Thu, 30 Oct 2008 10:00:29 +0100\nSubject: [PATCH 1/2] Add --verbose|-v to test-chmtime\n\nThis allows us replace perl when getting the mtime of a file because\nof time zone conversions, though at the moment only one platform which\ndoes this has been identified: Cygwin when used with ActiveState Perl\n(as usual).\n\nThe output format is:\n\n    <mtime1> TAB <filename1> <LF>\n    <mtime2> TAB <filename2> <LF>\n    ...\n\nwhich, if only mtime is needed can be parsed with cut(1):\n\n    test-chmtime -v +0 filename1 | cut -f 1\n\nAlso, the change adds a description of programs features, with examples.\n\nSigned-off-by: Alex Riesen <ariesen@harmanbecker.com>\n---\n test-chmtime.c |   91 +++++++++++++++++++++++++++++++++++++++++++-------------\n 1 files changed, 70 insertions(+), 21 deletions(-)\n\ndiff --git a/test-chmtime.c b/test-chmtime.c\nindex 90da448..d5358cb 100644\n--- a/test-chmtime.c\n+++ b/test-chmtime.c\n@@ -1,39 +1,83 @@\n+/*\n+ * This program can either change modification time of the given\n+ * file(s) or just print it. The program does not change atime nor\n+ * ctime (their values are explicitely preserved).\n+ *\n+ * The mtime can be changed to an absolute value:\n+ *\n+ *\ttest-chmtime =<seconds> file...\n+ *\n+ * Relative to the current time as returned by time(3):\n+ *\n+ *\ttest-chmtime =+<seconds> (or =-<seconds>) file...\n+ *\n+ * Or relative to the current mtime of the file:\n+ *\n+ *\ttest-chmtime <seconds> file...\n+ *\ttest-chmtime +<seconds> (or -<seconds>) file...\n+ *\n+ * Examples:\n+ *\n+ * To just print the mtime use --verbose and set the file mtime offset to 0:\n+ *\n+ *\ttest-chmtime -v +0 file\n+ *\n+ * To set the mtime to current time:\n+ *\n+ *\ttest-chmtime =+0 file\n+ *\n+ */\n #include \"git-compat-util.h\"\n #include <utime.h>\n \n-static const char usage_str[] = \"(+|=|=+|=-|-)<seconds> <file>...\";\n+static const char usage_str[] = \"-v|--verbose (+|=|=+|=-|-)<seconds> <file>...\";\n \n-int main(int argc, const char *argv[])\n+static int timespec_arg(const char *arg, long int *set_time, int *set_eq)\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+\tconst char *timespec = arg;\n+\t*set_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\t*set_eq = 2; /* relative \"in the future\" */\n \t\t\ttimespec++;\n \t\t}\n \t}\n-\tset_time = strtol(timespec, &test, 10);\n+\t*set_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\tfprintf(stderr, \"Not a base-10 integer: %s\\n\", arg + 1);\n+\t\treturn 0;\n \t}\n-\tif ((set_eq && set_time < 0) || set_eq == 2) {\n+\tif ((*set_eq && *set_time < 0) || *set_eq == 2) {\n \t\ttime_t now = time(NULL);\n-\t\tset_time += now;\n+\t\t*set_time += now;\n \t}\n+\treturn 1;\n+}\n+\n+int main(int argc, const char *argv[])\n+{\n+\tstatic int verbose;\n \n-\tfor (i = 2; i < argc; i++) {\n+\tint i = 1;\n+\t/* no mtime change by default */\n+\tint set_eq = 0;\n+\tlong int set_time = 0;\n+\n+\tif (argc < 3)\n+\t\tgoto usage;\n+\n+\tif (strcmp(argv[i], \"--verbose\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n+\t\tverbose = 1;\n+\t\t++i;\n+\t}\n+\tif (timespec_arg(argv[i], &set_time, &set_eq))\n+\t\t++i;\n+\telse\n+\t\tgoto usage;\n+\n+\tfor (; i < argc; i++) {\n \t\tstruct stat sb;\n \t\tstruct utimbuf utb;\n \n@@ -46,7 +90,12 @@ int main(int argc, const char *argv[])\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\tif (verbose) {\n+\t\t\tuintmax_t mtime = utb.modtime < 0 ? 0: utb.modtime;\n+\t\t\tprintf(\"%\"PRIuMAX\"\\t%s\\n\", mtime, argv[i]);\n+\t\t}\n+\n+\t\tif (utb.modtime != sb.st_mtime && 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-- \n1.6.0.3.552.g4ff73\n\n"},{"id":"94347","messageId":"20081030225850.GA3688@sigill.intra.peff.net","threadId":"16094","inReplyTo":"81b0412b0810300426u2ccbe51at1bf5f989b6333ed1@mail.gmail.com","subject":"Re: [PATCH 1/2] Add --verbose|-v to test-chmtime","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-10-30T22:58:51Z","receivedAt":"2008-10-30T22:58:51Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Oct 30, 2008 at 12:26:24PM +0100, Alex Riesen wrote:\n\n> This allows us replace perl when getting the mtime of a file because\n> of time zone conversions, though at the moment only one platform which\n> does this has been identified: Cygwin when used with ActiveState Perl\n> (as usual).\n> [...]\n>     test-chmtime -v +0 filename1 | cut -f 1\n\nPersonally, I would have:\n\n  - split the argument refactoring and the addition of the \"-v\" argument\n    into two patches to make reviewers lives easier\n\n  - just used a special timespec that means \"don't change anything, but\n    show show\"\n\nbut I think those are mostly nitpicks, so I am OK with the series as-is.\n\n-Peff\n"}]}