3 from collections
import defaultdict
8 NOTES_INDEX
= '.git/git-notes-index'
10 'GIT_INDEX_FILE': NOTES_INDEX
,
12 NOTES_REF
= 'refs/heads/mailnotes'
14 def write_notes(commit_sha1
, notes
):
15 blob_sha1
= git('hash-object', '-w', '--stdin', input=notes
)[0]
16 git('update-index', '--add', '--cacheinfo', '0644', blob_sha1
, commit_sha1
, env
=notes_env
)
19 previous
, ret
= git('rev-parse', NOTES_REF
)
24 args
= ['-p', previous
.strip()]
25 previous_arg
= [previous
.strip()]
26 tree_sha1
= git('write-tree', env
=notes_env
)[0].strip()
27 head_sha1
= git('commit-tree', tree_sha1
, *args
,
28 input='Mass annotation by notes.py')[0].strip()
29 git('update-ref', '-m', 'Mass annotation by notes.py',
30 NOTES_REF
, head_sha1
, *previous_arg
)
32 def compute_notes(session
, commit
, mail
):
34 notes
.append('Mail-From: %s\n' % mail
.author
)
35 notes
.append('Posted-Date: %s\n'
36 % time
.strftime("%c", time
.localtime(mail
.post_date
)))
38 notes
.append('In-Reply-To: %s\n' % mail
.in_reply_to
)
40 notes
.append('References:\n')
41 for r
in mail
.references
:
42 notes
.append('\t%s\n' % r
.message_id
)
43 if len(mail
.patch
)>0 and mail
.patch
[0].extra_notes
:
44 notes
.append('Extra-notes:\n')
45 for line
in str(mail
.patch
[0].extra_notes
).splitlines():
46 notes
.append('\t%s\n' % line
)
50 session
= db
.Session()
52 notes
= defaultdict(list)
53 for cmt
, mail
in (session
.query(db
.Commit
, db
.Mail
)
54 .filter(db
.Commit
.upstream
==True)
55 .filter(db
.Mail
.has_patch
==True)
56 .filter(db
.Mail
.patch_id
==db
.Commit
.patch_id
)):
57 nts
= compute_notes(session
, cmt
, mail
)
61 notes
[cmt
].append('\n')
62 notes
[cmt
].extend(nts
)
63 sys
.stdout
.write('\r%6d' % count
)
67 sys
.stdout
.write('\n')
68 for cmt
, nts
in notes
.iteritems():
69 sys
.stdout
.write('\r%6d' % count
)
71 write_notes(cmt
.sha1
, ''.join(nts
))
73 sys
.stdout
.write('\n')
76 if __name__
== '__main__':
78 session
= db
.Session()
79 cmt
= session
.query(db
.Commit
).filter(db
.Commit
.sha1
==sys
.argv
[1]).one()
80 print compute_notes(session
, cmt
)