Skip to content

Commit 53cd97d

Browse files
committed
Add ad/cd base date selectors for time shifting
Add `ad` (author date) and `cd` (commit date) as base date selectors, unifying them with the existing `now` keyword under `{ad|cd|now}`. - `ad` alone syncs commit date to author date - `cd` alone syncs author date to commit date - `ad<timediff>` shifts from author date (default, backward compatible) - `cd<timediff>` shifts from commit date Update copyright year to 2026.
1 parent 992377a commit 53cd97d

3 files changed

Lines changed: 30 additions & 21 deletions

File tree

‎LICENSE.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2010-2025 Akinori MUSHA
1+
Copyright (c) 2010-2026 Akinori MUSHA
22

33
All rights reserved.
44

‎README.md‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Requirements
1818
How to use
1919
----------
2020

21-
usage: git shift [options] {[<time>][<timediff>][timezone]|<datetime>} <rev-list>...
21+
usage: git shift [options] {[<time>][{ad|cd|now}][<timediff>][<timezone>]|<datetime>} <rev-list>...
2222

2323
-v, --verbose be verbose
2424
-n, --dry-run dry run
@@ -30,13 +30,15 @@ How to use
3030
- "HH:MM:SS"
3131
- "HH:MM" (= "HH:MM:00")
3232

33-
<timediff> add this time span to current commit time(s)
34-
in regexp: /^[-+]([0-9]+[wdhms])+$/
35-
e.g.
36-
+1d -12h 30m -1h30m -600s
33+
{ad|cd|now} select the base date (default: ad)
34+
ad author date
35+
cd commit date
36+
now current time
3737

38-
now[<timediff>] now, or now plus <timediff>
38+
<timediff> add this time span to the base date
39+
in regexp: /^[-+]([0-9]+[wdhms])+$/
3940
e.g.
41+
+1d -12h 30m -1h30m -600s cd+1d
4042
now now+1d now-1h30m
4143

4244
<timezone> in regexp: /^[-+][01][0-9][0-5][0-9]$/
@@ -56,7 +58,7 @@ How to use
5658
Author
5759
------
5860

59-
Copyright (c) 2010-2025 Akinori MUSHA.
61+
Copyright (c) 2010-2026 Akinori MUSHA.
6062

6163
Licensed under the 2-clause BSD license. See `LICENSE.txt` for
6264
further details.

‎git-shift‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# git-shift - shifts timestamps of commits after the fact
44
#
5-
# Copyright (c) 2010-2025 Akinori MUSHA
5+
# Copyright (c) 2010-2026 Akinori MUSHA
66
#
77
# All rights reserved.
88
#
@@ -44,19 +44,21 @@ my $exit_status = 0;
4444

4545
sub usage {
4646
print STDERR <<'EOS';
47-
usage: git shift [options] {[<time>][<timediff>][timezone]|<datetime>} <rev-list>...
47+
usage: git shift [options] {[<time>][{ad|cd|now}][<timediff>][<timezone>]|<datetime>} <rev-list>...
4848
4949
-v, --verbose be verbose
5050
-n, --dry-run dry run
5151
-k skip errors
5252
53-
<timediff> add this time span to current commit time(s)
54-
in regexp: /^[-+]([0-9]+[wdhms])+$/
55-
e.g.
56-
+1d -12h 30m -1h30m -600s
53+
{ad|cd|now} select the base date (default: ad)
54+
ad author date
55+
cd commit date
56+
now current time
5757
58-
now[<timediff>] now, or now plus <timediff>
58+
<timediff> add this time span to the base date
59+
in regexp: /^[-+]([0-9]+[wdhms])+$/
5960
e.g.
61+
+1d -12h 30m -1h30m -600s cd+1d
6062
now now+1d now-1h30m
6163
6264
<time> substitute this value for the time part(s) of
@@ -160,7 +162,7 @@ sub git_shift {
160162
my($atime, $atz, $ctime, $ctz) = @{$rev_info{$rev}};
161163
my $changed;
162164
if (exists($revs{$rev})) {
163-
my($ntime, $ntz) = $function->($atime, $atz);
165+
my($ntime, $ntz) = $function->($atime, $atz, $ctime, $ctz);
164166

165167
my($atimestr, $ctimestr, $ntimestr) = map {
166168
stringify_git_time(@$_);
@@ -284,12 +286,17 @@ sub parse_timespec {
284286
my($otime, $otz) = @_;
285287
($ntime, defined($ntz) ? $ntz : $otz);
286288
};
287-
} elsif ($timespec =~ /\A(?=.)(([0-9]{2}):([0-9]{2})(?::([0-9]{2}))?)?(now|today)?($re_span)?($re_tz)?\z/o) {
288-
my($hhmmss, $hh, $mm, $ss, $now, $span, $ntz) = ($1, $2, $3, $4, $5, $6);
289+
} elsif ($timespec =~ /\A(?=.)(([0-9]{2}):([0-9]{2})(?::([0-9]{2}))?)?(now|today|ad|cd)?($re_span)?($re_tz)?\z/o) {
290+
my($hhmmss, $hh, $mm, $ss, $base, $span, $ntz) = ($1, $2, $3, $4, $5, $6, $7);
289291
return sub {
290-
my($otime, $otz) = @_;
291-
if (defined($now)) {
292-
$otime = time();
292+
my($otime, $otz, $octime, $octz) = @_;
293+
if (defined($base)) {
294+
if ($base eq 'now' || $base eq 'today') {
295+
$otime = time();
296+
} elsif ($base eq 'cd') {
297+
$otime = $octime;
298+
$otz = $octz;
299+
}
293300
}
294301
if (defined($span) && defined(my $seconds = parse_timediff($span))) {
295302
$otime += $seconds;

0 commit comments

Comments
 (0)