/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/commit.py

  • Committer: John Arbash Meinel
  • Date: 2006-09-15 00:44:57 UTC
  • mfrom: (2009 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2050.
  • Revision ID: john@arbash-meinel.com-20060915004457-902cec0526a39337
[merge] bzr.dev 2009

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
 
62
62
# TODO: If commit fails, leave the message in a file somewhere.
63
63
 
 
64
# TODO: Change the parameter 'rev_id' to 'revision_id' to be consistent with
 
65
# the rest of the code; add a deprecation of the old name.
64
66
 
65
67
import os
66
68
import re
245
247
            self._check_bound_branch()
246
248
 
247
249
            # check for out of date working trees
248
 
            # if we are bound, then self.branch is the master branch and this
249
 
            # test is thus all we need.
250
 
            if self.work_tree.last_revision() != self.master_branch.last_revision():
 
250
            try:
 
251
                first_tree_parent = self.work_tree.get_parent_ids()[0]
 
252
            except IndexError:
 
253
                # if there are no parents, treat our parent as 'None'
 
254
                # this is so that we still consier the master branch
 
255
                # - in a checkout scenario the tree may have no
 
256
                # parents but the branch may do.
 
257
                first_tree_parent = None
 
258
            master_last = self.master_branch.last_revision()
 
259
            if (master_last is not None and
 
260
                master_last != first_tree_parent):
251
261
                raise errors.OutOfDateTree(self.work_tree)
252
262
    
253
263
            if strict:
279
289
            if len(self.parents) > 1 and self.specific_files:
280
290
                raise NotImplementedError('selected-file commit of merges is not supported yet: files %r',
281
291
                        self.specific_files)
282
 
            self._check_parents_present()
 
292
            
283
293
            self.builder = self.branch.get_commit_builder(self.parents, 
284
294
                self.config, timestamp, timezone, committer, revprops, rev_id)
285
295
            
287
297
            self._populate_new_inv()
288
298
            self._report_deletes()
289
299
 
290
 
            if not (self.allow_pointless
291
 
                    or len(self.parents) > 1
292
 
                    or self.builder.new_inventory != self.basis_inv):
293
 
                raise PointlessCommit()
 
300
            self._check_pointless()
294
301
 
295
302
            self._emit_progress_update()
296
303
            # TODO: Now the new inventory is known, check for conflicts and
317
324
            # and now do the commit locally.
318
325
            self.branch.append_revision(self.rev_id)
319
326
 
320
 
            self.work_tree.set_pending_merges([])
321
 
            self.work_tree.set_last_revision(self.rev_id)
 
327
            # if the builder gave us the revisiontree it created back, we
 
328
            # could use it straight away here.
 
329
            # TODO: implement this.
 
330
            self.work_tree.set_parent_trees([(self.rev_id,
 
331
                self.branch.repository.revision_tree(self.rev_id))])
322
332
            # now the work tree is up to date with the branch
323
333
            
324
334
            self.reporter.completed(self.branch.revno(), self.rev_id)
335
345
            self._cleanup()
336
346
        return self.rev_id
337
347
 
 
348
    def _check_pointless(self):
 
349
        if self.allow_pointless:
 
350
            return
 
351
        # A merge with no effect on files
 
352
        if len(self.parents) > 1:
 
353
            return
 
354
        # work around the fact that a newly-initted tree does differ from its
 
355
        # basis
 
356
        if len(self.builder.new_inventory) != len(self.basis_inv):
 
357
            return
 
358
        if (len(self.builder.new_inventory) != 1 and
 
359
            self.builder.new_inventory != self.basis_inv):
 
360
            return
 
361
        raise PointlessCommit()
 
362
 
338
363
    def _check_bound_branch(self):
339
364
        """Check to see if the local branch is bound.
340
365
 
438
463
        self.parent_invs = []
439
464
        for revision in self.parents:
440
465
            if self.branch.repository.has_revision(revision):
 
466
                mutter('commit parent revision {%s}', revision)
441
467
                inventory = self.branch.repository.get_inventory(revision)
442
468
                self.parent_invs.append(inventory)
 
469
            else:
 
470
                mutter('commit parent ghost revision {%s}', revision)
443
471
 
444
 
    def _check_parents_present(self):
445
 
        for parent_id in self.parents:
446
 
            mutter('commit parent revision {%s}', parent_id)
447
 
            if not self.branch.repository.has_revision(parent_id):
448
 
                if parent_id == self.branch.last_revision():
449
 
                    warning("parent is missing %r", parent_id)
450
 
                    raise BzrCheckError("branch %s is missing revision {%s}"
451
 
                            % (self.branch, parent_id))
452
 
            
453
472
    def _remove_deleted(self):
454
473
        """Remove deleted files from the working inventories.
455
474
 
463
482
        """
464
483
        specific = self.specific_files
465
484
        deleted_ids = []
 
485
        deleted_paths = set()
466
486
        for path, ie in self.work_inv.iter_entries():
 
487
            if is_inside_any(deleted_paths, path):
 
488
                # The tree will delete the required ids recursively.
 
489
                continue
467
490
            if specific and not is_inside_any(specific, path):
468
491
                continue
469
492
            if not self.work_tree.has_filename(path):
 
493
                deleted_paths.add(path)
470
494
                self.reporter.missing(path)
471
 
                deleted_ids.append((path, ie.file_id))
472
 
        if deleted_ids:
473
 
            deleted_ids.sort(reverse=True)
474
 
            for path, file_id in deleted_ids:
475
 
                del self.work_inv[file_id]
476
 
            self.work_tree._write_inventory(self.work_inv)
 
495
                deleted_ids.append(ie.file_id)
 
496
        self.work_tree.unversion(deleted_ids)
477
497
 
478
498
    def _populate_new_inv(self):
479
499
        """Build revision inventory.