folder: LocalStatus: revamp cachemessagelist()
- Do not redefine "file". - break loop as soon as possible. Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
parent
9e6b23933a
commit
285295c4f2
@ -117,33 +117,33 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
self.messagelist = {}
|
self.messagelist = {}
|
||||||
return
|
return
|
||||||
|
|
||||||
# loop as many times as version, and update format
|
# Loop as many times as version, and update format.
|
||||||
for i in range(1, self.cur_version+1):
|
for i in range(1, self.cur_version + 1):
|
||||||
file = open(self.filename, "rt")
|
|
||||||
self.messagelist = {}
|
self.messagelist = {}
|
||||||
line = file.readline().strip()
|
cache = open(self.filename, "rt")
|
||||||
|
line = cache.readline().strip()
|
||||||
|
|
||||||
# convert from format v1
|
# Format is up to date. break.
|
||||||
if line == (self.magicline % 1):
|
if line == (self.magicline % self.cur_version):
|
||||||
self.ui._msg('Upgrading LocalStatus cache from version 1 to version 2 for %s:%s' %\
|
break
|
||||||
(self.repository, self))
|
|
||||||
self.readstatus_v1(file)
|
# Convert from format v1.
|
||||||
file.close()
|
elif line == (self.magicline % 1):
|
||||||
|
self.ui._msg('Upgrading LocalStatus cache from version 1'
|
||||||
|
'to version 2 for %s:%s'% (self.repository, self))
|
||||||
|
self.readstatus_v1(cache)
|
||||||
|
cache.close()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
# NOTE: Add other format transitions here in the future.
|
# NOTE: Add other format transitions here in the future.
|
||||||
# elif line == (self.magicline % 2):
|
# elif line == (self.magicline % 2):
|
||||||
# self.ui._msg('Upgrading LocalStatus cache from version 2 to version 3 for %s:%s' %\
|
# self.ui._msg(u'Upgrading LocalStatus cache from version 2'
|
||||||
# (self.repository, self))
|
# 'to version 3 for %s:%s'% (self.repository, self))
|
||||||
# self.readstatus_v2(file)
|
# self.readstatus_v2(cache)
|
||||||
# file.close()
|
# cache.close()
|
||||||
# file.save()
|
# cache.save()
|
||||||
|
|
||||||
# format is up to date. break
|
# Something is wrong.
|
||||||
elif line == (self.magicline % self.cur_version):
|
|
||||||
break
|
|
||||||
|
|
||||||
# something is wrong
|
|
||||||
else:
|
else:
|
||||||
errstr = "Unrecognized cache magicline in '%s'" % self.filename
|
errstr = "Unrecognized cache magicline in '%s'" % self.filename
|
||||||
self.ui.warn(errstr)
|
self.ui.warn(errstr)
|
||||||
@ -152,14 +152,14 @@ class LocalStatusFolder(BaseFolder):
|
|||||||
if not line:
|
if not line:
|
||||||
# The status file is empty - should not have happened,
|
# The status file is empty - should not have happened,
|
||||||
# but somehow did.
|
# but somehow did.
|
||||||
errstr = "Cache file '%s' is empty. Closing..." % self.filename
|
errstr = "Cache file '%s' is empty."% self.filename
|
||||||
self.ui.warn(errstr)
|
self.ui.warn(errstr)
|
||||||
file.close()
|
cache.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
assert(line == (self.magicline % self.cur_version))
|
assert(line == (self.magicline % self.cur_version))
|
||||||
self.readstatus(file)
|
self.readstatus(cache)
|
||||||
file.close()
|
cache.close()
|
||||||
|
|
||||||
def dropmessagelistcache(self):
|
def dropmessagelistcache(self):
|
||||||
self.messagelist = None
|
self.messagelist = None
|
||||||
|
Loading…
Reference in New Issue
Block a user