/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:26:17 UTC
  • Revision ID: tim@ed.am-20140405222617-4nf4alk3u2dxe430
removed reference to copy-in conflicts (which no longer exist)

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
 
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.match( r'(.+?)[/@+]? \([^)]+\)', 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
 
                                if the.verbose >= 2: print "removing (unknown): " + file
 
114
                                if the.verbose > 1: print "removing unknown: " + file
137
115
                                full_file = os.path.join( self.dir, file )
138
116
                                if os.path.isfile( full_file ):
139
117
                                        os.unlink( full_file )
142
120
                                else:
143
121
                                        raise RuntimeError( 'exotic file in repo: %s' % file )
144
122
 
145
 
                # if a revision identifier has been given, ensure we're updated to that
146
 
                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:
147
125
 
148
126
                        # bzr update
149
127
                        self.run( [ 'bzr', 'update', '-r', revno ] )
203
181
                for line in buf:
204
182
                        if not re.search( '^[-R+ ?][K NMD!][* ] ', line ): continue
205
183
                        line = line.rstrip()
206
 
                        if the.verbose >= 2: print '  %s' % line
 
184
                        if the.verbose > 1: print '  %s' % line
207
185
 
208
186
                        # renames show before and after file names
209
187
                        matches = re.search( '^R.. (.*?)[/@+]? => (.*?)[/@+]?$', line )
225
203
                                continue
226
204
 
227
205
                        raise RuntimeError(
228
 
                                'failed to parse bzr update output line:\n%s' % line )
 
206
                                'failed to parse bzr update output line:\n%' % line )
229
207
 
230
208
                return files
231
209
 
254
232
                return files['conflicts'] if 'conflicts' in files else None
255
233
 
256
234
 
257
 
        def add( self, files ):
258
 
                """Make sure files are added to version control.
259
 
                @param files a list of relative filenames
260
 
                """
261
 
 
262
 
                # bzr add
263
 
                self.run( [ 'bzr', 'add', '-N' ] + files )
264
 
 
265
 
 
266
 
        def commit( self ):
267
 
                """Commit changes to the repo.
268
 
                """
269
 
 
270
 
                # bzr commit
271
 
                self.run( [ 'bzr', 'commit', '-m', '' ] )
272
 
 
273
 
 
274
235
        def run( self, cmd ):
275
 
                if the.verbose >= 2: print 'exec: %s' % ' '.join( cmd )
 
236
                if the.verbose > 1: print 'exec: %s' % ' '.join( cmd )
276
237
                p = Popen( cmd, cwd = self.dir,
277
238
                                   stdout = subprocess.PIPE, stderr = subprocess.STDOUT )
278
239
                output = p.communicate()[ 0 ]
297
258
                                                res[ current ] = list()
298
259
                                        res[ current ].append( matches.group( 1 ) )
299
260
                                        continue
300
 
                        if re.search( '^[0-9]+ shel(?:f|ves) exists?', line ): continue
 
261
                        if re.search( '^[0-9]+ shelf exists', line ): continue
301
262
                        if re.search( '^working tree is out of date', line ): continue
302
263
                        raise self.ParseError( "unrecognised line: %s" % line )
303
264
                return res