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,16 +1,15 @@
from method import Method, Argument
class HgCommit(Method):
"""Commit the current file """
w.set_error("unimplemented")
class HgBlame(Method):
"""Show buffer annotated with hg metadata"""
w.set_error("unimplemented")
# use hg blame -udq FILE
def _execute(self, w, **vargs):
w.set_error("unimplemented")
class HgLog(Method):
"""Show hg log for this buffer"""
w.set_error("unimplemented")
def _execute(self, w, **vargs):
w.set_error("unimplemented")
class HgDiff(Method):
"""Diff the current file with the version in Mercurial"""

View File

@ -3,6 +3,7 @@ from subprocess import Popen, PIPE, STDOUT
import buffer, default, dirutil, lex, regex, util, window
from point import Point
import buffer.color
from method import Method, Argument
@ -257,48 +258,89 @@ class SvnDiff3(Method):
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$')
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):
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, []])
pipe = self._open_pipe(w, **vargs)
groups = [self._filter(line) for line in pipe.stdout]
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)
lexer = lex.Lexer(w.mode, w.mode.grammar)
tokens = list(lexer.lex([d['content'] for d in groups]))
groups[t.y]['tokens'] = tokens
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)
data = ''
for d in groups:
if d['tokens']:
suffix = ''
for t in d['tokens']:
code = buffer.color.get_cbuf_code(t.color)
suffix += code + util.cbuf_escape(t.string)
else:
suffix = content + '\n'
lines.append('%s %s' % (prefix, suffix))
data = ''.join(lines)
suffix = d['content'] + '\n'
data += self.prefix_fmt % d + ' ' + suffix
if status == 0:
w.application.color_data_buffer("*Blame*", data, switch_to=True)
else:
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):
#path = os.path.realpath(path)