Mercurial > hg
comparison mercurial/commit.py @ 45236:0c468fef09b3
commitctx: extract all the manual logic to process the files
That branch of the if is significantly more complicated than the other two.
Moving it to its own function make it simple to keep the scope limited and to
read to the higher level function.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Thu, 23 Jul 2020 18:25:45 +0200 |
parents | b65b4b09859c |
children | 39f4ec4039a8 |
comparison
equal
deleted
inserted
replaced
45235:b65b4b09859c | 45236:0c468fef09b3 |
---|---|
82 elif not ctx.files(): | 82 elif not ctx.files(): |
83 repo.ui.debug(b'reusing manifest from p1 (no file change)\n') | 83 repo.ui.debug(b'reusing manifest from p1 (no file change)\n') |
84 mn = p1.manifestnode() | 84 mn = p1.manifestnode() |
85 files = [] | 85 files = [] |
86 else: | 86 else: |
87 m1ctx = p1.manifestctx() | 87 mn, files, added, removed = _process_files(tr, ctx, error=error) |
88 m2ctx = p2.manifestctx() | |
89 mctx = m1ctx.copy() | |
90 | |
91 m = mctx.read() | |
92 m1 = m1ctx.read() | |
93 m2 = m2ctx.read() | |
94 | |
95 # check in files | |
96 added = [] | |
97 files_added = [] | |
98 removed = list(ctx.removed()) | |
99 touched = [] | |
100 linkrev = len(repo) | |
101 repo.ui.note(_(b"committing files:\n")) | |
102 uipathfn = scmutil.getuipathfn(repo) | |
103 for f in sorted(ctx.modified() + ctx.added()): | |
104 repo.ui.note(uipathfn(f) + b"\n") | |
105 try: | |
106 fctx = ctx[f] | |
107 if fctx is None: | |
108 removed.append(f) | |
109 else: | |
110 added.append(f) | |
111 m[f], is_touched = _filecommit( | |
112 repo, fctx, m1, m2, linkrev, tr, writefilecopymeta, | |
113 ) | |
114 if is_touched: | |
115 touched.append(f) | |
116 if is_touched == 'added': | |
117 files_added.append(f) | |
118 m.setflag(f, fctx.flags()) | |
119 except OSError: | |
120 repo.ui.warn(_(b"trouble committing %s!\n") % uipathfn(f)) | |
121 raise | |
122 except IOError as inst: | |
123 errcode = getattr(inst, 'errno', errno.ENOENT) | |
124 if error or errcode and errcode != errno.ENOENT: | |
125 repo.ui.warn( | |
126 _(b"trouble committing %s!\n") % uipathfn(f) | |
127 ) | |
128 raise | |
129 | |
130 # update manifest | |
131 removed = [f for f in removed if f in m1 or f in m2] | |
132 drop = sorted([f for f in removed if f in m]) | |
133 for f in drop: | |
134 del m[f] | |
135 if p2.rev() != nullrev: | |
136 rf = metadata.get_removal_filter(ctx, (p1, p2, m1, m2)) | |
137 removed = [f for f in removed if not rf(f)] | |
138 | |
139 touched.extend(removed) | |
140 | |
141 files = touched | |
142 mn = _commit_manifest(tr, linkrev, ctx, mctx, files, added, drop) | |
143 | |
144 if writechangesetcopy: | 88 if writechangesetcopy: |
145 filesremoved = removed | 89 filesremoved = removed |
146 filesadded = files_added | 90 filesadded = added |
147 | 91 |
148 if not writefilecopymeta: | 92 if not writefilecopymeta: |
149 # If writing only to changeset extras, use None to indicate that | 93 # If writing only to changeset extras, use None to indicate that |
150 # no entry should be written. If writing to both, write an empty | 94 # no entry should be written. If writing to both, write an empty |
151 # entry to prevent the reader from falling back to reading | 95 # entry to prevent the reader from falling back to reading |
188 # be compliant anyway | 132 # be compliant anyway |
189 # | 133 # |
190 # if minimal phase was 0 we don't need to retract anything | 134 # if minimal phase was 0 we don't need to retract anything |
191 phases.registernew(repo, tr, targetphase, [n]) | 135 phases.registernew(repo, tr, targetphase, [n]) |
192 return n | 136 return n |
137 | |
138 | |
139 def _process_files(tr, ctx, error=False): | |
140 repo = ctx.repo() | |
141 p1 = ctx.p1() | |
142 p2 = ctx.p2() | |
143 | |
144 writechangesetcopy, writefilecopymeta = _write_copy_meta(repo) | |
145 | |
146 m1ctx = p1.manifestctx() | |
147 m2ctx = p2.manifestctx() | |
148 mctx = m1ctx.copy() | |
149 | |
150 m = mctx.read() | |
151 m1 = m1ctx.read() | |
152 m2 = m2ctx.read() | |
153 | |
154 # check in files | |
155 added = [] | |
156 filesadded = [] | |
157 removed = list(ctx.removed()) | |
158 touched = [] | |
159 linkrev = len(repo) | |
160 repo.ui.note(_(b"committing files:\n")) | |
161 uipathfn = scmutil.getuipathfn(repo) | |
162 for f in sorted(ctx.modified() + ctx.added()): | |
163 repo.ui.note(uipathfn(f) + b"\n") | |
164 try: | |
165 fctx = ctx[f] | |
166 if fctx is None: | |
167 removed.append(f) | |
168 else: | |
169 added.append(f) | |
170 m[f], is_touched = _filecommit( | |
171 repo, fctx, m1, m2, linkrev, tr, writefilecopymeta, | |
172 ) | |
173 if is_touched: | |
174 touched.append(f) | |
175 if is_touched == 'added': | |
176 filesadded.append(f) | |
177 m.setflag(f, fctx.flags()) | |
178 except OSError: | |
179 repo.ui.warn(_(b"trouble committing %s!\n") % uipathfn(f)) | |
180 raise | |
181 except IOError as inst: | |
182 errcode = getattr(inst, 'errno', errno.ENOENT) | |
183 if error or errcode and errcode != errno.ENOENT: | |
184 repo.ui.warn(_(b"trouble committing %s!\n") % uipathfn(f)) | |
185 raise | |
186 | |
187 # update manifest | |
188 removed = [f for f in removed if f in m1 or f in m2] | |
189 drop = sorted([f for f in removed if f in m]) | |
190 for f in drop: | |
191 del m[f] | |
192 if p2.rev() != nullrev: | |
193 rf = metadata.get_removal_filter(ctx, (p1, p2, m1, m2)) | |
194 removed = [f for f in removed if not rf(f)] | |
195 | |
196 touched.extend(removed) | |
197 | |
198 files = touched | |
199 mn = _commit_manifest(tr, linkrev, ctx, mctx, files, added, drop) | |
200 | |
201 return mn, files, filesadded, removed | |
193 | 202 |
194 | 203 |
195 def _filecommit( | 204 def _filecommit( |
196 repo, fctx, manifest1, manifest2, linkrev, tr, includecopymeta, | 205 repo, fctx, manifest1, manifest2, linkrev, tr, includecopymeta, |
197 ): | 206 ): |