~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2005-11-28 18:32:14 UTC
  • mto: (0.3.1 shelf-dev) (325.1.2 bzrtools)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20051128183214-abade6823cc5ff40
Add support for 'unshelve --pick'. This works but the UI is broken, as the
hunk selector prompts are all still related to shelving, not unshelving.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
            return None
57
57
        return shelf[len(prefix):shelf.index('\n')]
58
58
 
59
 
    def unshelve(self):
 
59
    def unshelve(self, pick_hunks=False):
60
60
        shelf = self.last_shelf()
61
61
 
62
62
        if shelf is None:
63
63
            raise Exception("No shelf found in '%s'" % self.branch.base)
64
64
 
65
 
        patch = open(shelf, 'r').read()
 
65
        patches = parse_patches(open(shelf, 'r').readlines())
 
66
        if pick_hunks:
 
67
            try:
 
68
                patches = HunkSelector(patches).select()
 
69
            except QuitException:
 
70
                return False
 
71
 
 
72
        if len(patches) == 0:
 
73
            print >>sys.stderr, 'Nothing to unshelve'
 
74
            return True
66
75
 
67
76
        print >>sys.stderr, "Reapplying shelved patches",
68
 
        message = self.get_shelf_message(patch)
 
77
        message = self.get_shelf_message(open(shelf, 'r').read())
69
78
        if message is not None:
70
79
            print >>sys.stderr, ' "%s"' % message
71
80
        else:
72
81
            print >>sys.stderr, ""
73
82
        pipe = os.popen('patch -d %s -s -p0' % self.branch.base, 'w')
74
 
        pipe.write(patch)
 
83
        for patch in patches:
 
84
            pipe.write(str(patch))
75
85
        pipe.flush()
76
86
 
77
87
        if pipe.close() is not None: