abstract class HgBase introduced; methods updated

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-05-14 19:48:40 -04:00
parent b504d677eb
commit 0fad7e130c
1 changed files with 37 additions and 12 deletions

View File

@ -10,7 +10,23 @@ try:
except ImportError: except ImportError:
has_hg = False has_hg = False
class HgBlame(VcBlame): class HgBase(object):
def _hg_check(self, w):
if not has_hg:
w.set_error("Mercurial is not installed")
return False
elif not hasattr(w.buffer, 'path'):
w.set_error("Buffer has no corresponding file")
return False
else:
return True
def _hg_init(self):
ui_imp = ui.ui(verbose=True)
ui_imp.pushbuffer()
repo = hg.repository(ui=ui_imp, path='.')
return ui_imp, repo
class HgBlame(VcBlame, HgBase):
"""Show buffer annotated with hg metadata""" """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$') 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:*]' prefix_fmt = '[b:d:*]%(rev)-5s [c:d:*]%(user)-10s [b:d:*]%(date)10s[d:d:*]'
@ -19,23 +35,32 @@ class HgBlame(VcBlame):
cmd = ("hg", 'blame', '-nudq', w.buffer.path) cmd = ("hg", 'blame', '-nudq', w.buffer.path)
return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
class HgLog(Method): class HgBlame2(Method, HgBase):
def _execute(self, w, **vargs):
if not self._hg_check(w):
return
ui_imp, repo = self._hg_init()
hgc.identify(ui_imp, repo, w.buffer.path)
hgc.annotate(ui_imp, repo, w.buffer.path, user=None, date=None, rev=None)
s = ''.join(ui_imp.popbuffer())
w.application.data_buffer('*Blame*', s, switch_to=True)
class HgLog(Method, HgBase):
"""Show hg log for this buffer""" """Show hg log for this buffer"""
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
w.set_error("unimplemented") if not self._hg_check(w):
return
ui_imp, repo = self._hg_init()
hgc.log(ui_imp, repo, user=None, rev=None, date=None)
s = ''.join(ui_imp.popbuffer())
w.application.data_buffer('*Log*', s, switch_to=True)
class HgDiff(Method): class HgDiff(Method, HgBase):
"""Diff the current file with the version in Mercurial""" """Diff the current file with the version in Mercurial"""
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
if not has_hg: if not self._hg_check(w):
w.set_error("Mercurial is not installed")
return return
elif not hasattr(w.buffer, 'path'): ui_imp, repo = self._hg_init()
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) hgc.diff(ui_imp, repo, w.buffer.path)
s = ''.join(ui_imp.popbuffer()) s = ''.join(ui_imp.popbuffer())
w.application.data_buffer("*Diff*", s, switch_to=True, modename='diff') w.application.data_buffer("*Diff*", s, switch_to=True, modename='diff')