56 def readprofile(repo, profile, changeid): |
56 def readprofile(repo, profile, changeid): |
57 """Resolve the raw content of a sparse profile file.""" |
57 """Resolve the raw content of a sparse profile file.""" |
58 # TODO add some kind of cache here because this incurs a manifest |
58 # TODO add some kind of cache here because this incurs a manifest |
59 # resolve and can be slow. |
59 # resolve and can be slow. |
60 return repo.filectx(profile, changeid=changeid).data() |
60 return repo.filectx(profile, changeid=changeid).data() |
|
61 |
|
62 def patternsforrev(repo, rev): |
|
63 """Obtain sparse checkout patterns for the given rev. |
|
64 |
|
65 Returns a tuple of iterables representing includes, excludes, and |
|
66 patterns. |
|
67 """ |
|
68 # Feature isn't enabled. No-op. |
|
69 if not enabled: |
|
70 return set(), set(), [] |
|
71 |
|
72 raw = repo.vfs.tryread('sparse') |
|
73 if not raw: |
|
74 return set(), set(), [] |
|
75 |
|
76 if rev is None: |
|
77 raise error.Abort(_('cannot parse sparse patterns from working ' |
|
78 'directory')) |
|
79 |
|
80 includes, excludes, profiles = parseconfig(repo.ui, raw) |
|
81 ctx = repo[rev] |
|
82 |
|
83 if profiles: |
|
84 visited = set() |
|
85 while profiles: |
|
86 profile = profiles.pop() |
|
87 if profile in visited: |
|
88 continue |
|
89 |
|
90 visited.add(profile) |
|
91 |
|
92 try: |
|
93 raw = readprofile(repo, profile, rev) |
|
94 except error.ManifestLookupError: |
|
95 msg = ( |
|
96 "warning: sparse profile '%s' not found " |
|
97 "in rev %s - ignoring it\n" % (profile, ctx)) |
|
98 # experimental config: sparse.missingwarning |
|
99 if repo.ui.configbool( |
|
100 'sparse', 'missingwarning', True): |
|
101 repo.ui.warn(msg) |
|
102 else: |
|
103 repo.ui.debug(msg) |
|
104 continue |
|
105 |
|
106 pincludes, pexcludes, subprofs = parseconfig(repo.ui, raw) |
|
107 includes.update(pincludes) |
|
108 excludes.update(pexcludes) |
|
109 for subprofile in subprofs: |
|
110 profiles.append(subprofile) |
|
111 |
|
112 profiles = visited |
|
113 |
|
114 if includes: |
|
115 includes.add('.hg*') |
|
116 |
|
117 return includes, excludes, profiles |