Merge lp:~toshio/bzr-gtk/handle-patch-dirty into lp:bzr-gtk/gtk2

Proposed by Toshio Kuratomi
Status: Merged
Merged at revision: 693
Proposed branch: lp:~toshio/bzr-gtk/handle-patch-dirty
Merge into: lp:bzr-gtk/gtk2
Diff against target: 50 lines (+10/-3)
2 files modified
bzr-handle-patch (+1/-1)
diff.py (+9/-2)
To merge this branch: bzr merge lp:~toshio/bzr-gtk/handle-patch-dirty
Reviewer Review Type Date Requested Status
Bazaar GTK maintainers Pending
Review via email: mp+23330@code.launchpad.net

Description of the change

This fixes bzr-handle-patch to not traceback with patches that have leading and trailing comments if a newer bzr (2.2b1 is the first release to support this) is installed. If an older bzr is installed, the code falls back on the old behaviour that handles clean patches but fails on "dirty" ones.

Note: Detection of recent enough bzr uses inspect.getargspec() rather than checking against bzrlib.version_info since
* it seems more pythonic to detect that bzrlib has the necessary parameter than to hardcode versions
* since the change only appears in bzr-2.2b1; downstream distributors are likely to backport the fix. If they do that, a bzrlib.version_info check in bzr-gtk would need to be patched out as well as it would no longer represent the capabilities of that bzrlib.

If you don't like getargspec(), we can substitute::

  if bzrlib.version_info[:2] >= (2, 2, 0, 'b', 1):

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzr-handle-patch'
2--- bzr-handle-patch 2009-11-13 19:07:28 +0000
3+++ bzr-handle-patch 2010-04-13 15:23:16 +0000
4@@ -25,7 +25,7 @@
5 try:
6 directive = merge_directive.MergeDirective.from_lines(lines)
7 except errors.NotAMergeDirective:
8- controller = DiffController(path, lines)
9+ controller = DiffController(path, lines, allow_dirty=True)
10 else:
11 controller = MergeDirectiveController(path, directive)
12 window = controller.window
13
14=== modified file 'diff.py'
15--- diff.py 2010-02-24 07:47:17 +0000
16+++ diff.py 2010-04-13 15:23:16 +0000
17@@ -17,6 +17,7 @@
18 import os
19 import re
20 import sys
21+import inspect
22 try:
23 from xml.etree.ElementTree import Element, SubElement, tostring
24 except ImportError:
25@@ -524,9 +525,10 @@
26
27 class DiffController(object):
28
29- def __init__(self, path, patch, window=None):
30+ def __init__(self, path, patch, window=None, allow_dirty=False):
31 self.path = path
32 self.patch = patch
33+ self.allow_dirty = allow_dirty
34 if window is None:
35 window = DiffWindow(operations=self._provide_operations())
36 self.initialize_window(window)
37@@ -538,7 +540,12 @@
38
39 def get_diff_sections(self):
40 yield "Complete Diff", None, ''.join(self.patch)
41- for patch in parse_patches(self.patch):
42+ # allow_dirty was added to parse_patches in bzrlib 2.2b1
43+ if 'allow_dirty' in inspect.getargspec(parse_patches).args:
44+ patches = parse_patches(self.patch, allow_dirty=self.allow_dirty)
45+ else:
46+ patches = parse_patches(self.patch)
47+ for patch in patches:
48 oldname = patch.oldname.split('\t')[0]
49 newname = patch.newname.split('\t')[0]
50 yield oldname, newname, str(patch)

Subscribers

People subscribed via source and target branches

to all changes:
to status/vote changes: