t/helper: 'test-chmtime (--get|-g)' to print only the mtime
Compared to 'test-chmtime -v +0 file' which prints the mtime and and the file name, 'test-chmtime --get file' displays only the mtime. If it is used in combination with (+|=|=+|=-|-)seconds, it changes and prints the new value. test-chmtime -v +0 file | sed 's/[^0-9].*$//' is now equivalent to: test-chmtime --get file Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Paul-Sebastian Ungureanu committed
Apr 7, 2018 at 01:19 UTC
decf711fc13858087c87808e539d75f06bd9f7b7
10 files changed
+63
-42
t/helper/test-chmtime.c
+36
-8
@@ -18,19 +18,29 @@
18
*
19
* Examples:
20
*
21
- * To just print the mtime use --verbose and set the file mtime offset to 0:
21
+ * To print the mtime and the file name use --verbose and set
22
+ * the file mtime offset to 0:
23
*
24
* test-chmtime -v +0 file
25
*
26
+ * To print only the mtime use --get:
27
+ *
28
+ * test-chmtime --get file
29
+ *
30
* To set the mtime to current time:
31
*
32
* test-chmtime =+0 file
33
*
34
+ * To set the file mtime offset to +1 and print the new value:
35
+ *
36
+ * test-chmtime --get +1 file
37
+ *
38
*/
39
#include "git-compat-util.h"
40
#include <utime.h>
41
33
-static const char usage_str[] = "-v|--verbose (+|=|=+|=-|-)<seconds> <file>...";
42
+static const char usage_str[] =
43
+ "(-v|--verbose|-g|--get) (+|=|=+|=-|-)<seconds> <file>...";
44
45
static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
46
{
@@ -46,7 +56,6 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
56
}
57
*set_time = strtol(timespec, &test, 10);
58
if (*test) {
49
- fprintf(stderr, "Not a base-10 integer: %s\n", arg + 1);
59
return 0;
60
}
61
if ((*set_eq && *set_time < 0) || *set_eq == 2) {
@@ -59,6 +68,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
68
int cmd_main(int argc, const char **argv)
69
{
70
static int verbose;
71
+ static int get;
72
73
int i = 1;
74
/* no mtime change by default */
@@ -68,18 +78,34 @@ int cmd_main(int argc, const char **argv)
78
if (argc < 3)
79
goto usage;
80
71
- if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
81
+ if (strcmp(argv[i], "--get") == 0 || strcmp(argv[i], "-g") == 0) {
82
+ get = 1;
83
+ ++i;
84
+ } else if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
85
verbose = 1;
86
++i;
87
}
75
- if (timespec_arg(argv[i], &set_time, &set_eq))
88
+
89
+ if (i == argc) {
90
+ goto usage;
91
+ }
92
+
93
+ if (timespec_arg(argv[i], &set_time, &set_eq)) {
94
++i;
77
- else
95
+ } else {
96
+ if (get == 0) {
97
+ fprintf(stderr, "Not a base-10 integer: %s\n", argv[i] + 1);
98
+ goto usage;
99
+ }
100
+ }
101
+
102
+ if (i == argc)
103
goto usage;
104
105
for (; i < argc; i++) {
106
struct stat sb;
107
struct utimbuf utb;
108
+ uintmax_t mtime;
109
110
if (stat(argv[i], &sb) < 0) {
111
fprintf(stderr, "Failed to stat %s: %s\n",
@@ -99,8 +125,10 @@ int cmd_main(int argc, const char **argv)
125
utb.actime = sb.st_atime;
126
utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
127
102
- if (verbose) {
103
- uintmax_t mtime = utb.modtime < 0 ? 0: utb.modtime;
128
+ mtime = utb.modtime < 0 ? 0: utb.modtime;
129
+ if (get) {
130
+ printf("%"PRIuMAX"\n", mtime);
131
+ } else if (verbose) {
132
printf("%"PRIuMAX"\t%s\n", mtime, argv[i]);
133
}
134
t/t2022-checkout-paths.sh
+2
-2
@@ -73,8 +73,8 @@ test_expect_success 'do not touch files that are already up-to-date' '
73
git checkout HEAD -- file1 file2 &&
74
echo one >expect &&
75
test_cmp expect file1 &&
76
- echo "1000000000 file2" >expect &&
77
- test-chmtime -v +0 file2 >actual &&
76
+ echo "1000000000" >expect &&
77
+ test-chmtime --get file2 >actual &&
78
test_cmp expect actual
79
'
80
t/t3404-rebase-interactive.sh
+1
-1
@@ -705,7 +705,7 @@ test_expect_success 'avoid unnecessary reset' '
705
set_fake_editor &&
706
git rebase -i HEAD~4 &&
707
test $HEAD = $(git rev-parse HEAD) &&
708
- MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
708
+ MTIME=$(test-chmtime --get file3) &&
709
test 123456789 = $MTIME
710
'
711
t/t3510-cherry-pick-sequence.sh
+2
-2
@@ -247,9 +247,9 @@ test_expect_success '--abort after last commit in sequence' '
247
test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
248
pristine_detach initial &&
249
test_expect_code 1 git cherry-pick base..anotherpick &&
250
- test-chmtime -v +0 .git/sequencer >expect &&
250
+ test-chmtime --get .git/sequencer >expect &&
251
test_expect_code 128 git cherry-pick unrelatedpick &&
252
- test-chmtime -v +0 .git/sequencer >actual &&
252
+ test-chmtime --get .git/sequencer >actual &&
253
test_cmp expect actual
254
'
255
t/t4200-rerere.sh
+4
-4
@@ -166,7 +166,7 @@ test_expect_success 'first postimage wins' '
166
git commit -q -a -m "prefer first over second" &&
167
test -f $rr/postimage &&
168
169
- oldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) &&
169
+ oldmtimepost=$(test-chmtime --get -60 $rr/postimage) &&
170
171
git checkout -b third master &&
172
git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
@@ -179,7 +179,7 @@ test_expect_success 'first postimage wins' '
179
'
180
181
test_expect_success 'rerere updates postimage timestamp' '
182
- newmtimepost=$(test-chmtime -v +0 $rr/postimage | cut -f 1) &&
182
+ newmtimepost=$(test-chmtime --get $rr/postimage) &&
183
test $oldmtimepost -lt $newmtimepost
184
'
185
@@ -512,7 +512,7 @@ test_expect_success 'multiple identical conflicts' '
512
count_pre_post 2 0 &&
513
514
# Pretend that the conflicts were made quite some time ago
515
- find .git/rr-cache/ -type f | xargs test-chmtime -172800 &&
515
+ test-chmtime -172800 $(find .git/rr-cache/ -type f) &&
516
517
# Unresolved entries have not expired yet
518
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
@@ -568,7 +568,7 @@ test_expect_success 'multiple identical conflicts' '
568
git rerere &&
569
570
# Pretend that the resolutions are old again
571
- find .git/rr-cache/ -type f | xargs test-chmtime -172800 &&
571
+ test-chmtime -172800 $(find .git/rr-cache/ -type f) &&
572
573
# Resolved entries have not expired yet
574
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
t/t5000-tar-tree.sh
+1
-1
@@ -192,7 +192,7 @@ test_expect_success \
192
'validate file modification time' \
193
'mkdir extract &&
194
"$TAR" xf b.tar -C extract a/a &&
195
- test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
195
+ test-chmtime --get extract/a/a >b.mtime &&
196
echo "1117231200" >expected.mtime &&
197
test_cmp expected.mtime b.mtime'
198
t/t6022-merge-rename.sh
+10
-15
@@ -635,10 +635,9 @@ test_expect_success 'setup avoid unnecessary update, normal rename' '
635
636
test_expect_success 'avoid unnecessary update, normal rename' '
637
git checkout -q avoid-unnecessary-update-1^0 &&
638
- test-chmtime =1000000000 rename &&
639
- test-chmtime -v +0 rename >expect &&
638
+ test-chmtime --get =1000000000 rename >expect &&
639
git merge merge-branch-1 &&
641
- test-chmtime -v +0 rename >actual &&
640
+ test-chmtime --get rename >actual &&
641
test_cmp expect actual # "rename" should have stayed intact
642
'
643
@@ -668,10 +667,9 @@ test_expect_success 'setup to test avoiding unnecessary update, with D/F conflic
667
668
test_expect_success 'avoid unnecessary update, with D/F conflict' '
669
git checkout -q avoid-unnecessary-update-2^0 &&
671
- test-chmtime =1000000000 df &&
672
- test-chmtime -v +0 df >expect &&
670
+ test-chmtime --get =1000000000 df >expect &&
671
git merge merge-branch-2 &&
674
- test-chmtime -v +0 df >actual &&
672
+ test-chmtime --get df >actual &&
673
test_cmp expect actual # "df" should have stayed intact
674
'
675
@@ -700,10 +698,9 @@ test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
698
699
test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
700
git checkout -q master^0 &&
703
- test-chmtime =1000000000 df &&
704
- test-chmtime -v +0 df >expect &&
701
+ test-chmtime --get =1000000000 df >expect &&
702
git merge side &&
706
- test-chmtime -v +0 df >actual &&
703
+ test-chmtime --get df >actual &&
704
test_cmp expect actual # "df" should have stayed intact
705
'
706
@@ -730,10 +727,9 @@ test_expect_success 'setup avoid unnecessary update, modify/delete' '
727
728
test_expect_success 'avoid unnecessary update, modify/delete' '
729
git checkout -q master^0 &&
733
- test-chmtime =1000000000 file &&
734
- test-chmtime -v +0 file >expect &&
730
+ test-chmtime --get =1000000000 file >expect &&
731
test_must_fail git merge side &&
736
- test-chmtime -v +0 file >actual &&
732
+ test-chmtime --get file >actual &&
733
test_cmp expect actual # "file" should have stayed intact
734
'
735
@@ -759,10 +755,9 @@ test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
755
756
test_expect_success 'avoid unnecessary update, rename/add-dest' '
757
git checkout -q master^0 &&
762
- test-chmtime =1000000000 newfile &&
763
- test-chmtime -v +0 newfile >expect &&
758
+ test-chmtime --get =1000000000 newfile >expect &&
759
git merge side &&
765
- test-chmtime -v +0 newfile >actual &&
760
+ test-chmtime --get newfile >actual &&
761
test_cmp expect actual # "file" should have stayed intact
762
'
763
t/t6501-freshen-objects.sh
+2
-4
@@ -72,8 +72,7 @@ for repack in '' true; do
72
'
73
74
test_expect_success "simulate time passing ($title)" '
75
- find .git/objects -type f |
76
- xargs test-chmtime -v -86400
75
+ test-chmtime --get -86400 $(find .git/objects -type f)
76
'
77
78
test_expect_success "start writing new commit with old blob ($title)" '
@@ -103,8 +102,7 @@ for repack in '' true; do
102
103
test_expect_success "abandon objects again ($title)" '
104
git reset --hard HEAD^ &&
106
- find .git/objects -type f |
107
- xargs test-chmtime -v -86400
105
+ test-chmtime --get -86400 $(find .git/objects -type f)
106
'
107
108
test_expect_success "start writing new commit with same tree ($title)" '
t/t7508-status.sh
+2
-2
@@ -1674,10 +1674,10 @@ test_expect_success '"Initial commit" should not be noted in commit template' '
1674
test_expect_success '--no-optional-locks prevents index update' '
1675
test-chmtime =1234567890 .git/index &&
1676
git --no-optional-locks status &&
1677
- test-chmtime -v +0 .git/index >out &&
1677
+ test-chmtime --get .git/index >out &&
1678
grep ^1234567890 out &&
1679
git status &&
1680
- test-chmtime -v +0 .git/index >out &&
1680
+ test-chmtime --get .git/index >out &&
1681
! grep ^1234567890 out
1682
'
1683
t/t7701-repack-unpack-unreachable.sh
+3
-3
@@ -55,8 +55,8 @@ test_expect_success '-A with -d option leaves unreachable objects unpacked' '
55
56
compare_mtimes ()
57
{
58
- read tref rest &&
59
- while read t rest; do
58
+ read tref &&
59
+ while read t; do
60
test "$tref" = "$t" || return 1
61
done
62
}
@@ -90,7 +90,7 @@ test_expect_success 'unpacked objects receive timestamp of pack file' '
90
tmppack=".git/objects/pack/tmp_pack" &&
91
ln "$packfile" "$tmppack" &&
92
git repack -A -l -d &&
93
- test-chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
93
+ test-chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
94
> mtimes &&
95
compare_mtimes < mtimes
96
'