{"thread":{"id":"48237","subject":"[PATCH] t/helper: 'test-chmtime (--get|-g)' to print only the mtime","startedAt":"2018-04-06T22:22:28Z","lastAt":"2018-04-09T03:29:22Z","messageCount":3,"participants":["Paul-Sebastian Ungureanu","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"344020","messageId":"20180406221947.28402-1-ungureanupaulsebastian@gmail.com","threadId":"48237","inReplyTo":null,"subject":"[PATCH] t/helper: 'test-chmtime (--get|-g)' to print only the mtime","fromName":"Paul-Sebastian Ungureanu","fromEmail":"ungureanupaulsebastian@gmail.com","sentAt":"2018-04-06T22:19:47Z","receivedAt":"2018-04-06T22:22:28Z","isPatch":true,"sender":{"key":"ungureanupaulsebastian@gmail.com","avatar":"https://avatars.githubusercontent.com/u/24317622?v=4"},"body":"Compared to 'test-chmtime -v +0 file' which prints the mtime and\nand the file name, 'test-chmtime --get file' displays only the mtime.\nIf it is used in combination with (+|=|=+|=-|-)seconds, it changes\nand prints the new value.\n\n\ttest-chmtime -v +0 file | sed 's/[^0-9].*$//'\n\nis now equivalent to:\n\n\ttest-chmtime --get file\n\nSigned-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>\n---\n t/helper/test-chmtime.c              | 44 +++++++++++++++++++++++-----\n t/t2022-checkout-paths.sh            |  4 +--\n t/t3404-rebase-interactive.sh        |  2 +-\n t/t3510-cherry-pick-sequence.sh      |  4 +--\n t/t4200-rerere.sh                    |  8 ++---\n t/t5000-tar-tree.sh                  |  2 +-\n t/t6022-merge-rename.sh              | 25 +++++++---------\n t/t6501-freshen-objects.sh           |  6 ++--\n t/t7508-status.sh                    |  4 +--\n t/t7701-repack-unpack-unreachable.sh |  6 ++--\n 10 files changed, 63 insertions(+), 42 deletions(-)\n\ndiff --git a/t/helper/test-chmtime.c b/t/helper/test-chmtime.c\nindex e76025640..611e9520a 100644\n--- a/t/helper/test-chmtime.c\n+++ b/t/helper/test-chmtime.c\n@@ -18,19 +18,29 @@\n  *\n  * Examples:\n  *\n- * To just print the mtime use --verbose and set the file mtime offset to 0:\n+ * To print the mtime and the file name use --verbose and set\n+ * the file mtime offset to 0:\n  *\n  *\ttest-chmtime -v +0 file\n  *\n+ * To print only the mtime use --get:\n+ *\n+ *\ttest-chmtime --get file\n+ *\n  * To set the mtime to current time:\n  *\n  *\ttest-chmtime =+0 file\n  *\n+ * To set the file mtime offset to +1 and print the new value:\n+ *\n+ *\ttest-chmtime --get +1 file\n+ *\n  */\n #include \"git-compat-util.h\"\n #include <utime.h>\n \n-static const char usage_str[] = \"-v|--verbose (+|=|=+|=-|-)<seconds> <file>...\";\n+static const char usage_str[] =\n+\t\"(-v|--verbose|-g|--get) (+|=|=+|=-|-)<seconds> <file>...\";\n \n static int timespec_arg(const char *arg, long int *set_time, int *set_eq)\n {\n@@ -46,7 +56,6 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)\n \t}\n \t*set_time = strtol(timespec, &test, 10);\n \tif (*test) {\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@@ -59,6 +68,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)\n int cmd_main(int argc, const char **argv)\n {\n \tstatic int verbose;\n+\tstatic int get;\n \n \tint i = 1;\n \t/* no mtime change by default */\n@@ -68,18 +78,34 @@ int cmd_main(int argc, const char **argv)\n \tif (argc < 3)\n \t\tgoto usage;\n \n-\tif (strcmp(argv[i], \"--verbose\") == 0 || strcmp(argv[i], \"-v\") == 0) {\n+\tif (strcmp(argv[i], \"--get\") == 0 || strcmp(argv[i], \"-g\") == 0) {\n+\t\tget = 1;\n+\t\t++i;\n+\t} else if (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+\n+\tif (i == argc) {\n+\t\tgoto usage;\n+\t}\n+\n+\tif (timespec_arg(argv[i], &set_time, &set_eq)) {\n \t\t++i;\n-\telse\n+\t} else {\n+\t\tif (get == 0) {\n+\t\t\tfprintf(stderr, \"Not a base-10 integer: %s\\n\", argv[i] + 1);\n+\t\t\tgoto usage;\n+\t\t}\n+\t}\n+\n+\tif (i == argc)\n \t\tgoto usage;\n \n \tfor (; i < argc; i++) {\n \t\tstruct stat sb;\n \t\tstruct utimbuf utb;\n+\t\tuintmax_t mtime;\n \n \t\tif (stat(argv[i], &sb) < 0) {\n \t\t\tfprintf(stderr, \"Failed to stat %s: %s\\n\",\n@@ -99,8 +125,10 @@ int cmd_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 (verbose) {\n-\t\t\tuintmax_t mtime = utb.modtime < 0 ? 0: utb.modtime;\n+\t\tmtime = utb.modtime < 0 ? 0: utb.modtime;\n+\t\tif (get) {\n+\t\t\tprintf(\"%\"PRIuMAX\"\\n\", mtime);\n+\t\t} else if (verbose) {\n \t\t\tprintf(\"%\"PRIuMAX\"\\t%s\\n\", mtime, argv[i]);\n \t\t}\n \ndiff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh\nindex f46d0499b..2a42083bf 100755\n--- a/t/t2022-checkout-paths.sh\n+++ b/t/t2022-checkout-paths.sh\n@@ -73,8 +73,8 @@ test_expect_success 'do not touch files that are already up-to-date' '\n \tgit checkout HEAD -- file1 file2 &&\n \techo one >expect &&\n \ttest_cmp expect file1 &&\n-\techo \"1000000000\tfile2\" >expect &&\n-\ttest-chmtime -v +0 file2 >actual &&\n+\techo \"1000000000\" >expect &&\n+\ttest-chmtime --get file2 >actual &&\n \ttest_cmp expect actual\n '\n \ndiff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh\nindex 3b905406d..0e3724d58 100755\n--- a/t/t3404-rebase-interactive.sh\n+++ b/t/t3404-rebase-interactive.sh\n@@ -717,7 +717,7 @@ test_expect_success 'avoid unnecessary reset' '\n \tset_fake_editor &&\n \tgit rebase -i HEAD~4 &&\n \ttest $HEAD = $(git rev-parse HEAD) &&\n-\tMTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&\n+\tMTIME=$(test-chmtime --get file3) &&\n \ttest 123456789 = $MTIME\n '\n \ndiff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh\nindex 0acf4b146..34f2c7b49 100755\n--- a/t/t3510-cherry-pick-sequence.sh\n+++ b/t/t3510-cherry-pick-sequence.sh\n@@ -247,9 +247,9 @@ test_expect_success '--abort after last commit in sequence' '\n test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '\n \tpristine_detach initial &&\n \ttest_expect_code 1 git cherry-pick base..anotherpick &&\n-\ttest-chmtime -v +0 .git/sequencer >expect &&\n+\ttest-chmtime --get .git/sequencer >expect &&\n \ttest_expect_code 128 git cherry-pick unrelatedpick &&\n-\ttest-chmtime -v +0 .git/sequencer >actual &&\n+\ttest-chmtime --get .git/sequencer >actual &&\n \ttest_cmp expect actual\n '\n \ndiff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh\nindex d97d2bebc..e49f9862c 100755\n--- a/t/t4200-rerere.sh\n+++ b/t/t4200-rerere.sh\n@@ -166,7 +166,7 @@ test_expect_success 'first postimage wins' '\n \tgit commit -q -a -m \"prefer first over second\" &&\n \ttest -f $rr/postimage &&\n \n-\toldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) &&\n+\toldmtimepost=$(test-chmtime --get -60 $rr/postimage) &&\n \n \tgit checkout -b third master &&\n \tgit show second^:a1 | sed \"s/To die: t/To die! T/\" >a1 &&\n@@ -179,7 +179,7 @@ test_expect_success 'first postimage wins' '\n '\n \n test_expect_success 'rerere updates postimage timestamp' '\n-\tnewmtimepost=$(test-chmtime -v +0 $rr/postimage | cut -f 1) &&\n+\tnewmtimepost=$(test-chmtime --get $rr/postimage) &&\n \ttest $oldmtimepost -lt $newmtimepost\n '\n \n@@ -512,7 +512,7 @@ test_expect_success 'multiple identical conflicts' '\n \tcount_pre_post 2 0 &&\n \n \t# Pretend that the conflicts were made quite some time ago\n-\tfind .git/rr-cache/ -type f | xargs test-chmtime -172800 &&\n+\ttest-chmtime -172800 $(find .git/rr-cache/ -type f) &&\n \n \t# Unresolved entries have not expired yet\n \tgit -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&\n@@ -568,7 +568,7 @@ test_expect_success 'multiple identical conflicts' '\n \tgit rerere &&\n \n \t# Pretend that the resolutions are old again\n-\tfind .git/rr-cache/ -type f | xargs test-chmtime -172800 &&\n+\ttest-chmtime -172800 $(find .git/rr-cache/ -type f) &&\n \n \t# Resolved entries have not expired yet\n \tgit -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&\ndiff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh\nindex fe2d4f15a..161a700af 100755\n--- a/t/t5000-tar-tree.sh\n+++ b/t/t5000-tar-tree.sh\n@@ -192,7 +192,7 @@ test_expect_success \\\n     'validate file modification time' \\\n     'mkdir extract &&\n      \"$TAR\" xf b.tar -C extract a/a &&\n-     test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&\n+     test-chmtime --get extract/a/a >b.mtime &&\n      echo \"1117231200\" >expected.mtime &&\n      test_cmp expected.mtime b.mtime'\n \ndiff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh\nindex c01f721f1..206aea0cc 100755\n--- a/t/t6022-merge-rename.sh\n+++ b/t/t6022-merge-rename.sh\n@@ -635,10 +635,9 @@ test_expect_success 'setup avoid unnecessary update, normal rename' '\n \n test_expect_success 'avoid unnecessary update, normal rename' '\n \tgit checkout -q avoid-unnecessary-update-1^0 &&\n-\ttest-chmtime =1000000000 rename &&\n-\ttest-chmtime -v +0 rename >expect &&\n+\ttest-chmtime --get =1000000000 rename >expect &&\n \tgit merge merge-branch-1 &&\n-\ttest-chmtime -v +0 rename >actual &&\n+\ttest-chmtime --get rename >actual &&\n \ttest_cmp expect actual # \"rename\" should have stayed intact\n '\n \n@@ -668,10 +667,9 @@ test_expect_success 'setup to test avoiding unnecessary update, with D/F conflic\n \n test_expect_success 'avoid unnecessary update, with D/F conflict' '\n \tgit checkout -q avoid-unnecessary-update-2^0 &&\n-\ttest-chmtime =1000000000 df &&\n-\ttest-chmtime -v +0 df >expect &&\n+\ttest-chmtime --get =1000000000 df >expect &&\n \tgit merge merge-branch-2 &&\n-\ttest-chmtime -v +0 df >actual &&\n+\ttest-chmtime --get df >actual &&\n \ttest_cmp expect actual # \"df\" should have stayed intact\n '\n \n@@ -700,10 +698,9 @@ test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '\n \n test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '\n \tgit checkout -q master^0 &&\n-\ttest-chmtime =1000000000 df &&\n-\ttest-chmtime -v +0 df >expect &&\n+\ttest-chmtime --get =1000000000 df >expect &&\n \tgit merge side &&\n-\ttest-chmtime -v +0 df >actual &&\n+\ttest-chmtime --get df >actual &&\n \ttest_cmp expect actual # \"df\" should have stayed intact\n '\n \n@@ -730,10 +727,9 @@ test_expect_success 'setup avoid unnecessary update, modify/delete' '\n \n test_expect_success 'avoid unnecessary update, modify/delete' '\n \tgit checkout -q master^0 &&\n-\ttest-chmtime =1000000000 file &&\n-\ttest-chmtime -v +0 file >expect &&\n+\ttest-chmtime --get =1000000000 file >expect &&\n \ttest_must_fail git merge side &&\n-\ttest-chmtime -v +0 file >actual &&\n+\ttest-chmtime --get file >actual &&\n \ttest_cmp expect actual # \"file\" should have stayed intact\n '\n \n@@ -759,10 +755,9 @@ test_expect_success 'setup avoid unnecessary update, rename/add-dest' '\n \n test_expect_success 'avoid unnecessary update, rename/add-dest' '\n \tgit checkout -q master^0 &&\n-\ttest-chmtime =1000000000 newfile &&\n-\ttest-chmtime -v +0 newfile >expect &&\n+\ttest-chmtime --get =1000000000 newfile >expect &&\n \tgit merge side &&\n-\ttest-chmtime -v +0 newfile >actual &&\n+\ttest-chmtime --get newfile >actual &&\n \ttest_cmp expect actual # \"file\" should have stayed intact\n '\n \ndiff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh\nindex 394b169ea..fa12bba98 100755\n--- a/t/t6501-freshen-objects.sh\n+++ b/t/t6501-freshen-objects.sh\n@@ -72,8 +72,7 @@ for repack in '' true; do\n \t'\n \n \ttest_expect_success \"simulate time passing ($title)\" '\n-\t\tfind .git/objects -type f |\n-\t\txargs test-chmtime -v -86400\n+\t\ttest-chmtime --get -86400 $(find .git/objects -type f)\n \t'\n \n \ttest_expect_success \"start writing new commit with old blob ($title)\" '\n@@ -103,8 +102,7 @@ for repack in '' true; do\n \n \ttest_expect_success \"abandon objects again ($title)\" '\n \t\tgit reset --hard HEAD^ &&\n-\t\tfind .git/objects -type f |\n-\t\txargs test-chmtime -v -86400\n+\t\ttest-chmtime --get -86400 $(find .git/objects -type f)\n \t'\n \n \ttest_expect_success \"start writing new commit with same tree ($title)\" '\ndiff --git a/t/t7508-status.sh b/t/t7508-status.sh\nindex 50052e287..2e19d590e 100755\n--- a/t/t7508-status.sh\n+++ b/t/t7508-status.sh\n@@ -1674,10 +1674,10 @@ test_expect_success '\"Initial commit\" should not be noted in commit template' '\n test_expect_success '--no-optional-locks prevents index update' '\n \ttest-chmtime =1234567890 .git/index &&\n \tgit --no-optional-locks status &&\n-\ttest-chmtime -v +0 .git/index >out &&\n+\ttest-chmtime --get .git/index >out &&\n \tgrep ^1234567890 out &&\n \tgit status &&\n-\ttest-chmtime -v +0 .git/index >out &&\n+\ttest-chmtime --get .git/index >out &&\n \t! grep ^1234567890 out\n '\n \ndiff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh\nindex 987573c41..47f22555f 100755\n--- a/t/t7701-repack-unpack-unreachable.sh\n+++ b/t/t7701-repack-unpack-unreachable.sh\n@@ -55,8 +55,8 @@ test_expect_success '-A with -d option leaves unreachable objects unpacked' '\n \n compare_mtimes ()\n {\n-\tread tref rest &&\n-\twhile read t rest; do\n+\tread tref &&\n+\twhile read t; do\n \t\ttest \"$tref\" = \"$t\" || return 1\n \tdone\n }\n@@ -90,7 +90,7 @@ test_expect_success 'unpacked objects receive timestamp of pack file' '\n \ttmppack=\".git/objects/pack/tmp_pack\" &&\n \tln \"$packfile\" \"$tmppack\" &&\n \tgit repack -A -l -d &&\n-\ttest-chmtime -v +0 \"$tmppack\" \"$fsha1path\" \"$csha1path\" \"$tsha1path\" \\\n+\ttest-chmtime --get \"$tmppack\" \"$fsha1path\" \"$csha1path\" \"$tsha1path\" \\\n \t\t> mtimes &&\n \tcompare_mtimes < mtimes\n '\n-- \n2.16.2.751.g6be39c975.dirty\n\n"},{"id":"344149","messageId":"xmqq1sfp6r9n.fsf@gitster-ct.c.googlers.com","threadId":"48237","inReplyTo":"20180406221947.28402-1-ungureanupaulsebastian@gmail.com","subject":"Re: [PATCH] t/helper: 'test-chmtime (--get|-g)' to print only the mtime","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-09T02:35:32Z","receivedAt":"2018-04-09T02:36:07Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com> writes:\n\n> Compared to 'test-chmtime -v +0 file' which prints the mtime and\n> and the file name, 'test-chmtime --get file' displays only the mtime.\n> If it is used in combination with (+|=|=+|=-|-)seconds, it changes\n> and prints the new value.\n>\n> \ttest-chmtime -v +0 file | sed 's/[^0-9].*$//'\n>\n> is now equivalent to:\n>\n> \ttest-chmtime --get file\n>\n> Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>\n> ---\n>  t/helper/test-chmtime.c              | 44 +++++++++++++++++++++++-----\n>  t/t2022-checkout-paths.sh            |  4 +--\n>  t/t3404-rebase-interactive.sh        |  2 +-\n>  t/t3510-cherry-pick-sequence.sh      |  4 +--\n>  t/t4200-rerere.sh                    |  8 ++---\n>  t/t5000-tar-tree.sh                  |  2 +-\n>  t/t6022-merge-rename.sh              | 25 +++++++---------\n>  t/t6501-freshen-objects.sh           |  6 ++--\n>  t/t7508-status.sh                    |  4 +--\n>  t/t7701-repack-unpack-unreachable.sh |  6 ++--\n>  10 files changed, 63 insertions(+), 42 deletions(-)\n\nThanks both for suggesting and implementing an obvious improvement\nand updating many places that are helped by it.\n\nWill queue.\n.\n"},{"id":"344150","messageId":"xmqqvad15a7r.fsf@gitster-ct.c.googlers.com","threadId":"48237","inReplyTo":"20180406221947.28402-1-ungureanupaulsebastian@gmail.com","subject":"Re: [PATCH] t/helper: 'test-chmtime (--get|-g)' to print only the mtime","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-04-09T03:29:12Z","receivedAt":"2018-04-09T03:29:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com> writes:\n\n> -\tfind .git/rr-cache/ -type f | xargs test-chmtime -172800 &&\n> +\ttest-chmtime -172800 $(find .git/rr-cache/ -type f) &&\n\nYou've sneaked this kind of rewrite in, as if you are testing to see\nhow careful the reviewers are ;-).\n\nWe often use \"find piped to xargs\" pattern to avoid unbounded number\nof paths from appearing on a command line, busting platform limits.\nIn the case of these test scripts, it does not matter very much, but\nsuch a \"we can save a process and a pipe this way\" optimization is\nnot within the scope of \"chmtime +v often is piped to sed only to\nstrip path---let's give it a way to just grab the timestamp\" topic.\nNot a very welcome change.\n\nHaving said that, I do not want this to be rerolled if this\nunrelated \"removal of find-piped-to-xargs pattern\" is the only\nniggle in the patch, as I've already checked if these conversions\nare safe (they are---we are not dealing with hundreds of stuff in\n.git/objects/ or .git/rr-cache/).  There were conflicts caused by\nthis patch and nd/combined-test-helper (which makes the test-chmtime\nstandalone binary as a subcommand of test-tool); I think I resolved\nthem correctly, but please double check when I update the public\nrepositories in several hours.\n\nThanks.\n"}]}