Skip to content

Commit 87d1133

Browse files
committed
initial import
0 parents  commit 87d1133

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

changedate.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import click
2+
import datetime
3+
import git
4+
5+
6+
@click.command()
7+
@click.option('-d', '--date')
8+
@click.argument('base')
9+
def main(date, base):
10+
if date is None:
11+
date = datetime.datetime.now()
12+
else:
13+
date = datetime.datetime.fromisoformat(date)
14+
15+
if '..' not in base:
16+
base = f'{base}..HEAD'
17+
18+
repo = git.Repo()
19+
branch = repo.active_branch
20+
old_head = repo.head.commit
21+
22+
for commit in repo.iter_commits(base):
23+
print(commit.hexsha[:7])
24+
repo.git.checkout(commit)
25+
repo.git.commit(amend=True, no_edit=True, date=date.isoformat())
26+
repo.git.rebase('HEAD', branch)
27+
28+
new_head = repo.head.commit
29+
print(f'{old_head.hexsha[:7]} -> {new_head.hexsha[:7]}')
30+
31+
32+
if __name__ == '__main__':
33+
main()

editmsg-recurse.py

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import click
2+
import git
3+
4+
5+
def clone_commit(old, **kwargs):
6+
md = dict(
7+
message=old.message,
8+
parent_commits=old.parents,
9+
author=old.author,
10+
committer=old.committer,
11+
author_date=old.authored_datetime,
12+
commit_date=old.committed_datetime
13+
)
14+
15+
md.update(kwargs)
16+
17+
return git.Commit.create_from_tree(
18+
old.repo, old.tree, **md)
19+
20+
21+
def replace(commit, target=None, seen=None, **kwargs):
22+
'''update commit <target>
23+
24+
traverse tree looking for target, then make any requested changes.
25+
26+
ensure we visit each node only once
27+
'''
28+
29+
if seen is None:
30+
seen = set()
31+
32+
if commit.hexsha in seen:
33+
return commit
34+
35+
seen.add(commit.hexsha)
36+
37+
if commit == target:
38+
new = clone_commit(commit, **kwargs)
39+
return new
40+
41+
parents = list(commit.parents)
42+
for i, parent in enumerate(parents):
43+
parents[i] = replace(parent, target=target, seen=seen, **kwargs)
44+
45+
return clone_commit(commit, parent_commits=parents)
46+
47+
48+
@click.command()
49+
@click.option('-m', '--message', required=True)
50+
@click.argument('rev')
51+
def main(message, rev):
52+
repo = git.Repo()
53+
branch = repo.active_branch
54+
rev = repo.commit(rev)
55+
cur = repo.head.commit
56+
57+
print('old:', branch.commit)
58+
new = replace(cur, target=rev, message=message)
59+
branch.set_commit(new)
60+
print('new:', branch.commit)
61+
62+
63+
if __name__ == '__main__':
64+
main()

0 commit comments

Comments
 (0)