/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-09-09 19:13:33 UTC
  • Revision ID: tim@ed.am-20140909191333-0b7hrzonxce8mgy3
attempt to allow arguments before main command by treating the first thing that
doesn't look like an option as the command

Show diffs side-by-side

added added

removed removed

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