Mercurial > hg-stable
changeset 24261:20aac24e2114
record: move header class from record to patch
Part of a series of patches to move record from hgext to core
author | Laurent Charignon <lcharignon@fb.com> |
---|---|
date | Mon, 09 Mar 2015 13:04:50 -0700 |
parents | 76225ab5a5da |
children | 7f24b2a0581a |
files | hgext/record.py mercurial/patch.py |
diffstat | 2 files changed, 59 insertions(+), 61 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/record.py Tue Mar 10 13:06:38 2015 -0700 +++ b/hgext/record.py Mon Mar 09 13:04:50 2015 -0700 @@ -69,66 +69,6 @@ else: yield 'other', line -class header(object): - """patch header - - XXX shouldn't we move this to mercurial/patch.py ? - """ - diffgit_re = re.compile('diff --git a/(.*) b/(.*)$') - diff_re = re.compile('diff -r .* (.*)$') - allhunks_re = re.compile('(?:index|deleted file) ') - pretty_re = re.compile('(?:new file|deleted file) ') - special_re = re.compile('(?:index|new|deleted|copy|rename) ') - - def __init__(self, header): - self.header = header - self.hunks = [] - - def binary(self): - return util.any(h.startswith('index ') for h in self.header) - - def pretty(self, fp): - for h in self.header: - if h.startswith('index '): - fp.write(_('this modifies a binary file (all or nothing)\n')) - break - if self.pretty_re.match(h): - fp.write(h) - if self.binary(): - fp.write(_('this is a binary file\n')) - break - if h.startswith('---'): - fp.write(_('%d hunks, %d lines changed\n') % - (len(self.hunks), - sum([max(h.added, h.removed) for h in self.hunks]))) - break - fp.write(h) - - def write(self, fp): - fp.write(''.join(self.header)) - - def allhunks(self): - return util.any(self.allhunks_re.match(h) for h in self.header) - - def files(self): - match = self.diffgit_re.match(self.header[0]) - if match: - fromfile, tofile = match.groups() - if fromfile == tofile: - return [fromfile] - return [fromfile, tofile] - else: - return self.diff_re.match(self.header[0]).groups() - - def filename(self): - return self.files()[-1] - - def __repr__(self): - return '<header %s>' % (' '.join(map(repr, self.files()))) - - def special(self): - return util.any(self.special_re.match(h) for h in self.header) - def countchanges(hunk): """hunk -> (n+,n-)""" add = len([h for h in hunk if h[0] == '+']) @@ -215,7 +155,7 @@ def newfile(self, hdr): self.addcontext([]) - h = header(hdr) + h = patch.header(hdr) self.headers.append(h) self.header = h
--- a/mercurial/patch.py Tue Mar 10 13:06:38 2015 -0700 +++ b/mercurial/patch.py Mon Mar 09 13:04:50 2015 -0700 @@ -804,6 +804,64 @@ self.write_rej() return len(self.rej) +class header(object): + """patch header + """ + diffgit_re = re.compile('diff --git a/(.*) b/(.*)$') + diff_re = re.compile('diff -r .* (.*)$') + allhunks_re = re.compile('(?:index|deleted file) ') + pretty_re = re.compile('(?:new file|deleted file) ') + special_re = re.compile('(?:index|new|deleted|copy|rename) ') + + def __init__(self, header): + self.header = header + self.hunks = [] + + def binary(self): + return util.any(h.startswith('index ') for h in self.header) + + def pretty(self, fp): + for h in self.header: + if h.startswith('index '): + fp.write(_('this modifies a binary file (all or nothing)\n')) + break + if self.pretty_re.match(h): + fp.write(h) + if self.binary(): + fp.write(_('this is a binary file\n')) + break + if h.startswith('---'): + fp.write(_('%d hunks, %d lines changed\n') % + (len(self.hunks), + sum([max(h.added, h.removed) for h in self.hunks]))) + break + fp.write(h) + + def write(self, fp): + fp.write(''.join(self.header)) + + def allhunks(self): + return util.any(self.allhunks_re.match(h) for h in self.header) + + def files(self): + match = self.diffgit_re.match(self.header[0]) + if match: + fromfile, tofile = match.groups() + if fromfile == tofile: + return [fromfile] + return [fromfile, tofile] + else: + return self.diff_re.match(self.header[0]).groups() + + def filename(self): + return self.files()[-1] + + def __repr__(self): + return '<header %s>' % (' '.join(map(repr, self.files()))) + + def special(self): + return util.any(self.special_re.match(h) for h in self.header) + class hunk(object): def __init__(self, desc, num, lr, context): self.number = num