author | Matt Mackall <mpm@selenic.com> |
Sun, 06 Nov 2011 11:57:24 -0600 | |
changeset 15419 | ccb7de21625a |
parent 15418 | cf729af26963 |
child 15454 | 5a7dde5adec8 |
permissions | -rw-r--r-- |
15417
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
1 |
# Mercurial phases support code |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
2 |
# |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
3 |
# Copyright 2011 Pierre-Yves David <pierre-yves.david@ens-lyon.org> |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
4 |
# Logilab SA <contact@logilab.fr> |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
5 |
# Augie Fackler <durin42@gmail.com> |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
6 |
# |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
7 |
# This software may be used and distributed according to the terms of the |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
8 |
# GNU General Public License version 2 or any later version. |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
9 |
|
15419
ccb7de21625a
phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents:
15418
diff
changeset
|
10 |
import errno |
15418
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
11 |
from node import nullid, bin, hex |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
12 |
|
15417
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
13 |
allphases = range(2) |
5261140d9322
phases: Minimal first add.
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
diff
changeset
|
14 |
trackedphases = allphases[1:] |
15418
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
15 |
|
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
16 |
def readroots(repo): |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
17 |
"""Read phase roots from disk""" |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
18 |
roots = [set() for i in allphases] |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
19 |
roots[0].add(nullid) |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
20 |
try: |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
21 |
f = repo.sopener('phaseroots') |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
22 |
try: |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
23 |
for line in f: |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
24 |
phase, nh = line.strip().split() |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
25 |
roots[int(phase)].add(bin(nh)) |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
26 |
finally: |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
27 |
f.close() |
15419
ccb7de21625a
phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents:
15418
diff
changeset
|
28 |
except IOError, inst: |
ccb7de21625a
phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents:
15418
diff
changeset
|
29 |
if inst.errno != errno.ENOENT: |
ccb7de21625a
phases: handle errors other than ENOENT appropriately
Matt Mackall <mpm@selenic.com>
parents:
15418
diff
changeset
|
30 |
raise |
15418
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
31 |
return roots |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
32 |
|
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
33 |
def writeroots(repo): |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
34 |
"""Write phase roots from disk""" |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
35 |
f = repo.sopener('phaseroots', 'w', atomictemp=True) |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
36 |
try: |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
37 |
for phase, roots in enumerate(repo._phaseroots): |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
38 |
for h in roots: |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
39 |
f.write('%i %s\n' % (phase, hex(h))) |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
40 |
finally: |
cf729af26963
phases: basic I/O logic
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents:
15417
diff
changeset
|
41 |
f.close() |