From 062cc1018d17c84d577c3415d6d0985c2fc5b0c5 Mon Sep 17 00:00:00 2001 From: moculus Date: Mon, 31 Mar 2008 16:14:37 +0000 Subject: [PATCH] cvs-blame2 works... fixes --HG-- branch : pmacs2 --- method/cvs.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++--- method/svn.py | 6 ++--- 2 files changed, 62 insertions(+), 6 deletions(-) diff --git a/method/cvs.py b/method/cvs.py index b660cbf..d611ee8 100644 --- a/method/cvs.py +++ b/method/cvs.py @@ -1,7 +1,7 @@ import os, commands, re, sets, tempfile from subprocess import Popen, PIPE, STDOUT -import buffer, default, dirutil, regex, util, window +import buffer, default, dirutil, lex, regex, util, window from point import Point from method import DATATYPES, Method, Argument, arg @@ -168,8 +168,6 @@ class CvsDiff3(Method): w.set_error("Could not parse revision2: %r" % rev) return - - cwd = os.getcwd() + os.path.sep path = w.buffer.path if path.startswith(cwd): @@ -184,6 +182,7 @@ class CvsDiff3(Method): else: w.application.data_buffer("*Diff*", data, switch_to=True, modename='diff') w.set_error("Differences were found") + class CvsBlame(Method): '''show blame output for the current version in SVN''' line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$') @@ -223,3 +222,60 @@ class CvsBlame(Method): w.application.data_buffer("*Blame*", data, switch_to=True, modename='blame') else: w.set_error("There was an error (%s)" % (status)) +class CvsBlame2(Method): + '''show blame output for the current version in SVN''' + line_re = re.compile('^([0-9.]+) +\(*([a-zA-Z0-9_]+) +([-0-9A-Za-z]+)\): (.*)$') + def _execute(self, w, **vargs): + if not hasattr(w.buffer, 'path'): + w.set_error("Buffer has no corresponding file") + return + + cwd = os.getcwd() + os.path.sep + path = w.buffer.path + if path.startswith(cwd): + path = path[len(cwd):] + + cmd = ("/usr/bin/cvs", 'annotate', path) + pipe = Popen(cmd, stdout=PIPE, stderr=PIPE) + + linetokens = [] + max_rev = 0 + max_user = 0 + for line in pipe.stdout: + m = self.line_re.match(line) + if not m: + raise Exception, line + (rev, user, date, content) = m.groups() + max_rev = max(max_rev, len(rev)) + max_user = max(max_user, len(user)) + linetokens.append([rev, user, date, content, []]) + status = pipe.wait() >> 8 + + lines = [x[3] for x in linetokens] + if w.mode.grammar: + lexer = lex.Lexer(w.mode, w.mode.grammar) + lextokens = [[] for l in lines] + for t in lexer.lex(lines): + linetokens[t.y][4].append(t) + + lines = [] + for linetoken in linetokens: + (rev, user, date, content, lextokens) = linetoken + prefix = '[b:d:*]%-8s [c:d:*]%-10s [b:d:*]%10s[d:d:*]' % (rev, user, date) + if lextokens: + suffixes = [] + for lt in lextokens: + s = lt.string.replace('\\', '\\\\') + s = s.replace('[', '\\[').replace(']', '\\]') + suffixes.append('[%s:%s:*]%s' % (lt.color[0], lt.color[1], s)) + suffix = ''.join(suffixes) + else: + suffix = content + '\n' + lines.append('%s %s' % (prefix, suffix)) + data = ''.join(lines) + + status = pipe.wait() >> 8 + if status == 0: + w.application.color_data_buffer("*Blame*", data, switch_to=True) + else: + w.set_error("There was an error (%s)" % (status)) diff --git a/method/svn.py b/method/svn.py index eaf60fa..873ff49 100644 --- a/method/svn.py +++ b/method/svn.py @@ -166,7 +166,7 @@ class SvnBlame(Method): return cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path) - pipe = Popen(cmd, stdin=PIPE, stdout=PIPE) + pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) lines = [] for line in pipe.stdout: @@ -192,7 +192,7 @@ class SvnBlame2(Method): return cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path) - pipe = Popen(cmd, stdin=PIPE, stdout=PIPE) + pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) linetokens = [] for line in pipe.stdout: @@ -222,7 +222,7 @@ class SvnBlame2(Method): suffixes.append('[%s:%s:*]%s' % (lt.color[0], lt.color[1], s)) suffix = ''.join(suffixes) else: - suffix = content + suffix = content + '\n' lines.append('%s %s' % (prefix, suffix)) data = ''.join(lines)