comparison onsub.py @ 17:5ea3f7533ec5

Exposed new environment variable with the subrepo type. Updated test. Added a test for mixed subrepo cases.
author Ludovic Chabant <ludovic@chabant.com>
date Tue, 27 Mar 2012 16:53:23 -0700
parents 44feac64ecfe
children d920e3425db5
comparison
equal deleted inserted replaced
16:44feac64ecfe 17:5ea3f7533ec5
46 containing repository's ``.hgsub`` file. 46 containing repository's ``.hgsub`` file.
47 47
48 ``HG_SUBSTATE``: 48 ``HG_SUBSTATE``:
49 State of the current subrepository as specified in the 49 State of the current subrepository as specified in the
50 containing repository's ``.hgsubstate`` file. 50 containing repository's ``.hgsubstate`` file.
51
52 ``HG_SUBTYPE``:
53 The type of the current subrepository (hg, git or svn).
51 """ 54 """
52 55
53 # function level "constants" - these won't be modified by the nested functions 56 # function level "constants" - these won't be modified by the nested functions
54 print0 = opts.get('print0') 57 print0 = opts.get('print0')
55 if opts.get('ignore_errors'): 58 if opts.get('ignore_errors'):
59 maxdepth = opts.get('max_depth') 62 maxdepth = opts.get('max_depth')
60 precmd = None 63 precmd = None
61 postcmd = None 64 postcmd = None
62 includeroot = opts.get('root_repo') 65 includeroot = opts.get('root_repo')
63 66
64 def execCmd(sub, cmd): 67 def execCmd(sub, cmd, kind):
65 """if sub == None, cmd is executed inside repo; else, inside sub. 68 """if sub == None, cmd is executed inside repo; else, inside sub.
66 If cmd == None, do nothing. If cmd == '', do only the print0 (if needed). 69 If cmd == None, do nothing. If cmd == '', do only the print0 (if needed).
67 Else, do either print0 or the debugging message, then execute the command. 70 Else, do either print0 or the debugging message, then execute the command.
71 kind is the type of the (sub)repo.
68 """ 72 """
69 if sub == None: 73 if sub == None:
70 envargdict = dict(HG_SUBPATH='.', 74 envargdict = dict(HG_SUBPATH='.',
71 HG_SUBURL='.', 75 HG_SUBURL='.',
72 HG_SUBSTATE=repo['.'].hex(), 76 HG_SUBSTATE=repo['.'].hex(),
73 HG_REPO=repo.root) 77 HG_REPO=repo.root,
78 HG_SUBTYPE=kind)
74 relpath = '.' 79 relpath = '.'
75 cmdwd = repo.root 80 cmdwd = repo.root
76 else: 81 else:
77 # subrepo.relpath was renamed to subrepo.subrelpath in 82 # subrepo.relpath was renamed to subrepo.subrelpath in
78 # 18b5b6392fcf. 83 # 18b5b6392fcf.
81 else: 86 else:
82 relpath = subrepo.subrelpath(sub) 87 relpath = subrepo.subrelpath(sub)
83 envargdict = dict(HG_SUBPATH=relpath, 88 envargdict = dict(HG_SUBPATH=relpath,
84 HG_SUBURL=sub._path, 89 HG_SUBURL=sub._path,
85 HG_SUBSTATE=sub._state[1], 90 HG_SUBSTATE=sub._state[1],
86 HG_REPO=repo.root) 91 HG_REPO=repo.root,
92 HG_SUBTYPE=kind)
87 cmdwd = os.path.join(repo.root, relpath) 93 cmdwd = os.path.join(repo.root, relpath)
88 if cmd != None: 94 if cmd != None:
89 if print0: 95 if print0:
90 ui.write(relpath, "\0") 96 ui.write(relpath, "\0")
91 if cmd != '': 97 if cmd != '':
94 errprefix=_('terminated onsub in %s') % relpath) 100 errprefix=_('terminated onsub in %s') % relpath)
95 101
96 def bfs(): 102 def bfs():
97 """execute precmd in repo.root and in each subrepository, breadth-first""" 103 """execute precmd in repo.root and in each subrepository, breadth-first"""
98 if includeroot: 104 if includeroot:
99 execCmd(None, precmd) 105 execCmd(None, precmd, 'hg')
100 ctx = repo['.'] 106 ctx = repo['.']
101 work = [(1, ctx.sub(subpath)) for subpath in sorted(ctx.substate)] 107 work = [(1, ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)]
102 while work: 108 while work:
103 (depth, sub) = work.pop(0) 109 (depth, sub, kind) = work.pop(0)
104 if depth > maxdepth >= 0: 110 if depth > maxdepth >= 0:
105 continue 111 continue
106 execCmd(sub, precmd) 112 execCmd(sub, precmd, kind)
107 if isinstance(sub, subrepo.hgsubrepo): 113 if kind == 'hg':
108 rev = sub._state[1] 114 rev = sub._state[1]
109 ctx = sub._repo[rev] 115 ctx = sub._repo[rev]
110 w = [(depth + 1, ctx.sub(subpath)) 116 w = [(depth + 1, ctx.sub(subpath), ctx.substate[subpath][2])
111 for subpath in sorted(ctx.substate)] 117 for subpath in sorted(ctx.substate)]
112 work.extend(w) 118 work.extend(w)
113 119
114 def dfs(): 120 def dfs():
115 """execute pre-/postcmd in repo.root and in each subrepository, depth-first""" 121 """execute pre-/postcmd in repo.root and in each subrepository, depth-first"""
116 122
117 def dfs_rek(depth, sub): 123 def dfs_rek(depth, sub, kind):
118 if depth > maxdepth >= 0: 124 if depth > maxdepth >= 0:
119 return 125 return
120 execCmd(sub, precmd) 126 execCmd(sub, precmd, kind)
121 if isinstance(sub, subrepo.hgsubrepo): 127 if kind == 'hg':
122 rev = sub._state[1] 128 rev = sub._state[1]
123 ctx = sub._repo[rev] 129 ctx = sub._repo[rev]
124 for subpath in sorted(ctx.substate): 130 for subpath in sorted(ctx.substate):
125 dfs_rek(depth+1, ctx.sub(subpath)) 131 dfs_rek(depth+1, ctx.sub(subpath), ctx.substate[subpath][2])
126 execCmd(sub, postcmd) 132 execCmd(sub, postcmd, kind)
127 133
128 ctx = repo['.'] 134 ctx = repo['.']
129 work = [ctx.sub(subpath) for subpath in sorted(ctx.substate)] 135 work = [(ctx.sub(subpath), ctx.substate[subpath][2]) for subpath in sorted(ctx.substate)]
130 if includeroot: 136 if includeroot:
131 execCmd(None, precmd) 137 execCmd(None, precmd, 'hg')
132 for sub in work: 138 for (sub, kind) in work:
133 dfs_rek(1, sub) 139 dfs_rek(1, sub, kind)
134 if includeroot: 140 if includeroot:
135 execCmd(None, postcmd) 141 execCmd(None, postcmd, 'hg')
136 142
137 ### start of main function part ### 143 ### start of main function part ###
138 if len(args) == 2: 144 if len(args) == 2:
139 precmd = args[0] 145 precmd = args[0]
140 postcmd = args[1] 146 postcmd = args[1]