Mercurial > hg
comparison mercurial/changegroup.py @ 38999:b83e9c503f2f
changegroup: define linknodes callbacks in generatefiles()
This is how it is done everywhere else.
But the logic here is a bit more complex because shallow clone
needs to reference the original linknode implementation. But
at least now all function implementations are defined in the
same place.
Differential Revision: https://phab.mercurial-scm.org/D4191
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 07 Aug 2018 15:45:56 -0700 |
parents | 40374b4a780f |
children | 4cff37564006 |
comparison
equal
deleted
inserted
replaced
38998:40374b4a780f | 38999:b83e9c503f2f |
---|---|
817 for (n, lr) in mfs.iteritems()] | 817 for (n, lr) in mfs.iteritems()] |
818 | 818 |
819 mfs.clear() | 819 mfs.clear() |
820 clrevs = set(cl.rev(x) for x in clnodes) | 820 clrevs = set(cl.rev(x) for x in clnodes) |
821 | 821 |
822 if not fastpathlinkrev: | 822 for chunk in self.generatefiles(changedfiles, commonrevs, |
823 def linknodes(unused, fname): | 823 source, mfdicts, fastpathlinkrev, |
824 return fnodes.get(fname, {}) | 824 fnodes, clrevs): |
825 else: | |
826 cln = cl.node | |
827 def linknodes(filerevlog, fname): | |
828 llr = filerevlog.linkrev | |
829 fln = filerevlog.node | |
830 revs = ((r, llr(r)) for r in filerevlog) | |
831 return dict((fln(r), cln(lr)) for r, lr in revs if lr in clrevs) | |
832 | |
833 for chunk in self.generatefiles(changedfiles, linknodes, commonrevs, | |
834 source, mfdicts): | |
835 yield chunk | 825 yield chunk |
836 | 826 |
837 yield self._close() | 827 yield self._close() |
838 | 828 |
839 if clnodes: | 829 if clnodes: |
984 yield x | 974 yield x |
985 self._verbosenote(_('%8.i (manifests)\n') % size) | 975 self._verbosenote(_('%8.i (manifests)\n') % size) |
986 yield self._manifestsend | 976 yield self._manifestsend |
987 | 977 |
988 # The 'source' parameter is useful for extensions | 978 # The 'source' parameter is useful for extensions |
989 def generatefiles(self, changedfiles, linknodes, commonrevs, source, | 979 def generatefiles(self, changedfiles, commonrevs, source, |
990 mfdicts): | 980 mfdicts, fastpathlinkrev, fnodes, clrevs): |
991 changedfiles = list(filter(self._filematcher, changedfiles)) | 981 changedfiles = list(filter(self._filematcher, changedfiles)) |
982 | |
983 if not fastpathlinkrev: | |
984 def normallinknodes(unused, fname): | |
985 return fnodes.get(fname, {}) | |
986 else: | |
987 cln = self._repo.changelog.node | |
988 | |
989 def normallinknodes(store, fname): | |
990 flinkrev = store.linkrev | |
991 fnode = store.node | |
992 revs = ((r, flinkrev(r)) for r in store) | |
993 return dict((fnode(r), cln(lr)) | |
994 for r, lr in revs if lr in clrevs) | |
992 | 995 |
993 if self._isshallow: | 996 if self._isshallow: |
994 # In a shallow clone, the linknodes callback needs to also include | 997 # In a shallow clone, the linknodes callback needs to also include |
995 # those file nodes that are in the manifests we sent but weren't | 998 # those file nodes that are in the manifests we sent but weren't |
996 # introduced by those manifests. | 999 # introduced by those manifests. |
997 commonctxs = [self._repo[c] for c in commonrevs] | 1000 commonctxs = [self._repo[c] for c in commonrevs] |
998 oldlinknodes = linknodes | |
999 clrev = self._repo.changelog.rev | 1001 clrev = self._repo.changelog.rev |
1000 | 1002 |
1001 # Defining this function has a side-effect of overriding the | 1003 # Defining this function has a side-effect of overriding the |
1002 # function of the same name that was passed in as an argument. | 1004 # function of the same name that was passed in as an argument. |
1003 # TODO have caller pass in appropriate function. | 1005 # TODO have caller pass in appropriate function. |
1006 try: | 1008 try: |
1007 fnode = c.filenode(fname) | 1009 fnode = c.filenode(fname) |
1008 self._clrevtolocalrev[c.rev()] = flog.rev(fnode) | 1010 self._clrevtolocalrev[c.rev()] = flog.rev(fnode) |
1009 except error.ManifestLookupError: | 1011 except error.ManifestLookupError: |
1010 pass | 1012 pass |
1011 links = oldlinknodes(flog, fname) | 1013 links = normallinknodes(flog, fname) |
1012 if len(links) != len(mfdicts): | 1014 if len(links) != len(mfdicts): |
1013 for mf, lr in mfdicts: | 1015 for mf, lr in mfdicts: |
1014 fnode = mf.get(fname, None) | 1016 fnode = mf.get(fname, None) |
1015 if fnode in links: | 1017 if fnode in links: |
1016 links[fnode] = min(links[fnode], lr, key=clrev) | 1018 links[fnode] = min(links[fnode], lr, key=clrev) |
1017 elif fnode: | 1019 elif fnode: |
1018 links[fnode] = lr | 1020 links[fnode] = lr |
1019 return links | 1021 return links |
1022 else: | |
1023 linknodes = normallinknodes | |
1020 | 1024 |
1021 return self._generatefiles(changedfiles, linknodes, commonrevs, source) | 1025 return self._generatefiles(changedfiles, linknodes, commonrevs, source) |
1022 | 1026 |
1023 def _generatefiles(self, changedfiles, linknodes, commonrevs, source): | 1027 def _generatefiles(self, changedfiles, linknodes, commonrevs, source): |
1024 repo = self._repo | 1028 repo = self._repo |