diff --git a/method/cvs.py b/method/cvs.py index e360e82..123d899 100644 --- a/method/cvs.py +++ b/method/cvs.py @@ -5,6 +5,7 @@ import buffer, default, dirutil, lex, regex, util, window from point import Point from method import Method, Argument, arg +from method.vc import VcBlame, VcRevView, VcDateView class CvsCommit(Method): '''diff the current file with the version in CVS''' @@ -273,48 +274,27 @@ class CvsBlame(Method): w.set_error("There was an error (%s)" % (status)) class CvsBlame2(CvsBlame): - '''show blame output for the current version in CVS''' + '''show blame output for the given version in CVS''' args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$') def _get_cmd(self, w, **vargs): path = self._get_path(w, **vargs) return ("/usr/bin/cvs", 'annotate', '-r', vargs['revision'], path) -class CvsRevView(Method): +class CvsRevView(VcRevView): '''show blame output for the current version in CVS''' - args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] - def _get_path(self, w, **vargs): - cwd = os.getcwd() + os.path.sep - path = w.buffer.path - if path.startswith(cwd): - path = path[len(cwd):] - return path - + args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] + namebase = 'CVS' + _is_method = True def _get_cmd(self, w, **vargs): path = self._get_path(w, **vargs) return ("/usr/bin/cvs", 'up', '-p', '-r', vargs['revision'], path) - def _get_name(self, w, **vargs): - return '*CVS:%s-%s' % (w.buffer.name(), vargs['revision']) - - def _execute(self, w, **vargs): - if not hasattr(w.buffer, 'path'): - w.set_error("Buffer has no corresponding file") - return - - cmd = self._get_cmd(w, **vargs) - name = self._get_name(w, **vargs) - mname = w.mode.name.lower() - status, out, err = util.communicate(cmd) - - w.application.data_buffer(name, out, switch_to=True, modename=mname) - -class CvsDateView(CvsRevView): +class CvsDateView(VcDateView): '''show blame output for the current version in CVS''' - args = [arg("date", t=type(""), p="Date: ", h="date specifier")] + args = [arg("date", t=type(""), p="Date: ", h="date specifier")] + namebase = 'CVS' + _is_method = True def _get_cmd(self, w, **vargs): path = self._get_path(w, **vargs) return ("/usr/bin/cvs", 'up', '-p', '-D', vargs['date'], path) - - def _get_name(self, w, **vargs): - return '*CVS:%s-%s' % (w.buffer.name(), vargs['date']) diff --git a/method/svn.py b/method/svn.py index b2ec8f5..da10943 100644 --- a/method/svn.py +++ b/method/svn.py @@ -4,9 +4,9 @@ from subprocess import Popen, PIPE, STDOUT import buffer, default, dirutil, lex, regex, util, window from point import Point import buffer.colors -from method.vc import VcBlame +from method.vc import VcBlame, VcRevView -from method import Method, Argument +from method import Method, Argument, arg if os.system('which svn >/dev/null 2>/dev/null') == 0: has_svn = True @@ -275,3 +275,19 @@ class SvnBlame(VcBlame): def _open_pipe(self, w, **vargs): cmd = ("svn", 'blame', '-v', w.buffer.path) return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) + +class SvnBlame2(SvnBlame): + '''show file contents in SVN at revision''' + args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] + def _open_pipe(self, w, **vargs): + cmd = ("svn", 'blame', '-v', '-r', vargs['revision'], w.buffer.path) + return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) + +class SvnRevView(VcRevView): + '''show file contents in SVN at date''' + args = [arg("revision", t=type(""), p="Revision: ", h="revision number")] + namebase = 'SVN' + _is_method = True + def _get_cmd(self, w, **vargs): + path = self._get_path(w, **vargs) + return ("svn", 'cat', '-r', vargs['revision'], path) diff --git a/method/vc.py b/method/vc.py index c2ca06a..b6482b5 100644 --- a/method/vc.py +++ b/method/vc.py @@ -1,3 +1,4 @@ +import os from method import Method import buffer.colors import util @@ -68,3 +69,39 @@ class VcBlame(Method): data = ''.join(self._build_lines(groups, gsizes, w, **vargs)) w.application.color_data_buffer("*Blame*", data, switch_to=True) + +class VcRevView(Method): + '''show file contents at revision''' + _is_method = False + namebase = 'VC' + def _get_path(self, w, **vargs): + cwd = os.getcwd() + os.path.sep + path = w.buffer.path + if path.startswith(cwd): + path = path[len(cwd):] + return path + + def _get_cmd(self, w, **vargs): + path = self._get_path(w, **vargs) + raise Exception("unimplemented") + + def _get_name(self, w, **vargs): + return '*%s:%s-%s' % (self.namebase, w.buffer.name(), vargs['revision']) + + def _execute(self, w, **vargs): + if not hasattr(w.buffer, 'path'): + w.set_error("Buffer has no corresponding file") + return + + cmd = self._get_cmd(w, **vargs) + name = self._get_name(w, **vargs) + mname = w.mode.name.lower() + status, out, err = util.communicate(cmd) + + w.application.data_buffer(name, out, switch_to=True, modename=mname) + +class VcDateView(VcRevView): + '''show file contents at date''' + args = [arg("date", t=type(""), p="Date: ", h="date specifier")] + def _get_name(self, w, **vargs): + return '*%s:%s-%s' % (self.namebase, w.buffer.name(), vargs['date']) diff --git a/mode/c.py b/mode/c.py index 92a99e4..fd767f7 100644 --- a/mode/c.py +++ b/mode/c.py @@ -213,7 +213,7 @@ class C(Fundamental): closetokens = ('delimiter',) closetags = {')': '(', ']': '[', '}': '{'} actions = [CCheckSyntax, CMake] - format = "%(flag)s %(bname)s (%(mname)s) %(indent)s %(cursor)s %(perc)s [%(func)s]" + format = "%(flag)s %(bname)s (%(mname)s) %(indent)s %(cursor)s %(perc)s [%(func)s] %(vc-info)s" commentc = '//' colors = {