+while not os.path.exists('.git'):
+ os.chdir('..')
+ if os.getcwd() == '/':
+ sys.stderr('failed to find a git repository')
+ sys.exit(1)
+
+
+def amend_commit(repo, initial_commit, start_timestamp):
+ t0 = time.time()
+ counter = 0
+ authored_timestamp = start_timestamp
+ while True:
+ authored_timestamp -= 1
+ for committed_timestamp in range(start_timestamp, authored_timestamp, -1):
+ counter += 1
+ if counter % 10000 == 0:
+ repo.git.prune()
+ if not args.quiet:
+ print(
+ '%5d - %s - %s - [%s:%02d]'
+ % (
+ counter,
+ time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(authored_timestamp)),
+ time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(committed_timestamp)),
+ int((time.time() - t0) // 60),
+ int((time.time() - t0) % 60),
+ ),
+ end='\r',
+ )
+
+ commit = initial_commit.replace(
+ authored_date=authored_timestamp, committed_date=committed_timestamp
+ )
+ if args.prefix and not commit.hexsha.startswith('acab'):
+ continue
+ if args.suffix and not commit.hexsha.endswith('acab'):
+ continue
+ if 'acab' not in commit.hexsha:
+ continue
+ repo.active_branch.set_commit(commit)
+ repo.git.prune()
+ return commit
+
+
+repo = git.Repo()
+commit = repo.commit('HEAD')
+