[Pkg-bazaar-commits] ./bzr/unstable r882: - Optionally raise EmptyCommit if there are no changes. Test for this.
Martin Pool
mbp at sourcefrog.net
Fri Apr 10 08:21:20 UTC 2009
------------------------------------------------------------
revno: 882
committer: Martin Pool <mbp at sourcefrog.net>
timestamp: Mon 2005-07-11 13:27:43 +1000
message:
- Optionally raise EmptyCommit if there are no changes. Test for this.
modified:
bzrlib/commit.py
bzrlib/errors.py
bzrlib/selftest/whitebox.py
-------------- next part --------------
=== modified file 'bzrlib/commit.py'
--- a/bzrlib/commit.py 2005-07-11 03:12:55 +0000
+++ b/bzrlib/commit.py 2005-07-11 03:27:43 +0000
@@ -24,7 +24,8 @@
committer=None,
verbose=True,
specific_files=None,
- rev_id=None):
+ rev_id=None,
+ allow_empty=True):
"""Commit working copy as a new revision.
The basic approach is to add all the file texts into the
@@ -41,6 +42,9 @@
be robust against files disappearing, moving, etc. So the
whole thing is a bit hard.
+ This raises EmptyCommit if there are no changes, no new merges,
+ and allow_empty is false.
+
timestamp -- if not None, seconds-since-epoch for a
postdated/predated commit.
@@ -59,7 +63,7 @@
from bzrlib.osutils import local_time_offset, username
from bzrlib.branch import gen_file_id
- from bzrlib.errors import BzrError
+ from bzrlib.errors import BzrError, EmptyCommit
from bzrlib.revision import Revision, RevisionReference
from bzrlib.trace import mutter, note
from bzrlib.xml import pack_xml
@@ -85,12 +89,16 @@
pending_merges = branch.pending_merges()
- missing_ids, new_inv = _gather_commit(branch,
- work_tree,
- work_inv,
- basis_inv,
- specific_files,
- verbose)
+ missing_ids, new_inv, any_changes = \
+ _gather_commit(branch,
+ work_tree,
+ work_inv,
+ basis_inv,
+ specific_files,
+ verbose)
+
+ if not (any_changes or allow_empty or pending_merges):
+ raise EmptyCommit()
for file_id in missing_ids:
# Any files that have been deleted are now removed from the
@@ -192,6 +200,8 @@
verbose):
"""Build inventory preparatory to commit.
+ Returns missing_ids, new_inv, any_changes.
+
This adds any changed files into the text store, and sets their
test-id, sha and size in the returned inventory appropriately.
@@ -209,6 +219,7 @@
from revision import Revision
from bzrlib.trace import mutter, note
+ any_changes = False
inv = Inventory()
missing_ids = []
@@ -233,6 +244,7 @@
if not work_tree.has_id(file_id):
if verbose:
print('deleted %s%s' % (path, kind_marker(entry.kind)))
+ any_changes = True
mutter(" file is missing, removing from inventory")
missing_ids.append(file_id)
continue
@@ -284,14 +296,17 @@
marked = path + kind_marker(entry.kind)
if not old_ie:
print 'added', marked
+ any_changes = True
elif old_ie == entry:
pass # unchanged
elif (old_ie.name == entry.name
and old_ie.parent_id == entry.parent_id):
print 'modified', marked
+ any_changes = True
else:
print 'renamed', marked
+ any_changes = True
- return missing_ids, inv
+ return missing_ids, inv, any_changes
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2005-06-22 08:12:31 +0000
+++ b/bzrlib/errors.py 2005-07-11 03:27:43 +0000
@@ -66,3 +66,7 @@
Exception.__init__(self, e)
else:
Exception.__init__(self)
+
+
+class EmptyCommit(Exception):
+ """Commit failed because nothing was changed."""
=== modified file 'bzrlib/selftest/whitebox.py'
--- a/bzrlib/selftest/whitebox.py 2005-07-06 05:24:29 +0000
+++ b/bzrlib/selftest/whitebox.py 2005-07-11 03:27:43 +0000
@@ -20,6 +20,22 @@
+class NoChanges(InTempDir):
+ def runTest(self):
+ from bzrlib.errors import EmptyCommit
+
+ b = Branch('.', init=True)
+
+ self.build_tree(['hello.txt'])
+
+ self.assertRaises(EmptyCommit,
+ b.commit,
+ 'commit without adding',
+ allow_empty=False)
+
+
+
+
class ValidateRevisionId(TestBase):
def runTest(self):
from bzrlib.revision import validate_revision_id
More information about the Pkg-bazaar-commits
mailing list