~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Aaron Bentley
  • Date: 2005-11-08 17:24:19 UTC
  • Revision ID: aaron.bentley@utoronto.ca-20051108172419-80f4f57367e40dab
Added CREDITS

Show diffs side-by-side

added added

removed removed

Lines of Context:
11
11
from bzrlib import DEFAULT_IGNORE
12
12
from hunk_selector import HunkSelector
13
13
from diffstat import DiffStat
14
 
from subprocess import Popen, PIPE
15
14
 
16
15
DEFAULT_IGNORE.append('./.bzr-shelf*')
17
16
 
76
75
            print >>sys.stderr, ' "%s"' % message
77
76
        else:
78
77
            print >>sys.stderr, ""
79
 
        run_patch(self.branch.base, (patch,))
 
78
        pipe = os.popen('patch -d %s -s -p0' % self.branch.base, 'w')
 
79
        pipe.write(patch)
 
80
        pipe.flush()
 
81
 
 
82
        if pipe.close() is not None:
 
83
            raise Exception("Failed running patch!")
 
84
 
80
85
        os.remove(shelf)
81
86
 
82
87
        diff_stat = DiffStat(self.get_patches(None, None))
83
88
        print 'Diff status is now:\n', diff_stat
84
89
 
85
 
        return 1
 
90
        return True
86
91
 
87
92
    def get_patches(self, revision, file_list):
88
93
        from StringIO import StringIO
104
109
 
105
110
        if len(patches) == 0:
106
111
            print >>sys.stderr, 'Nothing to shelve'
107
 
            return 0
 
112
            return True
108
113
 
109
114
        shelf = self.next_shelf()
110
115
        print >>sys.stderr, "Saving shelved patches to", shelf
120
125
        shelf.close()
121
126
 
122
127
        print >>sys.stderr, "Reverting shelved patches"
123
 
        run_patch(self.branch.base, patches, reverse=True)
 
128
        pipe = os.popen('patch -d %s -sR -p0' % self.branch.base, 'w')
 
129
        for patch in patches:
 
130
            pipe.write(str(patch))
 
131
        pipe.flush()
 
132
 
 
133
        if pipe.close() is not None:
 
134
            raise Exception("Failed running patch!")
124
135
 
125
136
        diff_stat = DiffStat(self.get_patches(None, None))
126
137
        print 'Diff status is now:\n', diff_stat
127
138
 
128
 
        return 1
 
139
        return True
129
140
 
130
 
def run_patch(branch_base, patches, reverse=False):
131
 
    args = ['patch', '-d', branch_base, '-s', '-p0', '-f']
132
 
    if reverse:
133
 
        args.append('-R')
134
 
    process = Popen(args, stdin=PIPE)
135
 
    for patch in patches:
136
 
        process.stdin.write(str(patch))
137
 
    process.stdin.close()
138
 
    result = process.wait()
139
 
    if result not in (0, 1):
140
 
        raise Exception("Error applying patches")
141
 
    return result