git-email-contacts

email yourself patches from git-contacts
git clone git://jb55.com/git-email-contacts
Log | Files | Refs | README | LICENSE

git-email-contacts (1112B)


      1 #!/usr/bin/env xonsh
      2 
      3 import sys
      4 import os
      5 
      6 dir = $(git rev-parse --show-toplevel).strip()
      7 name = $(git config user.name).strip()
      8 email = $(git config user.email).strip()
      9 user = f"{name} <{email}>"
     10 fresh_file  = os.path.join(dir, "contacts_fresh_hashes")
     11 tmp_file  = os.path.join(dir, "contacts_new_hashes")
     12 contacts_tsv = os.path.join(dir, "contacts.tsv")
     13 touch @(contacts_tsv)
     14 
     15 sys.stderr.write(f"finding new patches for {user}\n")
     16 
     17 def get_hashes():
     18 	cut -d "\t" --output-delimiter="\t" -f1 @(contacts_tsv) > @(tmp_file)
     19 
     20 git fetch
     21 git log --no-merges --all --format=%H | head -n1050 | sort > @(fresh_file)
     22 
     23 get_hashes()
     24 new_hashes = $(grep -Fxvf @(tmp_file) @(fresh_file)).split("\n")
     25 
     26 with open(contacts_tsv, "a") as contacts:
     27 	for hash in new_hashes:
     28 		emails = $(git-contacts @(hash)^-).split("\n")
     29 		emails = filter(lambda e: e != "", emails)
     30 		for email in emails:
     31 			if email == user:
     32 				sys.stderr.write(f"emailing {hash}^- to '{user}'\n")
     33 				git-send-email --suppress-cc=all --to=@(email) @(hash)^- 
     34 			line = "{}\t{}\n".format(hash, email)
     35 			contacts.write(line)
     36 
     37 rm -f @(fresh_file) @(tmp_file)