Readable Git Annex Unused



So unless you know and use [git annex](https://git-annex.branchable.com/), this is not going to be very useful for you. Check it out, though. It's pretty cool. Unless you are on Windows. In that case it's hell. Anyway, I wrote a script to help me figure out the output of [git annex unused](http://manpages.ubuntu.com/manpages/wily/man1/git-annex-unused.1.html). In short, it tells you what those files used to be called before you lost them. Script:
#!/usr/local/bin/python3.5
import re, sys, os
from subprocess import Popen,PIPE
FNULL = open(os.devnull, 'w')

def seeker(s):
  process = Popen(["git", "log", "--stat", "-S", s], stderr=FNULL, stdout=PIPE)
  log = process.stdout.read().decode("utf-8")
  match = re.search(r"(([ -~]*\/)*[ -~]*)\|", log)
  if not match: return ''
  else: return match.group(1).strip()

if len(sys.argv)>1:
  print( seeker(sys.argv[1]) )
else:
  clist = []
  while True:
    crawl = input().strip()
    if not crawl: break
    crawl = crawl.split()
    clist.append(crawl)
  for x in clist:
    print('%s : %s' % ( x[0], seeker(x[1]) ) )
You can either call it with one argument which should be a key, or if you call it with no argument, it expects you to paste the list of results you got from git annex unused into stdin. It then goes through the list and tells you the corresponding filename for each key. This script is phenomenally stupid in that it does quite a terrible regular expression search on the output of git log and returns the first match it finds. Sue me, it works pretty well at my end.

Tags: - - -

Leave a Reply

Your email address will not be published. Required fields are marked *