Skip to content

Commit decf711

Browse files
ungpsgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d32eb83 commit decf711

10 files changed

+63
-42
lines changed

t/helper/test-chmtime.c

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,29 @@
1818
*
1919
* Examples:
2020
*
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:
2223
*
2324
* test-chmtime -v +0 file
2425
*
26+
* To print only the mtime use --get:
27+
*
28+
* test-chmtime --get file
29+
*
2530
* To set the mtime to current time:
2631
*
2732
* test-chmtime =+0 file
2833
*
34+
* To set the file mtime offset to +1 and print the new value:
35+
*
36+
* test-chmtime --get +1 file
37+
*
2938
*/
3039
#include "git-compat-util.h"
3140
#include <utime.h>
3241

33-
static const char usage_str[] = "-v|--verbose (+|=|=+|=-|-)<seconds> <file>...";
42+
static const char usage_str[] =
43+
"(-v|--verbose|-g|--get) (+|=|=+|=-|-)<seconds> <file>...";
3444

3545
static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
3646
{
@@ -46,7 +56,6 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
4656
}
4757
*set_time = strtol(timespec, &test, 10);
4858
if (*test) {
49-
fprintf(stderr, "Not a base-10 integer: %s\n", arg + 1);
5059
return 0;
5160
}
5261
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)
5968
int cmd_main(int argc, const char **argv)
6069
{
6170
static int verbose;
71+
static int get;
6272

6373
int i = 1;
6474
/* no mtime change by default */
@@ -68,18 +78,34 @@ int cmd_main(int argc, const char **argv)
6878
if (argc < 3)
6979
goto usage;
7080

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) {
7285
verbose = 1;
7386
++i;
7487
}
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)) {
7694
++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)
78103
goto usage;
79104

80105
for (; i < argc; i++) {
81106
struct stat sb;
82107
struct utimbuf utb;
108+
uintmax_t mtime;
83109

84110
if (stat(argv[i], &sb) < 0) {
85111
fprintf(stderr, "Failed to stat %s: %s\n",
@@ -99,8 +125,10 @@ int cmd_main(int argc, const char **argv)
99125
utb.actime = sb.st_atime;
100126
utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
101127

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) {
104132
printf("%"PRIuMAX"\t%s\n", mtime, argv[i]);
105133
}
106134

t/t2022-checkout-paths.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ test_expect_success 'do not touch files that are already up-to-date' '
7373
git checkout HEAD -- file1 file2 &&
7474
echo one >expect &&
7575
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 &&
7878
test_cmp expect actual
7979
'
8080

t/t3404-rebase-interactive.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -705,7 +705,7 @@ test_expect_success 'avoid unnecessary reset' '
705705
set_fake_editor &&
706706
git rebase -i HEAD~4 &&
707707
test $HEAD = $(git rev-parse HEAD) &&
708-
MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
708+
MTIME=$(test-chmtime --get file3) &&
709709
test 123456789 = $MTIME
710710
'
711711

t/t3510-cherry-pick-sequence.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,9 @@ test_expect_success '--abort after last commit in sequence' '
247247
test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
248248
pristine_detach initial &&
249249
test_expect_code 1 git cherry-pick base..anotherpick &&
250-
test-chmtime -v +0 .git/sequencer >expect &&
250+
test-chmtime --get .git/sequencer >expect &&
251251
test_expect_code 128 git cherry-pick unrelatedpick &&
252-
test-chmtime -v +0 .git/sequencer >actual &&
252+
test-chmtime --get .git/sequencer >actual &&
253253
test_cmp expect actual
254254
'
255255

t/t4200-rerere.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ test_expect_success 'first postimage wins' '
166166
git commit -q -a -m "prefer first over second" &&
167167
test -f $rr/postimage &&
168168
169-
oldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) &&
169+
oldmtimepost=$(test-chmtime --get -60 $rr/postimage) &&
170170
171171
git checkout -b third master &&
172172
git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
@@ -179,7 +179,7 @@ test_expect_success 'first postimage wins' '
179179
'
180180

181181
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) &&
183183
test $oldmtimepost -lt $newmtimepost
184184
'
185185

@@ -512,7 +512,7 @@ test_expect_success 'multiple identical conflicts' '
512512
count_pre_post 2 0 &&
513513
514514
# 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) &&
516516
517517
# Unresolved entries have not expired yet
518518
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
@@ -568,7 +568,7 @@ test_expect_success 'multiple identical conflicts' '
568568
git rerere &&
569569
570570
# 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) &&
572572
573573
# Resolved entries have not expired yet
574574
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&

t/t5000-tar-tree.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ test_expect_success \
192192
'validate file modification time' \
193193
'mkdir extract &&
194194
"$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 &&
196196
echo "1117231200" >expected.mtime &&
197197
test_cmp expected.mtime b.mtime'
198198

t/t6022-merge-rename.sh

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -635,10 +635,9 @@ test_expect_success 'setup avoid unnecessary update, normal rename' '
635635

636636
test_expect_success 'avoid unnecessary update, normal rename' '
637637
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 &&
640639
git merge merge-branch-1 &&
641-
test-chmtime -v +0 rename >actual &&
640+
test-chmtime --get rename >actual &&
642641
test_cmp expect actual # "rename" should have stayed intact
643642
'
644643

@@ -668,10 +667,9 @@ test_expect_success 'setup to test avoiding unnecessary update, with D/F conflic
668667

669668
test_expect_success 'avoid unnecessary update, with D/F conflict' '
670669
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 &&
673671
git merge merge-branch-2 &&
674-
test-chmtime -v +0 df >actual &&
672+
test-chmtime --get df >actual &&
675673
test_cmp expect actual # "df" should have stayed intact
676674
'
677675

@@ -700,10 +698,9 @@ test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
700698

701699
test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
702700
git checkout -q master^0 &&
703-
test-chmtime =1000000000 df &&
704-
test-chmtime -v +0 df >expect &&
701+
test-chmtime --get =1000000000 df >expect &&
705702
git merge side &&
706-
test-chmtime -v +0 df >actual &&
703+
test-chmtime --get df >actual &&
707704
test_cmp expect actual # "df" should have stayed intact
708705
'
709706

@@ -730,10 +727,9 @@ test_expect_success 'setup avoid unnecessary update, modify/delete' '
730727

731728
test_expect_success 'avoid unnecessary update, modify/delete' '
732729
git checkout -q master^0 &&
733-
test-chmtime =1000000000 file &&
734-
test-chmtime -v +0 file >expect &&
730+
test-chmtime --get =1000000000 file >expect &&
735731
test_must_fail git merge side &&
736-
test-chmtime -v +0 file >actual &&
732+
test-chmtime --get file >actual &&
737733
test_cmp expect actual # "file" should have stayed intact
738734
'
739735

@@ -759,10 +755,9 @@ test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
759755

760756
test_expect_success 'avoid unnecessary update, rename/add-dest' '
761757
git checkout -q master^0 &&
762-
test-chmtime =1000000000 newfile &&
763-
test-chmtime -v +0 newfile >expect &&
758+
test-chmtime --get =1000000000 newfile >expect &&
764759
git merge side &&
765-
test-chmtime -v +0 newfile >actual &&
760+
test-chmtime --get newfile >actual &&
766761
test_cmp expect actual # "file" should have stayed intact
767762
'
768763

t/t6501-freshen-objects.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ for repack in '' true; do
7272
'
7373

7474
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)
7776
'
7877

7978
test_expect_success "start writing new commit with old blob ($title)" '
@@ -103,8 +102,7 @@ for repack in '' true; do
103102

104103
test_expect_success "abandon objects again ($title)" '
105104
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)
108106
'
109107

110108
test_expect_success "start writing new commit with same tree ($title)" '

t/t7508-status.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1674,10 +1674,10 @@ test_expect_success '"Initial commit" should not be noted in commit template' '
16741674
test_expect_success '--no-optional-locks prevents index update' '
16751675
test-chmtime =1234567890 .git/index &&
16761676
git --no-optional-locks status &&
1677-
test-chmtime -v +0 .git/index >out &&
1677+
test-chmtime --get .git/index >out &&
16781678
grep ^1234567890 out &&
16791679
git status &&
1680-
test-chmtime -v +0 .git/index >out &&
1680+
test-chmtime --get .git/index >out &&
16811681
! grep ^1234567890 out
16821682
'
16831683

t/t7701-repack-unpack-unreachable.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ test_expect_success '-A with -d option leaves unreachable objects unpacked' '
5555

5656
compare_mtimes ()
5757
{
58-
read tref rest &&
59-
while read t rest; do
58+
read tref &&
59+
while read t; do
6060
test "$tref" = "$t" || return 1
6161
done
6262
}
@@ -90,7 +90,7 @@ test_expect_success 'unpacked objects receive timestamp of pack file' '
9090
tmppack=".git/objects/pack/tmp_pack" &&
9191
ln "$packfile" "$tmppack" &&
9292
git repack -A -l -d &&
93-
test-chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
93+
test-chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
9494
> mtimes &&
9595
compare_mtimes < mtimes
9696
'

0 commit comments

Comments
 (0)