Mercurial > hg
comparison mercurial/changegroup.py @ 39229:2646b8d66b7b
changegroup: move node sorting into deltagroup()
The 3 callers of deltagroup() all sort nodes and convert to
integer revs immediately before calling deltagroup().
Stepping back a bit, aside from the constraints on node ordering
that always apply (namely that a node must follow its ancestor),
it makes sense for sorting to be an implementation detail of the
store. Moving the sorting into deltagroup() will open the door
for moving sorting into a storage API.
The test for the changelog in deltagroup() to impact the sorting
method is a bit hacky. I suspect this will be resolved once
we establish a formal interface for delta group generation
and port changelog to it.
Differential Revision: https://phab.mercurial-scm.org/D4224
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 09 Aug 2018 14:31:25 -0700 |
parents | 0a934ee94f09 |
children | b518d495a560 |
comparison
equal
deleted
inserted
replaced
39228:66f046116105 | 39229:2646b8d66b7b |
---|---|
769 linknode=linknode, | 769 linknode=linknode, |
770 basenode=nullid, | 770 basenode=nullid, |
771 ellipsis=True, | 771 ellipsis=True, |
772 ) | 772 ) |
773 | 773 |
774 def deltagroup(repo, revs, store, ischangelog, lookup, forcedeltaparentprev, | 774 def deltagroup(repo, store, nodes, ischangelog, lookup, forcedeltaparentprev, |
775 allowreorder, | |
775 units=None, | 776 units=None, |
776 ellipses=False, clrevtolocalrev=None, fullclnodes=None, | 777 ellipses=False, clrevtolocalrev=None, fullclnodes=None, |
777 precomputedellipsis=None): | 778 precomputedellipsis=None): |
778 """Calculate deltas for a set of revisions. | 779 """Calculate deltas for a set of revisions. |
779 | 780 |
780 Is a generator of ``revisiondelta`` instances. | 781 Is a generator of ``revisiondelta`` instances. |
781 | 782 |
782 If units is not None, progress detail will be generated, units specifies | 783 If units is not None, progress detail will be generated, units specifies |
783 the type of revlog that is touched (changelog, manifest, etc.). | 784 the type of revlog that is touched (changelog, manifest, etc.). |
784 """ | 785 """ |
785 if not revs: | 786 if not nodes: |
786 return | 787 return |
787 | 788 |
788 # We perform two passes over the revisions whose data we will emit. | 789 # We perform two passes over the revisions whose data we will emit. |
789 # | 790 # |
790 # In the first pass, we obtain information about the deltas that will | 791 # In the first pass, we obtain information about the deltas that will |
794 # to obtain. | 795 # to obtain. |
795 # | 796 # |
796 # The second pass is simply resolving the requested deltas. | 797 # The second pass is simply resolving the requested deltas. |
797 | 798 |
798 cl = repo.changelog | 799 cl = repo.changelog |
800 | |
801 if ischangelog: | |
802 # Changelog doesn't benefit from reordering revisions. So send | |
803 # out revisions in store order. | |
804 # TODO the API would be cleaner if this were controlled by the | |
805 # store producing the deltas. | |
806 revs = sorted(cl.rev(n) for n in nodes) | |
807 elif ellipses: | |
808 revs = _sortnodesellipsis(store, nodes, cl, lookup) | |
809 else: | |
810 revs = _sortnodesnormal(store, nodes, allowreorder) | |
799 | 811 |
800 # In the first pass, collect info about the deltas we'll be | 812 # In the first pass, collect info about the deltas we'll be |
801 # generating. | 813 # generating. |
802 requests = [] | 814 requests = [] |
803 | 815 |
1097 # this manifest. | 1109 # this manifest. |
1098 changedfiles.update(c[3]) | 1110 changedfiles.update(c[3]) |
1099 | 1111 |
1100 return x | 1112 return x |
1101 | 1113 |
1102 # Changelog doesn't benefit from reordering revisions. So send out | |
1103 # revisions in store order. | |
1104 revs = sorted(cl.rev(n) for n in nodes) | |
1105 | |
1106 state = { | 1114 state = { |
1107 'clrevorder': clrevorder, | 1115 'clrevorder': clrevorder, |
1108 'mfs': mfs, | 1116 'mfs': mfs, |
1109 'changedfiles': changedfiles, | 1117 'changedfiles': changedfiles, |
1110 'clrevtomanifestrev': clrevtomanifestrev, | 1118 'clrevtomanifestrev': clrevtomanifestrev, |
1111 } | 1119 } |
1112 | 1120 |
1113 gen = deltagroup( | 1121 gen = deltagroup( |
1114 self._repo, revs, cl, True, lookupcl, | 1122 self._repo, cl, nodes, True, lookupcl, |
1115 self._forcedeltaparentprev, | 1123 self._forcedeltaparentprev, |
1124 # Reorder settings are currently ignored for changelog. | |
1125 True, | |
1116 ellipses=self._ellipses, | 1126 ellipses=self._ellipses, |
1117 units=_('changesets'), | 1127 units=_('changesets'), |
1118 clrevtolocalrev={}, | 1128 clrevtolocalrev={}, |
1119 fullclnodes=self._fullclnodes, | 1129 fullclnodes=self._fullclnodes, |
1120 precomputedellipsis=self._precomputedellipsis) | 1130 precomputedellipsis=self._precomputedellipsis) |
1127 | 1137 |
1128 `source` is unused here, but is used by extensions like remotefilelog to | 1138 `source` is unused here, but is used by extensions like remotefilelog to |
1129 change what is sent based in pulls vs pushes, etc. | 1139 change what is sent based in pulls vs pushes, etc. |
1130 """ | 1140 """ |
1131 repo = self._repo | 1141 repo = self._repo |
1132 cl = repo.changelog | |
1133 mfl = repo.manifestlog | 1142 mfl = repo.manifestlog |
1134 dirlog = mfl._revlog.dirlog | 1143 dirlog = mfl._revlog.dirlog |
1135 tmfnodes = {'': mfs} | 1144 tmfnodes = {'': mfs} |
1136 | 1145 |
1137 # Callback for the manifest, used to collect linkrevs for filelog | 1146 # Callback for the manifest, used to collect linkrevs for filelog |
1190 if dir and not prunednodes: | 1199 if dir and not prunednodes: |
1191 continue | 1200 continue |
1192 | 1201 |
1193 lookupfn = makelookupmflinknode(dir, nodes) | 1202 lookupfn = makelookupmflinknode(dir, nodes) |
1194 | 1203 |
1195 if self._ellipses: | |
1196 revs = _sortnodesellipsis(store, prunednodes, cl, | |
1197 lookupfn) | |
1198 else: | |
1199 revs = _sortnodesnormal(store, prunednodes, | |
1200 self._reorder) | |
1201 | |
1202 deltas = deltagroup( | 1204 deltas = deltagroup( |
1203 self._repo, revs, store, False, lookupfn, | 1205 self._repo, store, prunednodes, False, lookupfn, |
1204 self._forcedeltaparentprev, | 1206 self._forcedeltaparentprev, self._reorder, |
1205 ellipses=self._ellipses, | 1207 ellipses=self._ellipses, |
1206 units=_('manifests'), | 1208 units=_('manifests'), |
1207 clrevtolocalrev=clrevtolocalrev, | 1209 clrevtolocalrev=clrevtolocalrev, |
1208 fullclnodes=self._fullclnodes, | 1210 fullclnodes=self._fullclnodes, |
1209 precomputedellipsis=self._precomputedellipsis) | 1211 precomputedellipsis=self._precomputedellipsis) |
1258 return links | 1260 return links |
1259 else: | 1261 else: |
1260 linknodes = normallinknodes | 1262 linknodes = normallinknodes |
1261 | 1263 |
1262 repo = self._repo | 1264 repo = self._repo |
1263 cl = repo.changelog | |
1264 progress = repo.ui.makeprogress(_('bundling'), unit=_('files'), | 1265 progress = repo.ui.makeprogress(_('bundling'), unit=_('files'), |
1265 total=len(changedfiles)) | 1266 total=len(changedfiles)) |
1266 for i, fname in enumerate(sorted(changedfiles)): | 1267 for i, fname in enumerate(sorted(changedfiles)): |
1267 filerevlog = repo.file(fname) | 1268 filerevlog = repo.file(fname) |
1268 if not filerevlog: | 1269 if not filerevlog: |
1282 if flr(frev(n)) not in commonrevs] | 1283 if flr(frev(n)) not in commonrevs] |
1283 | 1284 |
1284 if not filenodes: | 1285 if not filenodes: |
1285 continue | 1286 continue |
1286 | 1287 |
1287 if self._ellipses: | |
1288 revs = _sortnodesellipsis(filerevlog, filenodes, | |
1289 cl, lookupfilelog) | |
1290 else: | |
1291 revs = _sortnodesnormal(filerevlog, filenodes, | |
1292 self._reorder) | |
1293 | |
1294 progress.update(i + 1, item=fname) | 1288 progress.update(i + 1, item=fname) |
1295 | 1289 |
1296 deltas = deltagroup( | 1290 deltas = deltagroup( |
1297 self._repo, revs, filerevlog, False, lookupfilelog, | 1291 self._repo, filerevlog, filenodes, False, lookupfilelog, |
1298 self._forcedeltaparentprev, | 1292 self._forcedeltaparentprev, self._reorder, |
1299 ellipses=self._ellipses, | 1293 ellipses=self._ellipses, |
1300 clrevtolocalrev=clrevtolocalrev, | 1294 clrevtolocalrev=clrevtolocalrev, |
1301 fullclnodes=self._fullclnodes, | 1295 fullclnodes=self._fullclnodes, |
1302 precomputedellipsis=self._precomputedellipsis) | 1296 precomputedellipsis=self._precomputedellipsis) |
1303 | 1297 |