comparison mercurial/commit.py @ 45708:60c46cc28bf4

commit: pass ChangingFiles object as argument to _process_files Instead of returning it, we pass it as an argument. This makes the whole if-else in `_prepare_files` a bit simpler. Else each if-else branch was creating the object. Differential Revision: https://phab.mercurial-scm.org/D9194
author Pulkit Goyal <7895pulkit@gmail.com>
date Sat, 10 Oct 2020 13:19:25 +0530
parents 035302e6bb38
children 0428978bca22
comparison
equal deleted inserted replaced
45707:035302e6bb38 45708:60c46cc28bf4
112 def _prepare_files(tr, ctx, error=False, origctx=None): 112 def _prepare_files(tr, ctx, error=False, origctx=None):
113 repo = ctx.repo() 113 repo = ctx.repo()
114 p1 = ctx.p1() 114 p1 = ctx.p1()
115 115
116 writechangesetcopy, writefilecopymeta = _write_copy_meta(repo) 116 writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
117 files = metadata.ChangingFiles()
117 ms = mergestate.mergestate.read(repo) 118 ms = mergestate.mergestate.read(repo)
118 salvaged = _get_salvaged(repo, ms, ctx) 119 salvaged = _get_salvaged(repo, ms, ctx)
120 for s in salvaged:
121 files.mark_salvaged(s)
119 122
120 if ctx.manifestnode(): 123 if ctx.manifestnode():
121 # reuse an existing manifest revision 124 # reuse an existing manifest revision
122 repo.ui.debug(b'reusing known manifest\n') 125 repo.ui.debug(b'reusing known manifest\n')
123 mn = ctx.manifestnode() 126 mn = ctx.manifestnode()
124 files = metadata.ChangingFiles()
125 files.update_touched(ctx.files()) 127 files.update_touched(ctx.files())
126 if writechangesetcopy: 128 if writechangesetcopy:
127 files.update_added(ctx.filesadded()) 129 files.update_added(ctx.filesadded())
128 files.update_removed(ctx.filesremoved()) 130 files.update_removed(ctx.filesremoved())
129 elif not ctx.files(): 131 elif not ctx.files():
130 repo.ui.debug(b'reusing manifest from p1 (no file change)\n') 132 repo.ui.debug(b'reusing manifest from p1 (no file change)\n')
131 mn = p1.manifestnode() 133 mn = p1.manifestnode()
132 files = metadata.ChangingFiles()
133 else: 134 else:
134 mn, files = _process_files(tr, ctx, ms, error=error) 135 mn = _process_files(tr, ctx, ms, files, error=error)
135 136
136 if origctx and origctx.manifestnode() == mn: 137 if origctx and origctx.manifestnode() == mn:
137 origfiles = origctx.files() 138 origfiles = origctx.files()
138 assert files.touched.issubset(origfiles) 139 assert files.touched.issubset(origfiles)
139 files.update_touched(origfiles) 140 files.update_touched(origfiles)
140 141
141 if writechangesetcopy: 142 if writechangesetcopy:
142 files.update_copies_from_p1(ctx.p1copies()) 143 files.update_copies_from_p1(ctx.p1copies())
143 files.update_copies_from_p2(ctx.p2copies()) 144 files.update_copies_from_p2(ctx.p2copies())
144
145 for s in salvaged:
146 files.mark_salvaged(s)
147 145
148 return mn, files 146 return mn, files
149 147
150 148
151 def _get_salvaged(repo, ms, ctx): 149 def _get_salvaged(repo, ms, ctx):
163 if fname in ctx: 161 if fname in ctx:
164 salvaged.append(fname) 162 salvaged.append(fname)
165 return salvaged 163 return salvaged
166 164
167 165
168 def _process_files(tr, ctx, ms, error=False): 166 def _process_files(tr, ctx, ms, files, error=False):
169 repo = ctx.repo() 167 repo = ctx.repo()
170 p1 = ctx.p1() 168 p1 = ctx.p1()
171 p2 = ctx.p2() 169 p2 = ctx.p2()
172 170
173 writechangesetcopy, writefilecopymeta = _write_copy_meta(repo) 171 writechangesetcopy, writefilecopymeta = _write_copy_meta(repo)
177 mctx = m1ctx.copy() 175 mctx = m1ctx.copy()
178 176
179 m = mctx.read() 177 m = mctx.read()
180 m1 = m1ctx.read() 178 m1 = m1ctx.read()
181 m2 = m2ctx.read() 179 m2 = m2ctx.read()
182
183 files = metadata.ChangingFiles()
184 180
185 # check in files 181 # check in files
186 added = [] 182 added = []
187 removed = list(ctx.removed()) 183 removed = list(ctx.removed())
188 linkrev = len(repo) 184 linkrev = len(repo)
229 if not rf(f): 225 if not rf(f):
230 files.mark_removed(f) 226 files.mark_removed(f)
231 227
232 mn = _commit_manifest(tr, linkrev, ctx, mctx, m, files.touched, added, drop) 228 mn = _commit_manifest(tr, linkrev, ctx, mctx, m, files.touched, added, drop)
233 229
234 return mn, files 230 return mn
235 231
236 232
237 def _filecommit( 233 def _filecommit(
238 repo, fctx, manifest1, manifest2, linkrev, tr, includecopymeta, ms, 234 repo, fctx, manifest1, manifest2, linkrev, tr, includecopymeta, ms,
239 ): 235 ):