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>
This commit is contained in:
parent
d32eb83c1d
commit
decf711fc1
@ -18,19 +18,29 @@
|
|||||||
*
|
*
|
||||||
* Examples:
|
* Examples:
|
||||||
*
|
*
|
||||||
* To just print the mtime use --verbose and set the file mtime offset to 0:
|
* To print the mtime and the file name use --verbose and set
|
||||||
|
* the file mtime offset to 0:
|
||||||
*
|
*
|
||||||
* test-chmtime -v +0 file
|
* test-chmtime -v +0 file
|
||||||
*
|
*
|
||||||
|
* To print only the mtime use --get:
|
||||||
|
*
|
||||||
|
* test-chmtime --get file
|
||||||
|
*
|
||||||
* To set the mtime to current time:
|
* To set the mtime to current time:
|
||||||
*
|
*
|
||||||
* test-chmtime =+0 file
|
* test-chmtime =+0 file
|
||||||
*
|
*
|
||||||
|
* To set the file mtime offset to +1 and print the new value:
|
||||||
|
*
|
||||||
|
* test-chmtime --get +1 file
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
#include <utime.h>
|
#include <utime.h>
|
||||||
|
|
||||||
static const char usage_str[] = "-v|--verbose (+|=|=+|=-|-)<seconds> <file>...";
|
static const char usage_str[] =
|
||||||
|
"(-v|--verbose|-g|--get) (+|=|=+|=-|-)<seconds> <file>...";
|
||||||
|
|
||||||
static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
|
static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
|
||||||
{
|
{
|
||||||
@ -46,7 +56,6 @@ static int timespec_arg(const char *arg, long int *set_time, int *set_eq)
|
|||||||
}
|
}
|
||||||
*set_time = strtol(timespec, &test, 10);
|
*set_time = strtol(timespec, &test, 10);
|
||||||
if (*test) {
|
if (*test) {
|
||||||
fprintf(stderr, "Not a base-10 integer: %s\n", arg + 1);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((*set_eq && *set_time < 0) || *set_eq == 2) {
|
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)
|
|||||||
int cmd_main(int argc, const char **argv)
|
int cmd_main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
static int verbose;
|
static int verbose;
|
||||||
|
static int get;
|
||||||
|
|
||||||
int i = 1;
|
int i = 1;
|
||||||
/* no mtime change by default */
|
/* no mtime change by default */
|
||||||
@ -68,18 +78,34 @@ int cmd_main(int argc, const char **argv)
|
|||||||
if (argc < 3)
|
if (argc < 3)
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
||||||
if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
if (strcmp(argv[i], "--get") == 0 || strcmp(argv[i], "-g") == 0) {
|
||||||
|
get = 1;
|
||||||
|
++i;
|
||||||
|
} else if (strcmp(argv[i], "--verbose") == 0 || strcmp(argv[i], "-v") == 0) {
|
||||||
verbose = 1;
|
verbose = 1;
|
||||||
++i;
|
++i;
|
||||||
}
|
}
|
||||||
if (timespec_arg(argv[i], &set_time, &set_eq))
|
|
||||||
|
if (i == argc) {
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timespec_arg(argv[i], &set_time, &set_eq)) {
|
||||||
++i;
|
++i;
|
||||||
else
|
} else {
|
||||||
|
if (get == 0) {
|
||||||
|
fprintf(stderr, "Not a base-10 integer: %s\n", argv[i] + 1);
|
||||||
|
goto usage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == argc)
|
||||||
goto usage;
|
goto usage;
|
||||||
|
|
||||||
for (; i < argc; i++) {
|
for (; i < argc; i++) {
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
struct utimbuf utb;
|
struct utimbuf utb;
|
||||||
|
uintmax_t mtime;
|
||||||
|
|
||||||
if (stat(argv[i], &sb) < 0) {
|
if (stat(argv[i], &sb) < 0) {
|
||||||
fprintf(stderr, "Failed to stat %s: %s\n",
|
fprintf(stderr, "Failed to stat %s: %s\n",
|
||||||
@ -99,8 +125,10 @@ int cmd_main(int argc, const char **argv)
|
|||||||
utb.actime = sb.st_atime;
|
utb.actime = sb.st_atime;
|
||||||
utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
|
utb.modtime = set_eq ? set_time : sb.st_mtime + set_time;
|
||||||
|
|
||||||
if (verbose) {
|
mtime = utb.modtime < 0 ? 0: utb.modtime;
|
||||||
uintmax_t mtime = utb.modtime < 0 ? 0: utb.modtime;
|
if (get) {
|
||||||
|
printf("%"PRIuMAX"\n", mtime);
|
||||||
|
} else if (verbose) {
|
||||||
printf("%"PRIuMAX"\t%s\n", mtime, argv[i]);
|
printf("%"PRIuMAX"\t%s\n", mtime, argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ test_expect_success 'do not touch files that are already up-to-date' '
|
|||||||
git checkout HEAD -- file1 file2 &&
|
git checkout HEAD -- file1 file2 &&
|
||||||
echo one >expect &&
|
echo one >expect &&
|
||||||
test_cmp expect file1 &&
|
test_cmp expect file1 &&
|
||||||
echo "1000000000 file2" >expect &&
|
echo "1000000000" >expect &&
|
||||||
test-chmtime -v +0 file2 >actual &&
|
test-chmtime --get file2 >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -705,7 +705,7 @@ test_expect_success 'avoid unnecessary reset' '
|
|||||||
set_fake_editor &&
|
set_fake_editor &&
|
||||||
git rebase -i HEAD~4 &&
|
git rebase -i HEAD~4 &&
|
||||||
test $HEAD = $(git rev-parse HEAD) &&
|
test $HEAD = $(git rev-parse HEAD) &&
|
||||||
MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') &&
|
MTIME=$(test-chmtime --get file3) &&
|
||||||
test 123456789 = $MTIME
|
test 123456789 = $MTIME
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -247,9 +247,9 @@ test_expect_success '--abort after last commit in sequence' '
|
|||||||
test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
|
test_expect_success 'cherry-pick does not implicitly stomp an existing operation' '
|
||||||
pristine_detach initial &&
|
pristine_detach initial &&
|
||||||
test_expect_code 1 git cherry-pick base..anotherpick &&
|
test_expect_code 1 git cherry-pick base..anotherpick &&
|
||||||
test-chmtime -v +0 .git/sequencer >expect &&
|
test-chmtime --get .git/sequencer >expect &&
|
||||||
test_expect_code 128 git cherry-pick unrelatedpick &&
|
test_expect_code 128 git cherry-pick unrelatedpick &&
|
||||||
test-chmtime -v +0 .git/sequencer >actual &&
|
test-chmtime --get .git/sequencer >actual &&
|
||||||
test_cmp expect actual
|
test_cmp expect actual
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ test_expect_success 'first postimage wins' '
|
|||||||
git commit -q -a -m "prefer first over second" &&
|
git commit -q -a -m "prefer first over second" &&
|
||||||
test -f $rr/postimage &&
|
test -f $rr/postimage &&
|
||||||
|
|
||||||
oldmtimepost=$(test-chmtime -v -60 $rr/postimage | cut -f 1) &&
|
oldmtimepost=$(test-chmtime --get -60 $rr/postimage) &&
|
||||||
|
|
||||||
git checkout -b third master &&
|
git checkout -b third master &&
|
||||||
git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
|
git show second^:a1 | sed "s/To die: t/To die! T/" >a1 &&
|
||||||
@ -179,7 +179,7 @@ test_expect_success 'first postimage wins' '
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'rerere updates postimage timestamp' '
|
test_expect_success 'rerere updates postimage timestamp' '
|
||||||
newmtimepost=$(test-chmtime -v +0 $rr/postimage | cut -f 1) &&
|
newmtimepost=$(test-chmtime --get $rr/postimage) &&
|
||||||
test $oldmtimepost -lt $newmtimepost
|
test $oldmtimepost -lt $newmtimepost
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -512,7 +512,7 @@ test_expect_success 'multiple identical conflicts' '
|
|||||||
count_pre_post 2 0 &&
|
count_pre_post 2 0 &&
|
||||||
|
|
||||||
# Pretend that the conflicts were made quite some time ago
|
# Pretend that the conflicts were made quite some time ago
|
||||||
find .git/rr-cache/ -type f | xargs test-chmtime -172800 &&
|
test-chmtime -172800 $(find .git/rr-cache/ -type f) &&
|
||||||
|
|
||||||
# Unresolved entries have not expired yet
|
# Unresolved entries have not expired yet
|
||||||
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
|
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
|
||||||
@ -568,7 +568,7 @@ test_expect_success 'multiple identical conflicts' '
|
|||||||
git rerere &&
|
git rerere &&
|
||||||
|
|
||||||
# Pretend that the resolutions are old again
|
# Pretend that the resolutions are old again
|
||||||
find .git/rr-cache/ -type f | xargs test-chmtime -172800 &&
|
test-chmtime -172800 $(find .git/rr-cache/ -type f) &&
|
||||||
|
|
||||||
# Resolved entries have not expired yet
|
# Resolved entries have not expired yet
|
||||||
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
|
git -c gc.rerereresolved=5 -c gc.rerereunresolved=5 rerere gc &&
|
||||||
|
@ -192,7 +192,7 @@ test_expect_success \
|
|||||||
'validate file modification time' \
|
'validate file modification time' \
|
||||||
'mkdir extract &&
|
'mkdir extract &&
|
||||||
"$TAR" xf b.tar -C extract a/a &&
|
"$TAR" xf b.tar -C extract a/a &&
|
||||||
test-chmtime -v +0 extract/a/a |cut -f 1 >b.mtime &&
|
test-chmtime --get extract/a/a >b.mtime &&
|
||||||
echo "1117231200" >expected.mtime &&
|
echo "1117231200" >expected.mtime &&
|
||||||
test_cmp expected.mtime b.mtime'
|
test_cmp expected.mtime b.mtime'
|
||||||
|
|
||||||
|
@ -635,10 +635,9 @@ test_expect_success 'setup avoid unnecessary update, normal rename' '
|
|||||||
|
|
||||||
test_expect_success 'avoid unnecessary update, normal rename' '
|
test_expect_success 'avoid unnecessary update, normal rename' '
|
||||||
git checkout -q avoid-unnecessary-update-1^0 &&
|
git checkout -q avoid-unnecessary-update-1^0 &&
|
||||||
test-chmtime =1000000000 rename &&
|
test-chmtime --get =1000000000 rename >expect &&
|
||||||
test-chmtime -v +0 rename >expect &&
|
|
||||||
git merge merge-branch-1 &&
|
git merge merge-branch-1 &&
|
||||||
test-chmtime -v +0 rename >actual &&
|
test-chmtime --get rename >actual &&
|
||||||
test_cmp expect actual # "rename" should have stayed intact
|
test_cmp expect actual # "rename" should have stayed intact
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -668,10 +667,9 @@ test_expect_success 'setup to test avoiding unnecessary update, with D/F conflic
|
|||||||
|
|
||||||
test_expect_success 'avoid unnecessary update, with D/F conflict' '
|
test_expect_success 'avoid unnecessary update, with D/F conflict' '
|
||||||
git checkout -q avoid-unnecessary-update-2^0 &&
|
git checkout -q avoid-unnecessary-update-2^0 &&
|
||||||
test-chmtime =1000000000 df &&
|
test-chmtime --get =1000000000 df >expect &&
|
||||||
test-chmtime -v +0 df >expect &&
|
|
||||||
git merge merge-branch-2 &&
|
git merge merge-branch-2 &&
|
||||||
test-chmtime -v +0 df >actual &&
|
test-chmtime --get df >actual &&
|
||||||
test_cmp expect actual # "df" should have stayed intact
|
test_cmp expect actual # "df" should have stayed intact
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -700,10 +698,9 @@ test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' '
|
|||||||
|
|
||||||
test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
|
test_expect_success 'avoid unnecessary update, dir->(file,nothing)' '
|
||||||
git checkout -q master^0 &&
|
git checkout -q master^0 &&
|
||||||
test-chmtime =1000000000 df &&
|
test-chmtime --get =1000000000 df >expect &&
|
||||||
test-chmtime -v +0 df >expect &&
|
|
||||||
git merge side &&
|
git merge side &&
|
||||||
test-chmtime -v +0 df >actual &&
|
test-chmtime --get df >actual &&
|
||||||
test_cmp expect actual # "df" should have stayed intact
|
test_cmp expect actual # "df" should have stayed intact
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -730,10 +727,9 @@ test_expect_success 'setup avoid unnecessary update, modify/delete' '
|
|||||||
|
|
||||||
test_expect_success 'avoid unnecessary update, modify/delete' '
|
test_expect_success 'avoid unnecessary update, modify/delete' '
|
||||||
git checkout -q master^0 &&
|
git checkout -q master^0 &&
|
||||||
test-chmtime =1000000000 file &&
|
test-chmtime --get =1000000000 file >expect &&
|
||||||
test-chmtime -v +0 file >expect &&
|
|
||||||
test_must_fail git merge side &&
|
test_must_fail git merge side &&
|
||||||
test-chmtime -v +0 file >actual &&
|
test-chmtime --get file >actual &&
|
||||||
test_cmp expect actual # "file" should have stayed intact
|
test_cmp expect actual # "file" should have stayed intact
|
||||||
'
|
'
|
||||||
|
|
||||||
@ -759,10 +755,9 @@ test_expect_success 'setup avoid unnecessary update, rename/add-dest' '
|
|||||||
|
|
||||||
test_expect_success 'avoid unnecessary update, rename/add-dest' '
|
test_expect_success 'avoid unnecessary update, rename/add-dest' '
|
||||||
git checkout -q master^0 &&
|
git checkout -q master^0 &&
|
||||||
test-chmtime =1000000000 newfile &&
|
test-chmtime --get =1000000000 newfile >expect &&
|
||||||
test-chmtime -v +0 newfile >expect &&
|
|
||||||
git merge side &&
|
git merge side &&
|
||||||
test-chmtime -v +0 newfile >actual &&
|
test-chmtime --get newfile >actual &&
|
||||||
test_cmp expect actual # "file" should have stayed intact
|
test_cmp expect actual # "file" should have stayed intact
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -72,8 +72,7 @@ for repack in '' true; do
|
|||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "simulate time passing ($title)" '
|
test_expect_success "simulate time passing ($title)" '
|
||||||
find .git/objects -type f |
|
test-chmtime --get -86400 $(find .git/objects -type f)
|
||||||
xargs test-chmtime -v -86400
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "start writing new commit with old blob ($title)" '
|
test_expect_success "start writing new commit with old blob ($title)" '
|
||||||
@ -103,8 +102,7 @@ for repack in '' true; do
|
|||||||
|
|
||||||
test_expect_success "abandon objects again ($title)" '
|
test_expect_success "abandon objects again ($title)" '
|
||||||
git reset --hard HEAD^ &&
|
git reset --hard HEAD^ &&
|
||||||
find .git/objects -type f |
|
test-chmtime --get -86400 $(find .git/objects -type f)
|
||||||
xargs test-chmtime -v -86400
|
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success "start writing new commit with same tree ($title)" '
|
test_expect_success "start writing new commit with same tree ($title)" '
|
||||||
|
@ -1674,10 +1674,10 @@ test_expect_success '"Initial commit" should not be noted in commit template' '
|
|||||||
test_expect_success '--no-optional-locks prevents index update' '
|
test_expect_success '--no-optional-locks prevents index update' '
|
||||||
test-chmtime =1234567890 .git/index &&
|
test-chmtime =1234567890 .git/index &&
|
||||||
git --no-optional-locks status &&
|
git --no-optional-locks status &&
|
||||||
test-chmtime -v +0 .git/index >out &&
|
test-chmtime --get .git/index >out &&
|
||||||
grep ^1234567890 out &&
|
grep ^1234567890 out &&
|
||||||
git status &&
|
git status &&
|
||||||
test-chmtime -v +0 .git/index >out &&
|
test-chmtime --get .git/index >out &&
|
||||||
! grep ^1234567890 out
|
! grep ^1234567890 out
|
||||||
'
|
'
|
||||||
|
|
||||||
|
@ -55,8 +55,8 @@ test_expect_success '-A with -d option leaves unreachable objects unpacked' '
|
|||||||
|
|
||||||
compare_mtimes ()
|
compare_mtimes ()
|
||||||
{
|
{
|
||||||
read tref rest &&
|
read tref &&
|
||||||
while read t rest; do
|
while read t; do
|
||||||
test "$tref" = "$t" || return 1
|
test "$tref" = "$t" || return 1
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ test_expect_success 'unpacked objects receive timestamp of pack file' '
|
|||||||
tmppack=".git/objects/pack/tmp_pack" &&
|
tmppack=".git/objects/pack/tmp_pack" &&
|
||||||
ln "$packfile" "$tmppack" &&
|
ln "$packfile" "$tmppack" &&
|
||||||
git repack -A -l -d &&
|
git repack -A -l -d &&
|
||||||
test-chmtime -v +0 "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
|
test-chmtime --get "$tmppack" "$fsha1path" "$csha1path" "$tsha1path" \
|
||||||
> mtimes &&
|
> mtimes &&
|
||||||
compare_mtimes < mtimes
|
compare_mtimes < mtimes
|
||||||
'
|
'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user