Skip to content

Commit deb9845

Browse files
committed
Merge branch 'ps/test-chmtime-get'
Test cleanup. * ps/test-chmtime-get: t/helper: 'test-chmtime (--get|-g)' to print only the mtime
2 parents 3d5a179 + decf711 commit deb9845

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,20 +18,30 @@
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-tool chmtime -v +0 file
2425
*
26+
* To print only the mtime use --get:
27+
*
28+
* test-tool chmtime --get file
29+
*
2530
* To set the mtime to current time:
2631
*
2732
* test-tool chmtime =+0 file
2833
*
34+
* To set the file mtime offset to +1 and print the new value:
35+
*
36+
* test-tool chmtime --get +1 file
37+
*
2938
*/
3039
#include "test-tool.h"
3140
#include "git-compat-util.h"
3241
#include <utime.h>
3342

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

3646
static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
3747
{
@@ -47,7 +57,6 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
4757
}
4858
*set_time = strtol(timespec, &test, 10);
4959
if (*test) {
50-
fprintf(stderr, "Not a base-10 integer: %s\n", arg + 1);
5160
return 0;
5261
}
5362
if ((*set_eq && *set_time < 0) || *set_eq == 2) {
@@ -60,6 +69,7 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
6069
int cmd__chmtime(int argc, const char **argv)
6170
{
6271
static int verbose;
72+
static int get;
6373

6474
int i = 1;
6575
/* no mtime change by default */
@@ -69,18 +79,34 @@ int cmd__chmtime(int argc, const char **argv)
6979
if (argc < 3)
7080
goto usage;
7181

72-
if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
82+
if (strcmp(argv[i], "--get") == 0 || strcmp(argv[i], "-g") == 0) {
83+
get = 1;
84+
++i;
85+
} else if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
7386
verbose = 1;
7487
++i;
7588
}
76-
if (timespec_arg(argv[i], &set_time, &set_eq))
89+
90+
if (i == argc) {
91+
goto usage;
92+
}
93+
94+
if (timespec_arg(argv[i], &set_time, &set_eq)) {
7795
++i;
78-
else
96+
} else {
97+
if (get == 0) {
98+
fprintf(stderr, "Not a base-10 integer: %s\n", argv[i] + 1);
99+
goto usage;
100+
}
101+
}
102+
103+
if (i == argc)
79104
goto usage;
80105

81106
for (; i < argc; i++) {
82107
struct stat sb;
83108
struct utimbuf utb;
109+
uintmax_t mtime;
84110

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

103-
if (verbose) {
104-
uintmax_t mtime = utb.modtime < 0 ? 0: utb.modtime;
129+
mtime = utb.modtime < 0 ? 0: utb.modtime;
130+
if (get) {
131+
printf("%"PRIuMAX"\n", mtime);
132+
} else if (verbose) {
105133
printf("%"PRIuMAX"\t%s\n", mtime, argv[i]);
106134
}
107135

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-tool chmtime -v +0 file2 >actual &&
76+
echo "1000000000" >expect &&
77+
test-tool 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
@@ -717,7 +717,7 @@ test_expect_success 'avoid unnecessary reset' '
717717
set_fake_editor &&
718718
git rebase -i HEAD~4 &&
719719
test $HEAD = $(git rev-parse HEAD) &&
720-
MTIME=$(test-tool chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
720+
MTIME=$(test-tool chmtime --get file3) &&
721721
test 123456789 = $MTIME
722722
'
723723

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-tool chmtime -v +0 .git/sequencer >expect &&
250+
test-tool chmtime --get .git/sequencer >expect &&
251251
test_expect_code 128 git cherry-pick unrelatedpick &&
252-
test-tool chmtime -v +0 .git/sequencer >actual &&
252+
test-tool 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-tool chmtime -v -60 $rr/postimage | cut -f 1) &&
169+
oldmtimepost=$(test-tool 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-tool chmtime -v +0 $rr/postimage | cut -f 1) &&
182+
newmtimepost=$(test-tool 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-tool chmtime -172800 &&
515+
test-tool 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-tool chmtime -172800 &&
571+
test-tool 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-tool chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
195+
test-tool 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-tool chmtime =1000000000 rename &&
639-
test-tool chmtime -v +0 rename >expect &&
638+
test-tool chmtime --get =1000000000 rename >expect &&
640639
git merge merge-branch-1 &&
641-
test-tool chmtime -v +0 rename >actual &&
640+
test-tool 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-tool chmtime =1000000000 df &&
672-
test-tool chmtime -v +0 df >expect &&
670+
test-tool chmtime --get =1000000000 df >expect &&
673671
git merge merge-branch-2 &&
674-
test-tool chmtime -v +0 df >actual &&
672+
test-tool 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-tool chmtime =1000000000 df &&
704-
test-tool chmtime -v +0 df >expect &&
701+
test-tool chmtime --get =1000000000 df >expect &&
705702
git merge side &&
706-
test-tool chmtime -v +0 df >actual &&
703+
test-tool 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-tool chmtime =1000000000 file &&
734-
test-tool chmtime -v +0 file >expect &&
730+
test-tool chmtime --get =1000000000 file >expect &&
735731
test_must_fail git merge side &&
736-
test-tool chmtime -v +0 file >actual &&
732+
test-tool 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-tool chmtime =1000000000 newfile &&
763-
test-tool chmtime -v +0 newfile >expect &&
758+
test-tool chmtime --get =1000000000 newfile >expect &&
764759
git merge side &&
765-
test-tool chmtime -v +0 newfile >actual &&
760+
test-tool 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-tool chmtime -v -86400
75+
test-tool 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-tool chmtime -v -86400
105+
test-tool 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-tool chmtime =1234567890 .git/index &&
16761676
git --no-optional-locks status &&
1677-
test-tool chmtime -v +0 .git/index >out &&
1677+
test-tool chmtime --get .git/index >out &&
16781678
grep ^1234567890 out &&
16791679
git status &&
1680-
test-tool chmtime -v +0 .git/index >out &&
1680+
test-tool 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-tool chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
93+
test-tool chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
9494
> mtimes &&
9595
compare_mtimes < mtimes
9696
'

0 commit comments

Comments
 (0)