fix issues with the last commit

--HG--
branch : pmacs2
This commit is contained in:
Erik Osheim 2009-05-09 22:57:05 -04:00
parent e1296dcbae
commit c05127348e
3 changed files with 85 additions and 37 deletions

View File

@ -1,15 +1,14 @@
from method import Method, Argument from method import Method, Argument
class HgCommit(Method):
"""Commit the current file """
w.set_error("unimplemented")
class HgBlame(Method): class HgBlame(Method):
"""Show buffer annotated with hg metadata""" """Show buffer annotated with hg metadata"""
# use hg blame -udq FILE
def _execute(self, w, **vargs):
w.set_error("unimplemented") w.set_error("unimplemented")
class HgLog(Method): class HgLog(Method):
"""Show hg log for this buffer""" """Show hg log for this buffer"""
def _execute(self, w, **vargs):
w.set_error("unimplemented") w.set_error("unimplemented")
class HgDiff(Method): class HgDiff(Method):

View File

@ -3,6 +3,7 @@ from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, lex, regex, util, window import buffer, default, dirutil, lex, regex, util, window
from point import Point from point import Point
import buffer.color
from method import Method, Argument from method import Method, Argument
@ -257,48 +258,89 @@ class SvnDiff3(Method):
class SvnBlame(Method): class SvnBlame(Method):
'''show blame output for the current version in SVN''' '''show blame output for the current version in SVN'''
line_re = re.compile('^ *(\d+) *([a-zA-Z0-9_]+) *([-0-9]+) *([:0-9]+) *(-\d{4}) *\(([^\)]+)\) (.*)\n$') line_re = re.compile('^ *(?P<rev>\d+) *(?P<user>[a-zA-Z0-9_]+) *(?P<date>[-0-9]+) *(?P<time>[:0-9]+) *(?P<tz>-\d{4}) *\((?P<vdate>[^\)]+)\) (?P<content>.*)\n$')
prefix_fmt = '[b:d:*]%-4(rev)s [c:d:*]%-10(user)s [b:d:*]%10(date)s[d:d:*]'
def _filter(self, line):
m = self.line_re.match(line)
if not m:
raise SvnException("couldn't parse %r" % line)
return m.groupdict()
def _open_pipe(self, w, **vargs):
cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path)
return Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
def _execute(self, w, **vargs): def _execute(self, w, **vargs):
if not hasattr(w.buffer, 'path'): if not hasattr(w.buffer, 'path'):
w.set_error("Buffer has no corresponding file") w.set_error("Buffer has no corresponding file")
return return
cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path) pipe = self._open_pipe(w, **vargs)
pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE) groups = [self._filter(line) for line in pipe.stdout]
linetokens = []
for line in pipe.stdout:
m = self.line_re.match(line)
if not m:
raise Exception, line
(rev, user, date, t, tz, vdate, content) = m.groups()
linetokens.append([rev, user, date, content, []])
status = pipe.wait() >> 8 status = pipe.wait() >> 8
lines = [x[3] for x in linetokens]
if w.mode.grammar: if w.mode.grammar:
lexer = lex.Lexer(w.mode, w.mode.grammar) lexer = lex.Lexer(w.mode, w.mode.grammar)
lextokens = [[] for l in lines] tokens = list(lexer.lex([d['content'] for d in groups]))
for t in lexer.lex(lines): groups[t.y]['tokens'] = tokens
linetokens[t.y][4].append(t)
lines = [] data = ''
for linetoken in linetokens: for d in groups:
(rev, user, date, content, lextokens) = linetoken if d['tokens']:
prefix = '[b:d:*]%-4s [c:d:*]%-10s [b:d:*]%10s[d:d:*]' % (rev, user, date) suffix = ''
if lextokens: for t in d['tokens']:
suffixes = [] code = buffer.color.get_cbuf_code(t.color)
for lt in lextokens: suffix += code + util.cbuf_escape(t.string)
s = lt.string.replace('\\', '\\\\')
s = s.replace('[', '\\[').replace(']', '\\]')
suffixes.append('[%s:%s:*]%s' % (lt.color[0], lt.color[1], s))
suffix = ''.join(suffixes)
else: else:
suffix = content + '\n' suffix = d['content'] + '\n'
lines.append('%s %s' % (prefix, suffix)) data += self.prefix_fmt % d + ' ' + suffix
data = ''.join(lines)
if status == 0: if status == 0:
w.application.color_data_buffer("*Blame*", data, switch_to=True) w.application.color_data_buffer("*Blame*", data, switch_to=True)
else: else:
w.set_error("There was an error (%s)" % (status)) w.set_error("There was an error (%s)" % (status))
#class SvnBlame(Method):
# '''show blame output for the current version in SVN'''
# line_re = re.compile('^ *(\d+) *([a-zA-Z0-9_]+) *([-0-9]+) *([:0-9]+) *(-\d{4}) *\(([^\)]+)\) (.*)\n$')
# def _execute(self, w, **vargs):
# if not hasattr(w.buffer, 'path'):
# w.set_error("Buffer has no corresponding file")
# return
#
# cmd = ("/usr/bin/svn", 'blame', '-v', w.buffer.path)
# pipe = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=PIPE)
#
# linetokens = []
# for line in pipe.stdout:
# m = self.line_re.match(line)
# if not m:
# raise Exception, line
# (rev, user, date, t, tz, vdate, content) = m.groups()
# 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:*]%-4s [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)
#
# if status == 0:
# w.application.color_data_buffer("*Blame*", data, switch_to=True)
# else:
# w.set_error("There was an error (%s)" % (status))

View File

@ -1,4 +1,11 @@
import os, pwd, regex import os
import pwd
import re
import regex
cbuf_re = re.compile(r'[\[\]\\]')
def cbuf_escape(s):
return cbuf_re.sub(lambda m: '\\' + m.group(0), s)
def normal_path(path): def normal_path(path):
#path = os.path.realpath(path) #path = os.path.realpath(path)