40 lines
1.4 KiB
Python
40 lines
1.4 KiB
Python
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
from method import Method, Argument
|
|
from method.vc import VcBlame
|
|
import re
|
|
|
|
class HgBlame(VcBlame):
|
|
"""Show buffer annotated with hg metadata"""
|
|
line_re = re.compile(r'^ *(?P<user>[^ ]+) (?P<rev>\d+) (?P<date>\d{4}-\d{2}-\d{2}): (?P<content>.*)\n$')
|
|
prefix_fmt = '[b:d:*]%(rev)-5s [c:d:*]%(user)-10s [b:d:*]%(date)10s[d:d:*]'
|
|
_is_method = True
|
|
def _open_pipe(self, w, **vargs):
|
|
cmd = ("hg", 'blame', '-nudq', w.buffer.path)
|
|
return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
|
|
|
class HgLog(Method):
|
|
"""Show hg log for this buffer"""
|
|
def _execute(self, w, **vargs):
|
|
w.set_error("unimplemented")
|
|
|
|
class HgDiff(Method):
|
|
"""Diff the current file with the version in Mercurial"""
|
|
def _execute(self, w, **vargs):
|
|
try:
|
|
from mercurial import hg, ui
|
|
from mercurial import commands as hgc
|
|
except ImportError:
|
|
w.set_error("Mecurial is not installed")
|
|
return
|
|
|
|
if not hasattr(w.buffer, 'path'):
|
|
w.set_error("Buffer has no corresponding file")
|
|
return
|
|
ui_imp = ui.ui(verbose=True)
|
|
ui_imp.pushbuffer()
|
|
repo = hg.repository(ui=ui_imp, path='.')
|
|
hgc.diff(ui_imp, repo, w.buffer.path)
|
|
s = ''.join(ui_imp.popbuffer())
|
|
w.application.data_buffer("*Diff*", s, switch_to=True, modename='diff')
|