2 # amend HEAD commit to contain acab in its hash, it does so by repeatedly
3 # amending the commit with a new date.
12 parser = argparse.ArgumentParser()
13 parser.add_argument('--start', type=str, default='commit', help='now or commit')
14 parser.add_argument('--prefix', action='store_true')
15 parser.add_argument('--suffix', action='store_true')
16 parser.add_argument('-q', '--quiet', action='store_true')
17 args = parser.parse_args()
20 def amend_commit(start_timestamp):
23 cat_file = subprocess.run(['git', 'cat-file', 'commit', 'HEAD'], capture_output=True).stdout
24 cat_file_lines = cat_file.splitlines()
25 cat_file_lines[2] = cat_file_lines[2].replace(cat_file_lines[2].rsplit(b' ', 2)[1], b'$AUTHOR__$')
26 cat_file_lines[3] = cat_file_lines[3].replace(cat_file_lines[3].rsplit(b' ', 2)[1], b'$COMMITER$')
27 hashed_bytes_template = b'commit %s\0%s\n' % (
28 str(len(b'\n'.join(cat_file_lines)) + 1).encode(),
29 b'\n'.join(cat_file_lines),
31 authored_timestamp = start_timestamp
34 authored_timestamp -= 1
35 for committed_timestamp in range(start_timestamp, authored_timestamp, -1):
39 '%5d - %s - %s - [%s:%02d]'
42 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(authored_timestamp)),
43 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(committed_timestamp)),
44 int((time.time() - t0) // 60),
45 int((time.time() - t0) % 60),
50 hashed_bytes = hashed_bytes_template.replace(
51 b'$AUTHOR__$', str(authored_timestamp).encode()
52 ).replace(b'$COMMITER$', str(committed_timestamp).encode())
53 new_hash = hashlib.sha1(hashed_bytes).hexdigest()
54 if args.prefix and not new_hash.startswith('acab'):
56 if args.suffix and not new_hash.endswith('acab'):
58 if 'acab' not in new_hash:
60 base_env['GIT_COMMITTER_DATE'] = time.strftime(
61 '%Y-%m-%d %H:%M:%S', time.localtime(committed_timestamp)
70 '--date=%s' % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(authored_timestamp)),
78 if args.start == 'commit':
79 p = subprocess.run(['git', 'show', '--format=format:%at'], capture_output=True)
80 start_timestamp = int(p.stdout[: p.stdout.index(b'\n')])
81 elif args.start == 'now':
82 start_timestamp = int(time.time())
84 sys.stderr('unknown value for --start')
87 amend_commit(start_timestamp)
90 p = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True)
91 print('\ngot %s 🔥🚓' % p.stdout.decode().strip())