From acab0a73706e12abdeee7d94301a80449dce6422 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Thu, 26 Aug 2021 08:17:50 +0200 Subject: [PATCH] add initial version --- git-acab | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100755 git-acab diff --git a/git-acab b/git-acab new file mode 100755 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()) -- 2.39.2