/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-04 22:35:04 UTC
  • Revision ID: tim@ed.am-20140404223504-z91mtjgeljckqyg8
updated comment

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
 
 
125
102
                # bzr revert
126
103
                self.run( [ 'bzr', 'revert', '--no-backup' ] )
127
104
 
132
109
                # remove unknown files
133
110
                if 'unknown' in files:
134
111
                        for file in files[ 'unknown' ]:
135
 
                                if the.verbose >= 2: print "removing (unknown): " + file
136
112
                                full_file = os.path.join( self.dir, file )
137
113
                                if os.path.isfile( full_file ):
138
114
                                        os.unlink( full_file )
139
 
                                elif os.path.isdir( full_file ):
 
115
                                elif os.full_file.isdir( full_file ):
140
116
                                        shutil.rmtree( full_file )
141
117
                                else:
142
118
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
202
178
                for line in buf:
203
179
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
204
180
                        line = line.rstrip()
205
 
                        if the.verbose >= 2: print '  %s' % line
 
181
                        if the.verbose > 1: print '  %s' % line
206
182
 
207
183
                        # renames show before and after file names
208
184
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
224
200
                                continue
225
201
 
226
202
                        raise RuntimeError(
227
 
                                'failed to parse bzr update output line:\n%s' % line )
 
203
                                'failed to parse bzr update output line:\n%' % line )
228
204
 
229
205
                return files
230
206
 
254
230
 
255
231
 
256
232
        def run( self, cmd ):
257
 
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
 
233
                if the.verbose > 1: print 'exec: %s' % ' '.join( cmd )
258
234
                p = Popen( cmd, cwd = self.dir,
259
235
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
260
236
                output = p.communicate()[ 0 ]
279
255
                                                res[ current ] = list()
280
256
                                        res[ current ].append( matches.group( 1 ) )
281
257
                                        continue
282
 
                        if re.search( '^[0-9]+ shel(?:f|ves) exists?', line ): continue
 
258
                        if re.search( '^[0-9]+ shelf exists', line ): continue
283
259
                        if re.search( '^working tree is out of date', line ): continue
284
260
                        raise self.ParseError( "unrecognised line: %s" % line )
285
261
                return res