[RFC] Off by one error in info.py
Olaf Conradi
olaf at conradi.org
Sat Apr 1 13:12:27 BST 2006
Hello,
I was creating some testcases for my new bzr info and noticed a bug in
current missing revisions count code. It has an off-by-one error when
comparing length of a list with its index (which starts from 0).
I can either adjust the substraction with one, or use
revision_id_to_revo. The latter one has my preference because it would
get rid of the exception.
Shall I put the latter in my bzr.olaf.info branch (I already have a test case).
BTW: How does one best indent this without crossing 80 chars? PEP8
does not really show how to do it in this case. The original code
crossed 80 chars.
Cheers
-Olaf
=== modified file 'a/bzrlib/info.py'
--- a/bzrlib/info.py
+++ b/bzrlib/info.py
@@ -97,7 +97,8 @@
if len(history) and working.last_revision() != history[-1]:
try:
- missing_count = len(history) -
history.index(working.last_revision())
+ missing_count = len(history) - (1 +
+ history.index(working.last_revision())
except ValueError:
# consider it all out of date
missing_count = len(history)
=== modified file 'a/bzrlib/info.py'
--- a/bzrlib/info.py
+++ b/bzrlib/info.py
@@ -96,11 +96,8 @@
len(remote_extra), plural(len(remote_extra)))
if len(history) and working.last_revision() != history[-1]:
- try:
- missing_count = len(history) -
history.index(working.last_revision())
- except ValueError:
- # consider it all out of date
- missing_count = len(history)
+ missing_count = len(history) - \
+ branch.revision_id_to_revno(working.last_revision())
print 'Working tree is out of date: missing %d revision%s.' % (
missing_count, plural(missing_count))
print 'in the working tree:'
More information about the bazaar
mailing list