Mercurial > public > mercurial-scm > hg
comparison mercurial/subrepo.py @ 15149:eaec9cf91aea
subrepo: refactor state function
author | Martin Geisler <mg@aragost.com> |
---|---|
date | Thu, 22 Sep 2011 14:39:49 +0200 |
parents | 86380f24e697 |
children | 91dc8878f888 |
comparison
equal
deleted
inserted
replaced
15148:510184e5a09e | 15149:eaec9cf91aea |
---|---|
48 rev[path] = revision | 48 rev[path] = revision |
49 except IOError, err: | 49 except IOError, err: |
50 if err.errno != errno.ENOENT: | 50 if err.errno != errno.ENOENT: |
51 raise | 51 raise |
52 | 52 |
53 state = {} | 53 def remap(src): |
54 for path, src in p[''].items(): | |
55 kind = 'hg' | |
56 if src.startswith('['): | |
57 if ']' not in src: | |
58 raise util.Abort(_('missing ] in subrepo source')) | |
59 kind, src = src.split(']', 1) | |
60 kind = kind[1:] | |
61 | |
62 for pattern, repl in p.items('subpaths'): | 54 for pattern, repl in p.items('subpaths'): |
63 # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub | 55 # Turn r'C:\foo\bar' into r'C:\\foo\\bar' since re.sub |
64 # does a string decode. | 56 # does a string decode. |
65 repl = repl.encode('string-escape') | 57 repl = repl.encode('string-escape') |
66 # However, we still want to allow back references to go | 58 # However, we still want to allow back references to go |
70 try: | 62 try: |
71 src = re.sub(pattern, repl, src, 1) | 63 src = re.sub(pattern, repl, src, 1) |
72 except re.error, e: | 64 except re.error, e: |
73 raise util.Abort(_("bad subrepository pattern in %s: %s") | 65 raise util.Abort(_("bad subrepository pattern in %s: %s") |
74 % (p.source('subpaths', pattern), e)) | 66 % (p.source('subpaths', pattern), e)) |
75 | 67 return src |
68 | |
69 state = {} | |
70 for path, src in p[''].items(): | |
71 kind = 'hg' | |
72 if src.startswith('['): | |
73 if ']' not in src: | |
74 raise util.Abort(_('missing ] in subrepo source')) | |
75 kind, src = src.split(']', 1) | |
76 kind = kind[1:] | |
77 src = remap(src) | |
76 state[path] = (src.strip(), rev.get(path, ''), kind) | 78 state[path] = (src.strip(), rev.get(path, ''), kind) |
77 | 79 |
78 return state | 80 return state |
79 | 81 |
80 def writestate(repo, state): | 82 def writestate(repo, state): |