~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/patches.py

  • Committer: John Arbash Meinel
  • Date: 2008-11-25 17:15:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3851.
  • Revision ID: john@arbash-meinel.com-20081125171526-pi2g4m1w70pkie1f
Add a bit of help text when supplying --help.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#
14
14
# You should have received a copy of the GNU General Public License
15
15
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
18
 
19
19
class PatchSyntax(Exception):
92
92
    range = int(range)
93
93
    return (pos, range)
94
94
 
95
 
 
 
95
 
96
96
def hunk_from_header(line):
97
97
    import re
98
98
    matches = re.match(r'\@\@ ([^@]*) \@\@( (.*))?\n', line)
164
164
        return InsertLine(line[1:])
165
165
    elif line.startswith("-"):
166
166
        return RemoveLine(line[1:])
 
167
    elif line == NO_NL:
 
168
        return NO_NL
167
169
    else:
168
170
        raise MalformedLine("Unknown line type", line)
169
171
__pychecker__=""
266
268
        self.hunks = []
267
269
 
268
270
    def __str__(self):
269
 
        ret = self.get_header()
 
271
        ret = self.get_header() 
270
272
        ret += "".join([str(h) for h in self.hunks])
271
273
        return ret
272
274
 
273
275
    def get_header(self):
274
276
        return "--- %s\n+++ %s\n" % (self.oldname, self.newname)
275
277
 
276
 
    def stats_values(self):
277
 
        """Calculate the number of inserts and removes."""
 
278
    def stats_str(self):
 
279
        """Return a string of patch statistics"""
278
280
        removes = 0
279
281
        inserts = 0
280
282
        for hunk in self.hunks:
283
285
                     inserts+=1;
284
286
                elif isinstance(line, RemoveLine):
285
287
                     removes+=1;
286
 
        return (inserts, removes, len(self.hunks))
287
 
 
288
 
    def stats_str(self):
289
 
        """Return a string of patch statistics"""
290
288
        return "%i inserts, %i removes in %i hunks" % \
291
 
            self.stats_values()
 
289
            (inserts, removes, len(self.hunks))
292
290
 
293
291
    def pos_in_mod(self, position):
294
292
        newpos = position
298
296
                return None
299
297
            newpos += shift
300
298
        return newpos
301
 
 
 
299
            
302
300
    def iter_inserted(self):
303
301
        """Iteraties through inserted lines
304
 
 
 
302
        
305
303
        :return: Pair of line number, line
306
304
        :rtype: iterator of (int, InsertLine)
307
305
        """
316
314
 
317
315
 
318
316
def parse_patch(iter_lines):
319
 
    iter_lines = iter_lines_handle_nl(iter_lines)
320
317
    (orig_name, mod_name) = get_patch_names(iter_lines)
321
318
    patch = Patch(orig_name, mod_name)
322
319
    for hunk in iter_hunks(iter_lines):
369
366
 
370
367
 
371
368
def parse_patches(iter_lines):
 
369
    iter_lines = iter_lines_handle_nl(iter_lines)
372
370
    return [parse_patch(f.__iter__()) for f in iter_file_patch(iter_lines)]
373
371
 
374
372