-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgit-move-dates
executable file
·124 lines (81 loc) · 2.41 KB
/
git-move-dates
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#!/usr/bin/env perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
# process command-line options
my %option = (
weeks => 0,
days => 0,
hours => 0,
minutes => 0,
seconds => 0,
author => 0,
committer => 0,
);
GetOptions(
\%option, 'committer!', 'author!', 'dry-run!',
'weeks=i', 'days=i', 'hours=i', 'minutes=i',
'seconds=i', 'help', 'manual',
) or pod2usage();
pod2usage( -verbose => 1) if $option{help};
pod2usage( -verbose => 2) if $option{manual};
# by default, translate both
$option{author} = $option{committer} = 1
unless $option{author} || $option{committer};
# translation into seconds
my $seconds
= $option{seconds} + 60
* ( $option{minutes} + 60
* ( $option{hours} + 24
* ( $option{days} + 7
* $option{weeks} )
)
);
# nothing to do
exit 0 if ! $seconds;
# generate the shell command
my $cmd = q{git filter-branch --commit-filter '};
$cmd .= qq{GIT_${_}_DATE=`echo "\$GIT_${_}_DATE"|perl -pe'\\''s/\\d+/\$&+$seconds/e'\\''`;}
for map uc, grep { $option{$_} } qw( author committer );
$cmd .= q{git commit-tree "$@"' -- };
$cmd .= join ' ', map {qq{"$_"}} @ARGV;
# print it or run it
if ( $option{'dry-run'} ) { print "$cmd\n"; }
else { exec $cmd; }
__END__
=head1 NAME
git-move-dates - simple translation of commit dates
=head1 SYNOPSIS
B<git-move-dates> [ B<options> ] [ I<rev-list> ]
=head1 DESCRIPTION
B<git-move-dates> uses B<git filter-branch> to rewrite commits by
translating their GIT_AUTHOR_DATE and GITy_COMMITER_DATE.
=head2 Command-line options
B<git-move-dates> accepts the following options:
=over 4
=item B<--dry-run>
Print the generated command instead of executing it.
=item B<--author>
Move the GIT_AUTHOR_DATE.
=item B<--committer>
Move the GIT_COMMITTER_DATE.
=item B<--seconds> I<seconds>
=item B<--minutes> I<minutes>
=item B<--hours> I<hours>
=item B<--days> I<days>
=item B<--weeks> I<weeks>
Add an offset of the given unit (positive or negative).
It's possible to combine them with something like:
git-move-dates --days 1 --hours 1
=item B<--help>
Provide a short help summary.
=item B<--manual>
Show this manual page.
=back
=head1 AUTHOR
Philippe Bruhat (BooK), C<< [email protected] >>.
=head1 LICENSE
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
=cut