##// END OF EJS Templates
exchangev2: recognize narrow patterns when pulling...
Gregory Szorc -
r40363:55836a34 default
parent child Browse files
Show More
@@ -0,0 +1,38 b''
1 # pullext.py - Simple extension to test pulling
2 #
3 # Copyright 2018 Gregory Szorc <gregory.szorc@gmail.com>
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7
8 from __future__ import absolute_import
9
10 from mercurial.i18n import _
11 from mercurial import (
12 commands,
13 extensions,
14 localrepo,
15 repository,
16 )
17
18 def clonecommand(orig, ui, repo, *args, **kwargs):
19 if kwargs.get(r'include') or kwargs.get(r'exclude'):
20 kwargs[r'narrow'] = True
21
22 return orig(ui, repo, *args, **kwargs)
23
24 def featuresetup(ui, features):
25 features.add(repository.NARROW_REQUIREMENT)
26
27 def extsetup(ui):
28 entry = extensions.wrapcommand(commands.table, 'clone', clonecommand)
29
30 hasinclude = any(x[1] == 'include' for x in entry[1])
31
32 if not hasinclude:
33 entry[1].append(('', 'include', [],
34 _('pattern of file/directory to clone')))
35 entry[1].append(('', 'exclude', [],
36 _('pattern of file/directory to not clone')))
37
38 localrepo.featuresetupfuncs.add(featuresetup)
@@ -19,6 +19,7 b' from . import ('
19 bookmarks,
19 bookmarks,
20 error,
20 error,
21 mdiff,
21 mdiff,
22 narrowspec,
22 phases,
23 phases,
23 pycompat,
24 pycompat,
24 setdiscovery,
25 setdiscovery,
@@ -30,6 +31,23 b' def pull(pullop):'
30 remote = pullop.remote
31 remote = pullop.remote
31 tr = pullop.trmanager.transaction()
32 tr = pullop.trmanager.transaction()
32
33
34 # We don't use the repo's narrow matcher here because the patterns passed
35 # to exchange.pull() could be different.
36 narrowmatcher = narrowspec.match(repo.root,
37 # Empty maps to nevermatcher. So always
38 # set includes if missing.
39 pullop.includepats or {'path:.'},
40 pullop.excludepats)
41
42 if pullop.includepats or pullop.excludepats:
43 pathfilter = {}
44 if pullop.includepats:
45 pathfilter[b'include'] = sorted(pullop.includepats)
46 if pullop.excludepats:
47 pathfilter[b'exclude'] = sorted(pullop.excludepats)
48 else:
49 pathfilter = None
50
33 # Figure out what needs to be fetched.
51 # Figure out what needs to be fetched.
34 common, fetch, remoteheads = _pullchangesetdiscovery(
52 common, fetch, remoteheads = _pullchangesetdiscovery(
35 repo, remote, pullop.heads, abortwhenunrelated=pullop.force)
53 repo, remote, pullop.heads, abortwhenunrelated=pullop.force)
@@ -63,8 +81,8 b' def pull(pullop):'
63
81
64 # Find all file nodes referenced by added manifests and fetch those
82 # Find all file nodes referenced by added manifests and fetch those
65 # revisions.
83 # revisions.
66 fnodes = _derivefilesfrommanifests(repo, manres['added'])
84 fnodes = _derivefilesfrommanifests(repo, narrowmatcher, manres['added'])
67 _fetchfilesfromcsets(repo, tr, remote, fnodes, csetres['added'],
85 _fetchfilesfromcsets(repo, tr, remote, pathfilter, fnodes, csetres['added'],
68 manres['linkrevs'])
86 manres['linkrevs'])
69
87
70 def _pullchangesetdiscovery(repo, remote, heads, abortwhenunrelated=True):
88 def _pullchangesetdiscovery(repo, remote, heads, abortwhenunrelated=True):
@@ -315,7 +333,7 b' def _fetchmanifests(repo, tr, remote, ma'
315 'linkrevs': linkrevs,
333 'linkrevs': linkrevs,
316 }
334 }
317
335
318 def _derivefilesfrommanifests(repo, manifestnodes):
336 def _derivefilesfrommanifests(repo, matcher, manifestnodes):
319 """Determine what file nodes are relevant given a set of manifest nodes.
337 """Determine what file nodes are relevant given a set of manifest nodes.
320
338
321 Returns a dict mapping file paths to dicts of file node to first manifest
339 Returns a dict mapping file paths to dicts of file node to first manifest
@@ -340,7 +358,8 b' def _derivefilesfrommanifests(repo, mani'
340 md = m.readfast()
358 md = m.readfast()
341
359
342 for path, fnode in md.items():
360 for path, fnode in md.items():
343 fnodes[path].setdefault(fnode, manifestnode)
361 if matcher(path):
362 fnodes[path].setdefault(fnode, manifestnode)
344
363
345 progress.increment()
364 progress.increment()
346
365
@@ -421,7 +440,8 b' def _fetchfiles(repo, tr, remote, fnodes'
421 locallinkrevs[path].__getitem__,
440 locallinkrevs[path].__getitem__,
422 weakref.proxy(tr))
441 weakref.proxy(tr))
423
442
424 def _fetchfilesfromcsets(repo, tr, remote, fnodes, csets, manlinkrevs):
443 def _fetchfilesfromcsets(repo, tr, remote, pathfilter, fnodes, csets,
444 manlinkrevs):
425 """Fetch file data from explicit changeset revisions."""
445 """Fetch file data from explicit changeset revisions."""
426
446
427 def iterrevisions(objs, remaining, progress):
447 def iterrevisions(objs, remaining, progress):
@@ -481,6 +501,9 b' def _fetchfilesfromcsets(repo, tr, remot'
481 b'haveparents': True,
501 b'haveparents': True,
482 }
502 }
483
503
504 if pathfilter:
505 args[b'pathfilter'] = pathfilter
506
484 objs = e.callcommand(b'filesdata', args).result()
507 objs = e.callcommand(b'filesdata', args).result()
485
508
486 # First object is an overall header.
509 # First object is an overall header.
@@ -619,3 +619,347 b' Server-side bookmark moves are reflected'
619 $ hg -R client-bookmarks bookmarks
619 $ hg -R client-bookmarks bookmarks
620 book-1 2:cd2534766bec
620 book-1 2:cd2534766bec
621 book-2 2:cd2534766bec
621 book-2 2:cd2534766bec
622
623 $ killdaemons.py
624
625 Let's set up a slightly more complicated server
626
627 $ hg init server-2
628 $ enablehttpv2 server-2
629 $ cd server-2
630 $ mkdir dir0 dir1
631 $ echo a0 > a
632 $ echo b0 > b
633 $ hg -q commit -A -m 'commit 0'
634 $ echo c0 > dir0/c
635 $ echo d0 > dir0/d
636 $ hg -q commit -A -m 'commit 1'
637 $ echo e0 > dir1/e
638 $ echo f0 > dir1/f
639 $ hg -q commit -A -m 'commit 2'
640 $ echo c1 > dir0/c
641 $ echo e1 > dir1/e
642 $ hg commit -m 'commit 3'
643 $ hg serve -p $HGPORT -d --pid-file hg.pid -E error.log
644 $ cat hg.pid > $DAEMON_PIDS
645
646 $ cd ..
647
648 Narrow clone only fetches some files
649
650 $ hg --config extensions.pullext=$TESTDIR/pullext.py --debug clone -U --include dir0/ http://localhost:$HGPORT/ client-narrow-0
651 using http://localhost:$HGPORT/
652 sending capabilities command
653 query 1; heads
654 sending 2 commands
655 sending command heads: {}
656 sending command known: {
657 'nodes': []
658 }
659 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
660 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
661 received frame(size=22; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
662 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
663 received frame(size=11; request=3; stream=2; streamflags=encoded; type=command-response; flags=continuation)
664 received frame(size=1; request=3; stream=2; streamflags=encoded; type=command-response; flags=continuation)
665 received frame(size=0; request=3; stream=2; streamflags=; type=command-response; flags=eos)
666 sending 1 commands
667 sending command changesetdata: {
668 'fields': set([
669 'bookmarks',
670 'parents',
671 'phase',
672 'revision'
673 ]),
674 'revisions': [
675 {
676 'heads': [
677 '\x97v_\xc3\xcdbO\xd1\xfa\x01v\x93,!\xff\xd1j\xdfC.'
678 ],
679 'roots': [],
680 'type': 'changesetdagrange'
681 }
682 ]
683 }
684 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
685 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
686 received frame(size=783; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
687 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
688 add changeset 3390ef850073
689 add changeset b709380892b1
690 add changeset 47fe012ab237
691 add changeset 97765fc3cd62
692 checking for updated bookmarks
693 sending 1 commands
694 sending command manifestdata: {
695 'fields': set([
696 'parents',
697 'revision'
698 ]),
699 'haveparents': True,
700 'nodes': [
701 '\x99/Gy\x02\x9a=\xf8\xd0fm\x00\xbb\x92OicN&A',
702 '|2 \x1a\xa3\xa1R\xa9\xe6\xa9"+?\xa8\xd0\xe3\x0f\xc2V\xe8',
703 '\x8d\xd0W<\x7f\xaf\xe2\x04F\xcc\xea\xac\x05N\xea\xa4x\x91M\xdb',
704 '113\x85\xf2!\x8b\x08^\xb2Z\x821\x1e*\xdd\x0e\xeb\x8c3'
705 ],
706 'tree': ''
707 }
708 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
709 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
710 received frame(size=967; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
711 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
712 sending 1 commands
713 sending command filesdata: {
714 'fields': set([
715 'parents',
716 'revision'
717 ]),
718 'haveparents': True,
719 'pathfilter': {
720 'include': [
721 'path:dir0'
722 ]
723 },
724 'revisions': [
725 {
726 'nodes': [
727 '3\x90\xef\x85\x00s\xfb\xc2\xf0\xdf\xff"D4,\x8e\x92)\x01:',
728 '\xb7\t8\x08\x92\xb1\x93\xc1\t\x1d:\x81\x7fp`R\xe3F\x82\x1b',
729 'G\xfe\x01*\xb27\xa8\xc7\xfc\x0cx\xf9\xf2mXf\xee\xf3\xf8%',
730 '\x97v_\xc3\xcdbO\xd1\xfa\x01v\x93,!\xff\xd1j\xdfC.'
731 ],
732 'type': 'changesetexplicit'
733 }
734 ]
735 }
736 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
737 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
738 received frame(size=449; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
739 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
740 updating the branch cache
741 new changesets 3390ef850073:97765fc3cd62
742 (sent 5 HTTP requests and * bytes; received * bytes in responses) (glob)
743
744 #if reporevlogstore
745 $ find client-narrow-0/.hg/store -type f -name '*.i' | sort
746 client-narrow-0/.hg/store/00changelog.i
747 client-narrow-0/.hg/store/00manifest.i
748 client-narrow-0/.hg/store/data/dir0/c.i
749 client-narrow-0/.hg/store/data/dir0/d.i
750 #endif
751
752 --exclude by itself works
753
754 $ hg --config extensions.pullext=$TESTDIR/pullext.py --debug clone -U --exclude dir0/ http://localhost:$HGPORT/ client-narrow-1
755 using http://localhost:$HGPORT/
756 sending capabilities command
757 query 1; heads
758 sending 2 commands
759 sending command heads: {}
760 sending command known: {
761 'nodes': []
762 }
763 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
764 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
765 received frame(size=22; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
766 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
767 received frame(size=11; request=3; stream=2; streamflags=encoded; type=command-response; flags=continuation)
768 received frame(size=1; request=3; stream=2; streamflags=encoded; type=command-response; flags=continuation)
769 received frame(size=0; request=3; stream=2; streamflags=; type=command-response; flags=eos)
770 sending 1 commands
771 sending command changesetdata: {
772 'fields': set([
773 'bookmarks',
774 'parents',
775 'phase',
776 'revision'
777 ]),
778 'revisions': [
779 {
780 'heads': [
781 '\x97v_\xc3\xcdbO\xd1\xfa\x01v\x93,!\xff\xd1j\xdfC.'
782 ],
783 'roots': [],
784 'type': 'changesetdagrange'
785 }
786 ]
787 }
788 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
789 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
790 received frame(size=783; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
791 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
792 add changeset 3390ef850073
793 add changeset b709380892b1
794 add changeset 47fe012ab237
795 add changeset 97765fc3cd62
796 checking for updated bookmarks
797 sending 1 commands
798 sending command manifestdata: {
799 'fields': set([
800 'parents',
801 'revision'
802 ]),
803 'haveparents': True,
804 'nodes': [
805 '\x99/Gy\x02\x9a=\xf8\xd0fm\x00\xbb\x92OicN&A',
806 '|2 \x1a\xa3\xa1R\xa9\xe6\xa9"+?\xa8\xd0\xe3\x0f\xc2V\xe8',
807 '\x8d\xd0W<\x7f\xaf\xe2\x04F\xcc\xea\xac\x05N\xea\xa4x\x91M\xdb',
808 '113\x85\xf2!\x8b\x08^\xb2Z\x821\x1e*\xdd\x0e\xeb\x8c3'
809 ],
810 'tree': ''
811 }
812 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
813 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
814 received frame(size=967; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
815 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
816 sending 1 commands
817 sending command filesdata: {
818 'fields': set([
819 'parents',
820 'revision'
821 ]),
822 'haveparents': True,
823 'pathfilter': {
824 'exclude': [
825 'path:dir0'
826 ],
827 'include': [
828 'path:.'
829 ]
830 },
831 'revisions': [
832 {
833 'nodes': [
834 '3\x90\xef\x85\x00s\xfb\xc2\xf0\xdf\xff"D4,\x8e\x92)\x01:',
835 '\xb7\t8\x08\x92\xb1\x93\xc1\t\x1d:\x81\x7fp`R\xe3F\x82\x1b',
836 'G\xfe\x01*\xb27\xa8\xc7\xfc\x0cx\xf9\xf2mXf\xee\xf3\xf8%',
837 '\x97v_\xc3\xcdbO\xd1\xfa\x01v\x93,!\xff\xd1j\xdfC.'
838 ],
839 'type': 'changesetexplicit'
840 }
841 ]
842 }
843 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
844 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
845 received frame(size=709; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
846 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
847 updating the branch cache
848 new changesets 3390ef850073:97765fc3cd62
849 (sent 5 HTTP requests and * bytes; received * bytes in responses) (glob)
850
851 #if reporevlogstore
852 $ find client-narrow-1/.hg/store -type f -name '*.i' | sort
853 client-narrow-1/.hg/store/00changelog.i
854 client-narrow-1/.hg/store/00manifest.i
855 client-narrow-1/.hg/store/data/a.i
856 client-narrow-1/.hg/store/data/b.i
857 client-narrow-1/.hg/store/data/dir1/e.i
858 client-narrow-1/.hg/store/data/dir1/f.i
859 #endif
860
861 Mixing --include and --exclude works
862
863 $ hg --config extensions.pullext=$TESTDIR/pullext.py --debug clone -U --include dir0/ --exclude dir0/c http://localhost:$HGPORT/ client-narrow-2
864 using http://localhost:$HGPORT/
865 sending capabilities command
866 query 1; heads
867 sending 2 commands
868 sending command heads: {}
869 sending command known: {
870 'nodes': []
871 }
872 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
873 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
874 received frame(size=22; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
875 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
876 received frame(size=11; request=3; stream=2; streamflags=encoded; type=command-response; flags=continuation)
877 received frame(size=1; request=3; stream=2; streamflags=encoded; type=command-response; flags=continuation)
878 received frame(size=0; request=3; stream=2; streamflags=; type=command-response; flags=eos)
879 sending 1 commands
880 sending command changesetdata: {
881 'fields': set([
882 'bookmarks',
883 'parents',
884 'phase',
885 'revision'
886 ]),
887 'revisions': [
888 {
889 'heads': [
890 '\x97v_\xc3\xcdbO\xd1\xfa\x01v\x93,!\xff\xd1j\xdfC.'
891 ],
892 'roots': [],
893 'type': 'changesetdagrange'
894 }
895 ]
896 }
897 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
898 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
899 received frame(size=783; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
900 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
901 add changeset 3390ef850073
902 add changeset b709380892b1
903 add changeset 47fe012ab237
904 add changeset 97765fc3cd62
905 checking for updated bookmarks
906 sending 1 commands
907 sending command manifestdata: {
908 'fields': set([
909 'parents',
910 'revision'
911 ]),
912 'haveparents': True,
913 'nodes': [
914 '\x99/Gy\x02\x9a=\xf8\xd0fm\x00\xbb\x92OicN&A',
915 '|2 \x1a\xa3\xa1R\xa9\xe6\xa9"+?\xa8\xd0\xe3\x0f\xc2V\xe8',
916 '\x8d\xd0W<\x7f\xaf\xe2\x04F\xcc\xea\xac\x05N\xea\xa4x\x91M\xdb',
917 '113\x85\xf2!\x8b\x08^\xb2Z\x821\x1e*\xdd\x0e\xeb\x8c3'
918 ],
919 'tree': ''
920 }
921 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
922 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
923 received frame(size=967; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
924 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
925 sending 1 commands
926 sending command filesdata: {
927 'fields': set([
928 'parents',
929 'revision'
930 ]),
931 'haveparents': True,
932 'pathfilter': {
933 'exclude': [
934 'path:dir0/c'
935 ],
936 'include': [
937 'path:dir0'
938 ]
939 },
940 'revisions': [
941 {
942 'nodes': [
943 '3\x90\xef\x85\x00s\xfb\xc2\xf0\xdf\xff"D4,\x8e\x92)\x01:',
944 '\xb7\t8\x08\x92\xb1\x93\xc1\t\x1d:\x81\x7fp`R\xe3F\x82\x1b',
945 'G\xfe\x01*\xb27\xa8\xc7\xfc\x0cx\xf9\xf2mXf\xee\xf3\xf8%',
946 '\x97v_\xc3\xcdbO\xd1\xfa\x01v\x93,!\xff\xd1j\xdfC.'
947 ],
948 'type': 'changesetexplicit'
949 }
950 ]
951 }
952 received frame(size=9; request=1; stream=2; streamflags=stream-begin; type=stream-settings; flags=eos)
953 received frame(size=11; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
954 received frame(size=160; request=1; stream=2; streamflags=encoded; type=command-response; flags=continuation)
955 received frame(size=0; request=1; stream=2; streamflags=; type=command-response; flags=eos)
956 updating the branch cache
957 new changesets 3390ef850073:97765fc3cd62
958 (sent 5 HTTP requests and * bytes; received * bytes in responses) (glob)
959
960 #if reporevlogstore
961 $ find client-narrow-2/.hg/store -type f -name '*.i' | sort
962 client-narrow-2/.hg/store/00changelog.i
963 client-narrow-2/.hg/store/00manifest.i
964 client-narrow-2/.hg/store/data/dir0/d.i
965 #endif
General Comments 0
You need to be logged in to leave comments. Login now