Skip to content

Bug 1411943 - Fix Blame for Mercurial 4.3+ #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 23 additions & 19 deletions tools/migrate/blame.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import argparse
import os
import json
import hglib
from hglib.util import b, cmdbuilder
Expand All @@ -13,39 +12,44 @@ def __init__(self, repopath):
self.blame = {}

def main(self):
for manifestline in self.client.manifest():
leaf = manifestline[-1]
self.handleFile(leaf)
args = cmdbuilder(
b('annotate'), self.client.root(), d=True, u=True, T='json')
blame_json = ''.join(self.client.rawcommand(args))
file_blames = json.loads(blame_json)

for file_blame in file_blames:
self.handleFile(file_blame)

return {'authors': self.users,
'blame': self.blame}

def handleFile(self, leaf):
def handleFile(self, file_blame):
abspath = file_blame['abspath']

try:
parser = getParser(leaf)
parser = getParser(abspath)
except UserWarning:
return
args = cmdbuilder(b('annotate'), d=True, u=True, T='json',
*['path:' + leaf])
blame_json = ''.join(self.client.rawcommand(args))
blames = json.loads(blame_json)
fname = os.path.join(self.client.root(), leaf)
parser.readFile(fname)

self.blame[abspath] = {}

parser.readFile(file_blame['path'])
entities, emap = parser.parse()
self.blame[leaf] = {}
for e in entities:
if isinstance(e, Junk):
continue
blines = blames[
entity_lines = file_blame['lines'][
(e.value_position()[0] - 1):e.value_position(-1)[0]
]
blines.sort(key=lambda blame: -blame['date'][0]) # ignore timezone
blame = blines[0]
user = blame['user']
timestamp = blame['date'][0] # ignore timezone
# ignore timezone
entity_lines.sort(key=lambda blame: -blame['date'][0])
line_blame = entity_lines[0]
user = line_blame['user']
timestamp = line_blame['date'][0] # ignore timezone
if user not in self.users:
self.users.append(user)
userid = self.users.index(user)
self.blame[leaf][e.key] = [userid, timestamp]
self.blame[abspath][e.key] = [userid, timestamp]

if __name__ == '__main__':
parser = argparse.ArgumentParser()
Expand Down