]> git.0d.be Git - git-acab.git/commitdiff
add initial version
authorFrédéric Péters <fpeters@0d.be>
Thu, 26 Aug 2021 06:17:50 +0000 (08:17 +0200)
committerFrédéric Péters <fpeters@0d.be>
Thu, 26 Aug 2021 06:33:32 +0000 (08:33 +0200)
git-acab [new file with mode: 0755]

diff --git a/git-acab b/git-acab
new file mode 100755 (executable)
index 0000000..159933b
--- /dev/null
+++ b/git-acab
@@ -0,0 +1,66 @@
+#! /usr/bin/python3
+# amend HEAD commit to contain acab in its hash, it does so by repeatedly
+# amending the commit with a new date.
+
+import argparse
+import subprocess
+import sys
+import time
+
+parser = argparse.ArgumentParser()
+parser.add_argument('--start', type=str, default='commit', help='now or commit')
+parser.add_argument('--prefix', action='store_true')
+parser.add_argument('-v', '--verbose', action='store_true')
+args = parser.parse_args()
+
+if args.start == 'commit':
+    p = subprocess.run(['git', 'show', '--format=format:%at'], capture_output=True)
+    timestamp = int(p.stdout[: p.stdout.index(b'\n')])
+elif args.start == 'now':
+    timestamp = int(time.time())
+else:
+    sys.stderr('unknown value for --start')
+    sys.exit(1)
+
+t0 = time.time()
+counter = 0
+direction = -1
+while True:
+    counter += 1
+    timestamp += direction
+    if counter % 3600 == 0:
+        # don't move more than one hour in the past, going back to initial time
+        # will give new commit hashes as the commit date (not author date) will
+        # be different.
+        direction = - direction
+    if args.verbose:
+        print(
+            '%5d - %s - [%s:%02d]'
+            % (
+                counter,
+                time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
+                int((time.time() - t0) // 60),
+                int((time.time() - t0) % 60),
+            ),
+            end='\r',
+        )
+    p = subprocess.run(
+        [
+            'git',
+            'commit',
+            '--no-verify',
+            '--amend',
+            '--no-edit',
+            '--date=%s' % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
+        ],
+        capture_output=True,
+    )
+    p = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True)
+    if args.prefix:
+        if b'acab' == p.stdout[:4]:
+            break
+    elif b'acab' in p.stdout:
+        break
+
+if args.verbose:
+    print('\ngot %s' % p.stdout.decode().strip())