/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/vcs/bzr.py

  • Committer: Tim Marston
  • Date: 2014-04-18 14:32:26 UTC
  • Revision ID: tim@ed.am-20140418143226-d3ih1aafs6mg9ndw
made revert require --all to act on all files

Show diffs side-by-side

added added

removed removed

Lines of Context:
99
99
                revision.
100
100
                """
101
101
 
 
102
                # bzr st
 
103
                output = self.run( [ 'bzr', 'status' ] )
 
104
                files = self.parse_file_blocks( output )
 
105
 
 
106
                # remove kind changed files (or they can cause `bzr revert` to break in
 
107
                # strange situations, like when a directory has been replaced with a
 
108
                # symlink to a non-existant file)
 
109
                if 'kind changed' in files:
 
110
                        for file in files[ 'kind changed' ]:
 
111
                                matches = re.match( r'(.+?)[/@+]? \([^)]+\)', file )
 
112
                                if not matches:
 
113
                                        raise RunTimeError(
 
114
                                                'failed to parse bzr kind change: %s' % file )
 
115
                                file = matches.group( 1 )
 
116
                                if the.verbose >= 2: print "removing (kind changed): " + file
 
117
                                full_file = os.path.join( self.dir, file )
 
118
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
 
119
                                        os.unlink( full_file )
 
120
                                elif os.path.isdir( full_file ):
 
121
                                        shutil.rmtree( full_file )
 
122
                                else:
 
123
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
 
124
 
102
125
                # bzr revert
103
126
                self.run( [ 'bzr', 'revert', '--no-backup' ] )
104
127
 
109
132
                # remove unknown files
110
133
                if 'unknown' in files:
111
134
                        for file in files[ 'unknown' ]:
 
135
                                if the.verbose >= 2: print "removing (unknown): " + file
112
136
                                full_file = os.path.join( self.dir, file )
113
137
                                if os.path.isfile( full_file ):
114
138
                                        os.unlink( full_file )
115
 
                                elif os.full_file.isdir( full_file ):
 
139
                                elif os.path.isdir( full_file ):
116
140
                                        shutil.rmtree( full_file )
117
141
                                else:
118
142
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
178
202
                for line in buf:
179
203
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
180
204
                        line = line.rstrip()
181
 
                        if the.verbose > 1: print '  %s' % line
 
205
                        if the.verbose >= 2: print '  %s' % line
182
206
 
183
207
                        # renames show before and after file names
184
208
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
200
224
                                continue
201
225
 
202
226
                        raise RuntimeError(
203
 
                                'failed to parse bzr update output line:\n%' % line )
 
227
                                'failed to parse bzr update output line:\n%s' % line )
204
228
 
205
229
                return files
206
230
 
230
254
 
231
255
 
232
256
        def run( self, cmd ):
233
 
                if the.verbose > 1: print 'exec: %s' % ' '.join( cmd )
 
257
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
234
258
                p = Popen( cmd, cwd = self.dir,
235
259
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
236
260
                output = p.communicate()[ 0 ]
255
279
                                                res[ current ] = list()
256
280
                                        res[ current ].append( matches.group( 1 ) )
257
281
                                        continue
258
 
                        if re.search( '^[0-9]+ shelf exists', line ): continue
 
282
                        if re.search( '^[0-9]+ shel(?:f|ves) exists?', line ): continue
259
283
                        if re.search( '^working tree is out of date', line ): continue
260
284
                        raise self.ParseError( "unrecognised line: %s" % line )
261
285
                return res