git-email-contacts (1304B)
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 cc_cmd = $(git config sendmail.cccmd).strip() 10 cc_cmd = cc_cmd if cc_cmd != "" else "git-contacts" 11 12 user = f"{name} <{email}>" 13 fresh_file = os.path.join(dir, "contacts_fresh_hashes") 14 tmp_file = os.path.join(dir, "contacts_new_hashes") 15 contacts_tsv = os.path.join(dir, "contacts.tsv") 16 touch @(contacts_tsv) 17 18 sys.stderr.write(f"finding new patches for {user}\n") 19 20 def get_hashes(): 21 cut -d "\t" --output-delimiter="\t" -f1 @(contacts_tsv) > @(tmp_file) 22 23 git_args = sys.argv[1:] if len(sys.argv) > 1 else ["--all"] 24 25 git fetch 26 git log --no-merges @(git_args) --format=%H | head -n1050 | sort > @(fresh_file) 27 28 get_hashes() 29 new_hashes = $(grep -Fxvf @(tmp_file) @(fresh_file)).split("\n") 30 31 with open(contacts_tsv, "a") as contacts: 32 for hash in new_hashes: 33 if hash == "": 34 continue 35 emails = $(@(cc_cmd) @(hash)^-).split("\n") 36 emails = filter(lambda e: e != "", emails) 37 for email in emails: 38 if email == user: 39 sys.stderr.write(f"emailing {hash}^- to '{user}'\n") 40 git-send-email --suppress-cc=all --to=@(email) @(hash)^- 41 line = "{}\t{}\n".format(hash, email) 42 contacts.write(line) 43 44 rm -f @(fresh_file) @(tmp_file)