/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-05 22:27:09 UTC
  • Revision ID: tim@ed.am-20140405222709-4mp50aiu184blnf1
fixed file_matcher

Show diffs side-by-side

added added

removed removed

34
34
 
35
35
                @param dir the fully-qualified directory to work in.
36
36
                """
37
 
 
38
37
                self.dir = dir
39
38
 
40
39
 
86
85
                """Obtain some sort of revision identifier
87
86
                """
88
87
 
89
 
                # bzr revno
 
88
                # bzr revert
90
89
                output = self.run( [ 'bzr', 'revno', '--tree' ] )
91
90
 
92
91
                # parse revno
100
99
                revision.
101
100
                """
102
101
 
103
 
                # bzr st
104
 
                output = self.run( [ 'bzr', 'status' ] )
105
 
                files = self.parse_file_blocks( output )
106
 
 
107
 
                # remove kind changed files (or they can cause `bzr revert` to break in
108
 
                # strange situations, like when a directory has been replaced with a
109
 
                # symlink to a non-existant file)
110
 
                if 'kind changed' in files:
111
 
                        for file in files[ 'kind changed' ]:
112
 
                                matches = re.search( '^(.+?)[/@+]? \([^)]+\)$', file )
113
 
                                if not matches:
114
 
                                        raise RunTimeError(
115
 
                                                'failed to parse bzr kind change: %s' % file )
116
 
                                file = matches.group( 1 )
117
 
                                if the.verbose >= 2: print "removing (kind changed): " + file
118
 
                                full_file = os.path.join( self.dir, file )
119
 
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
120
 
                                        os.unlink( full_file )
121
 
                                elif os.path.isdir( full_file ):
122
 
                                        shutil.rmtree( full_file )
123
 
                                else:
124
 
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
125
 
 
126
 
                # bzr revert
 
102
                # bzr revert (run twice to handle a bug in bzr where reverting a
 
103
                # directory from a symlink can cause conflicts during initial revert)
 
104
                self.run( [ 'bzr', 'revert', '--no-backup' ] )
127
105
                self.run( [ 'bzr', 'revert', '--no-backup' ] )
128
106
 
129
107
                # bzr st
133
111
                # remove unknown files
134
112
                if 'unknown' in files:
135
113
                        for file in files[ 'unknown' ]:
136
 
                                matches = re.search( r'^(.+?)[/@+]?$', file )
137
 
                                if not matches:
138
 
                                        raise RunTimeError(
139
 
                                                'failed to parse bzr unknowns: %s' % file )
140
 
                                file = matches.group( 1 )
141
 
                                if the.verbose >= 2: print "removing (unknown): " + file
 
114
                                if the.verbose > 1: print "removing unknown: " + file
142
115
                                full_file = os.path.join( self.dir, file )
143
 
                                if os.path.isfile( full_file ) or os.path.islink( full_file ):
 
116
                                if os.path.isfile( full_file ):
144
117
                                        os.unlink( full_file )
145
118
                                elif os.path.isdir( full_file ):
146
119
                                        shutil.rmtree( full_file )
147
120
                                else:
148
121
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
149
122
 
150
 
                # if a revision identifier has been given, ensure we're updated to that
151
 
                if revno is not None and self.get_revno() != revno:
 
123
                # if a revision identifyer has been given, update to that
 
124
                if revno is not None:
152
125
 
153
126
                        # bzr update
154
127
                        self.run( [ 'bzr', 'update', '-r', revno ] )
208
181
                for line in buf:
209
182
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
210
183
                        line = line.rstrip()
 
184
                        if the.verbose > 1: print '  %s' % line
211
185
 
212
186
                        # renames show before and after file names
213
187
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
229
203
                                continue
230
204
 
231
205
                        raise RuntimeError(
232
 
                                'failed to parse bzr update output line:\n%s' % line )
 
206
                                'failed to parse bzr update output line:\n%' % line )
233
207
 
234
208
                return files
235
209
 
258
232
                return files['conflicts'] if 'conflicts' in files else None
259
233
 
260
234
 
261
 
        def add( self, files ):
262
 
                """Make sure files are added to version control.
263
 
                @param files a list of relative filenames
264
 
                """
265
 
 
266
 
                # bzr add
267
 
                self.run( [ 'bzr', 'add', '-N' ] + files )
268
 
 
269
 
 
270
 
        def commit( self ):
271
 
                """Commit changes to the repo.
272
 
                """
273
 
 
274
 
                # bzr commit
275
 
                self.run( [ 'bzr', 'commit', '-m', '' ] )
276
 
 
277
 
 
278
235
        def run( self, cmd ):
279
 
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
 
236
                if the.verbose > 1: print 'exec: %s' % ' '.join( cmd )
280
237
                p = Popen( cmd, cwd = self.dir,
281
238
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
282
239
                output = p.communicate()[ 0 ]
283
240
                if p.returncode > 0:
284
241
                        raise self.VcsError( ' '.join( cmd[ : 2 ] ), output )
285
 
                if the.verbose >= 2:
286
 
                        print re.sub( '(^|\n)', '\\1  > ', output.rstrip() )
287
242
                return output
288
243
 
289
244
 
303
258
                                                res[ current ] = list()
304
259
                                        res[ current ].append( matches.group( 1 ) )
305
260
                                        continue
306
 
                        if re.search( '^[0-9]+ shel(?:f|ves) exists?', line ): continue
 
261
                        if re.search( '^[0-9]+ shelf exists', line ): continue
307
262
                        if re.search( '^working tree is out of date', line ): continue
308
263
                        raise self.ParseError( "unrecognised line: %s" % line )
309
264
                return res