##// END OF EJS Templates
phases: handle errors other than ENOENT appropriately
Matt Mackall -
r15419:ccb7de21 default
parent child Browse files
Show More
@@ -1,39 +1,41 b''
1 # Mercurial phases support code
1 # Mercurial phases support code
2 #
2 #
3 # Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
3 # Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
4 # Logilab SA <contact@logilab.fr>
4 # Logilab SA <contact@logilab.fr>
5 # Augie Fackler <durin42@gmail.com>
5 # Augie Fackler <durin42@gmail.com>
6 #
6 #
7 # This software may be used and distributed according to the terms of the
7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2 or any later version.
8 # GNU General Public License version 2 or any later version.
9
9
10 import errno
10 from node import nullid, bin, hex
11 from node import nullid, bin, hex
11
12
12 allphases = range(2)
13 allphases = range(2)
13 trackedphases = allphases[1:]
14 trackedphases = allphases[1:]
14
15
15 def readroots(repo):
16 def readroots(repo):
16 """Read phase roots from disk"""
17 """Read phase roots from disk"""
17 roots = [set() for i in allphases]
18 roots = [set() for i in allphases]
18 roots[0].add(nullid)
19 roots[0].add(nullid)
19 try:
20 try:
20 f = repo.sopener('phaseroots')
21 f = repo.sopener('phaseroots')
21 try:
22 try:
22 for line in f:
23 for line in f:
23 phase, nh = line.strip().split()
24 phase, nh = line.strip().split()
24 roots[int(phase)].add(bin(nh))
25 roots[int(phase)].add(bin(nh))
25 finally:
26 finally:
26 f.close()
27 f.close()
27 except IOError:
28 except IOError, inst:
28 pass # default value are enough
29 if inst.errno != errno.ENOENT:
30 raise
29 return roots
31 return roots
30
32
31 def writeroots(repo):
33 def writeroots(repo):
32 """Write phase roots from disk"""
34 """Write phase roots from disk"""
33 f = repo.sopener('phaseroots', 'w', atomictemp=True)
35 f = repo.sopener('phaseroots', 'w', atomictemp=True)
34 try:
36 try:
35 for phase, roots in enumerate(repo._phaseroots):
37 for phase, roots in enumerate(repo._phaseroots):
36 for h in roots:
38 for h in roots:
37 f.write('%i %s\n' % (phase, hex(h)))
39 f.write('%i %s\n' % (phase, hex(h)))
38 finally:
40 finally:
39 f.close()
41 f.close()
General Comments 0
You need to be logged in to leave comments. Login now