Mercurial > hg
comparison hgext/record.py @ 13294:98f0adfc89e3
record: simplify header methods with util.any
author | Patrick Mezard <pmezard@gmail.com> |
---|---|
date | Sun, 23 Jan 2011 15:21:56 +0100 |
parents | ad1b46e4a575 |
children | fb446228c0d4 |
comparison
equal
deleted
inserted
replaced
13293:ad1b46e4a575 | 13294:98f0adfc89e3 |
---|---|
79 def __init__(self, header): | 79 def __init__(self, header): |
80 self.header = header | 80 self.header = header |
81 self.hunks = [] | 81 self.hunks = [] |
82 | 82 |
83 def binary(self): | 83 def binary(self): |
84 for h in self.header: | 84 return util.any(h.startswith('index ') for h in self.header) |
85 if h.startswith('index '): | |
86 return True | |
87 | 85 |
88 def pretty(self, fp): | 86 def pretty(self, fp): |
89 for h in self.header: | 87 for h in self.header: |
90 if h.startswith('index '): | 88 if h.startswith('index '): |
91 fp.write(_('this modifies a binary file (all or nothing)\n')) | 89 fp.write(_('this modifies a binary file (all or nothing)\n')) |
104 | 102 |
105 def write(self, fp): | 103 def write(self, fp): |
106 fp.write(''.join(self.header)) | 104 fp.write(''.join(self.header)) |
107 | 105 |
108 def allhunks(self): | 106 def allhunks(self): |
109 for h in self.header: | 107 return util.any(self.allhunks_re.match(h) for h in self.header) |
110 if self.allhunks_re.match(h): | |
111 return True | |
112 | 108 |
113 def files(self): | 109 def files(self): |
114 match = self.diffgit_re.match(self.header[0]) | 110 match = self.diffgit_re.match(self.header[0]) |
115 if match: | 111 if match: |
116 fromfile, tofile = match.groups() | 112 fromfile, tofile = match.groups() |
125 | 121 |
126 def __repr__(self): | 122 def __repr__(self): |
127 return '<header %s>' % (' '.join(map(repr, self.files()))) | 123 return '<header %s>' % (' '.join(map(repr, self.files()))) |
128 | 124 |
129 def special(self): | 125 def special(self): |
130 for h in self.header: | 126 return util.any(self.special_re.match(h) for h in self.header) |
131 if self.special_re.match(h): | |
132 return True | |
133 | 127 |
134 def countchanges(hunk): | 128 def countchanges(hunk): |
135 """hunk -> (n+,n-)""" | 129 """hunk -> (n+,n-)""" |
136 add = len([h for h in hunk if h[0] == '+']) | 130 add = len([h for h in hunk if h[0] == '+']) |
137 rem = len([h for h in hunk if h[0] == '-']) | 131 rem = len([h for h in hunk if h[0] == '-']) |