##// END OF EJS Templates
shallowutil: introduce a helper function isenabled()...
Pulkit Goyal -
r40549:6f0b6905 default
parent child Browse files
Show More
@@ -216,6 +216,8 b" testedwith = 'ships-with-hg-core'"
216 216 repoclass = localrepo.localrepository
217 217 repoclass._basesupported.add(constants.SHALLOWREPO_REQUIREMENT)
218 218
219 isenabled = shallowutil.isenabled
220
219 221 def uisetup(ui):
220 222 """Wraps user facing Mercurial commands to swap them out with shallow
221 223 versions.
@@ -236,8 +238,7 b' def uisetup(ui):'
236 238
237 239 # Prevent 'hg manifest --all'
238 240 def _manifest(orig, ui, repo, *args, **opts):
239 if (constants.SHALLOWREPO_REQUIREMENT in repo.requirements
240 and opts.get('all')):
241 if (isenabled(repo) and opts.get('all')):
241 242 raise error.Abort(_("--all is not supported in a shallow repo"))
242 243
243 244 return orig(ui, repo, *args, **opts)
@@ -262,7 +263,7 b' def cloneshallow(orig, ui, repo, *args, '
262 263 if opts.get('shallow'):
263 264 repos = []
264 265 def pull_shallow(orig, self, *args, **kwargs):
265 if constants.SHALLOWREPO_REQUIREMENT not in self.requirements:
266 if not isenabled(self):
266 267 repos.append(self.unfiltered())
267 268 # set up the client hooks so the post-clone update works
268 269 setupclient(self.ui, self.unfiltered())
@@ -347,7 +348,7 b' def reposetup(ui, repo):'
347 348 ui.setconfig('hooks', 'commit.prefetch', wcpprefetch)
348 349
349 350 isserverenabled = ui.configbool('remotefilelog', 'server')
350 isshallowclient = constants.SHALLOWREPO_REQUIREMENT in repo.requirements
351 isshallowclient = isenabled(repo)
351 352
352 353 if isserverenabled and isshallowclient:
353 354 raise RuntimeError("Cannot be both a server and shallow client.")
@@ -396,7 +397,7 b' def onetimeclientsetup(ui):'
396 397
397 398 # prefetch files before update
398 399 def applyupdates(orig, repo, actions, wctx, mctx, overwrite, labels=None):
399 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
400 if isenabled(repo):
400 401 manifest = mctx.manifest()
401 402 files = []
402 403 for f, args, msg in actions['g']:
@@ -409,7 +410,7 b' def onetimeclientsetup(ui):'
409 410 # Prefetch merge checkunknownfiles
410 411 def checkunknownfiles(orig, repo, wctx, mctx, force, actions,
411 412 *args, **kwargs):
412 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
413 if isenabled(repo):
413 414 files = []
414 415 sparsematch = repo.maybesparsematch(mctx.rev())
415 416 for f, (m, actionargs, msg) in actions.iteritems():
@@ -428,7 +429,7 b' def onetimeclientsetup(ui):'
428 429 # Prefetch files before status attempts to look at their size and contents
429 430 def checklookup(orig, self, files):
430 431 repo = self._repo
431 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
432 if isenabled(repo):
432 433 prefetchfiles = []
433 434 for parent in self._parents:
434 435 for f in files:
@@ -441,7 +442,7 b' def onetimeclientsetup(ui):'
441 442
442 443 # Prefetch the logic that compares added and removed files for renames
443 444 def findrenames(orig, repo, matcher, added, removed, *args, **kwargs):
444 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
445 if isenabled(repo):
445 446 files = []
446 447 parentctx = repo['.']
447 448 for f in removed:
@@ -454,7 +455,7 b' def onetimeclientsetup(ui):'
454 455 # prefetch files before mergecopies check
455 456 def computenonoverlap(orig, repo, c1, c2, *args, **kwargs):
456 457 u1, u2 = orig(repo, c1, c2, *args, **kwargs)
457 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
458 if isenabled(repo):
458 459 m1 = c1.manifest()
459 460 m2 = c2.manifest()
460 461 files = []
@@ -486,7 +487,7 b' def onetimeclientsetup(ui):'
486 487 def computeforwardmissing(orig, a, b, match=None):
487 488 missing = list(orig(a, b, match=match))
488 489 repo = a._repo
489 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
490 if isenabled(repo):
490 491 mb = b.manifest()
491 492
492 493 files = []
@@ -513,7 +514,7 b' def onetimeclientsetup(ui):'
513 514 # repo can be None when running in chg:
514 515 # - at startup, reposetup was called because serve is not norepo
515 516 # - a norepo command like "help" is called
516 if repo and constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
517 if repo and isenabled(repo):
517 518 repo.fileservice.close()
518 519 extensions.wrapfunction(dispatch, 'runcommand', runcommand)
519 520
@@ -525,7 +526,7 b' def onetimeclientsetup(ui):'
525 526
526 527 # prevent strip from stripping remotefilelogs
527 528 def _collectbrokencsets(orig, repo, files, striprev):
528 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
529 if isenabled(repo):
529 530 files = list([f for f in files if not repo.shallowmatch(f)])
530 531 return orig(repo, files, striprev)
531 532 extensions.wrapfunction(repair, '_collectbrokencsets', _collectbrokencsets)
@@ -576,16 +577,14 b' def onetimeclientsetup(ui):'
576 577 def filectx(orig, self, path, fileid=None, filelog=None):
577 578 if fileid is None:
578 579 fileid = self.filenode(path)
579 if (constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements and
580 self._repo.shallowmatch(path)):
580 if (isenabled(self._repo) and self._repo.shallowmatch(path)):
581 581 return remotefilectx.remotefilectx(self._repo, path,
582 582 fileid=fileid, changectx=self, filelog=filelog)
583 583 return orig(self, path, fileid=fileid, filelog=filelog)
584 584 extensions.wrapfunction(context.changectx, 'filectx', filectx)
585 585
586 586 def workingfilectx(orig, self, path, filelog=None):
587 if (constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements and
588 self._repo.shallowmatch(path)):
587 if (isenabled(self._repo) and self._repo.shallowmatch(path)):
589 588 return remotefilectx.remoteworkingfilectx(self._repo,
590 589 path, workingctx=self, filelog=filelog)
591 590 return orig(self, path, filelog=filelog)
@@ -594,7 +593,7 b' def onetimeclientsetup(ui):'
594 593 # prefetch required revisions before a diff
595 594 def trydiff(orig, repo, revs, ctx1, ctx2, modified, added, removed,
596 595 copy, getfilectx, *args, **kwargs):
597 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
596 if isenabled(repo):
598 597 prefetch = []
599 598 mf1 = ctx1.manifest()
600 599 for fname in modified + added + removed:
@@ -652,7 +651,7 b' def getrenamedfn(repo, endrev=None):'
652 651 return getrenamed
653 652
654 653 def walkfilerevs(orig, repo, match, follow, revs, fncache):
655 if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
654 if not isenabled(repo):
656 655 return orig(repo, match, follow, revs, fncache)
657 656
658 657 # remotefilelog's can't be walked in rev order, so throw.
@@ -692,7 +691,7 b' def filelogrevset(orig, repo, subset, x)'
692 691 a slower, more accurate result, use ``file()``.
693 692 """
694 693
695 if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
694 if not isenabled(repo):
696 695 return orig(repo, subset, x)
697 696
698 697 # i18n: "filelog" is a keyword
@@ -800,7 +799,7 b' def gcclient(ui, cachepath):'
800 799 # Protect against any repo or config changes that have happened since
801 800 # this repo was added to the repos file. We'd rather this loop succeed
802 801 # and too much be deleted, than the loop fail and nothing gets deleted.
803 if constants.SHALLOWREPO_REQUIREMENT not in repo.requirements:
802 if not isenabled(repo):
804 803 continue
805 804
806 805 if not util.safehasattr(repo, 'name'):
@@ -849,7 +848,7 b' def gcclient(ui, cachepath):'
849 848 ui.warn(_("warning: no valid repos in repofile\n"))
850 849
851 850 def log(orig, ui, repo, *pats, **opts):
852 if constants.SHALLOWREPO_REQUIREMENT not in repo.requirements:
851 if not isenabled(repo):
853 852 return orig(ui, repo, *pats, **opts)
854 853
855 854 follow = opts.get('follow')
@@ -910,7 +909,7 b' def wcpprefetch(ui, repo, **kwargs):'
910 909 """Prefetches in background revisions specified by bgprefetchrevs revset.
911 910 Does background repack if backgroundrepack flag is set in config.
912 911 """
913 shallow = constants.SHALLOWREPO_REQUIREMENT in repo.requirements
912 shallow = isenabled(repo)
914 913 bgprefetchrevs = ui.config('remotefilelog', 'bgprefetchrevs')
915 914 isready = readytofetch(repo)
916 915
@@ -932,7 +931,7 b' def wcpprefetch(ui, repo, **kwargs):'
932 931 def pull(orig, ui, repo, *pats, **opts):
933 932 result = orig(ui, repo, *pats, **opts)
934 933
935 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
934 if isenabled(repo):
936 935 # prefetch if it's configured
937 936 prefetchrevset = ui.config('remotefilelog', 'pullprefetch')
938 937 bgrepack = repo.ui.configbool('remotefilelog', 'backgroundrepack')
@@ -972,7 +971,7 b' def exchangepull(orig, repo, remote, *ar'
972 971 return orig(repo, remote, *args, **kwargs)
973 972
974 973 def _fileprefetchhook(repo, revs, match):
975 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
974 if isenabled(repo):
976 975 allfiles = []
977 976 for rev in revs:
978 977 if rev == nodemod.wdirrev or rev is None:
@@ -1068,7 +1067,7 b' def prefetch(ui, repo, *pats, **opts):'
1068 1067
1069 1068 Return 0 on success.
1070 1069 """
1071 if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
1070 if not isenabled(repo):
1072 1071 raise error.Abort(_("repo is not shallow"))
1073 1072
1074 1073 opts = resolveprefetchopts(ui, opts)
@@ -92,7 +92,7 b' def debugindex(orig, ui, repo, file_=Non'
92 92 if (opts.get('changelog') or
93 93 opts.get('manifest') or
94 94 opts.get('dir') or
95 not constants.SHALLOWREPO_REQUIREMENT in repo.requirements or
95 not shallowutil.isenabled(repo) or
96 96 not repo.shallowmatch(file_)):
97 97 return orig(ui, repo, file_, **opts)
98 98
@@ -139,7 +139,7 b' def debugindex(orig, ui, repo, file_=Non'
139 139
140 140 def debugindexdot(orig, ui, repo, file_):
141 141 """dump an index DAG as a graphviz dot file"""
142 if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
142 if not shallowutil.isenabled(repo):
143 143 return orig(ui, repo, file_)
144 144
145 145 r = buildtemprevlog(repo, os.path.basename(file_)[:-2])
@@ -132,7 +132,7 b' def onetimesetup(ui):'
132 132 def _walkstreamfiles(orig, repo):
133 133 if state.shallowremote:
134 134 # if we are shallow ourselves, stream our local commits
135 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
135 if shallowutil.isenabled(repo):
136 136 striplen = len(repo.store.path) + 1
137 137 readdir = repo.store.rawvfs.readdir
138 138 visit = [os.path.join(repo.store.path, 'data')]
@@ -166,7 +166,7 b' def onetimesetup(ui):'
166 166 continue
167 167 yield x
168 168
169 elif constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
169 elif shallowutil.isenabled(repo):
170 170 # don't allow cloning from a shallow repo to a full repo
171 171 # since it would require fetching every version of every
172 172 # file in order to create the revlogs.
@@ -193,8 +193,8 b' def onetimesetup(ui):'
193 193 # expose remotefilelog capabilities
194 194 def _capabilities(orig, repo, proto):
195 195 caps = orig(repo, proto)
196 if ((constants.SHALLOWREPO_REQUIREMENT in repo.requirements or
197 ui.configbool('remotefilelog', 'server'))):
196 if (shallowutil.isenabled(repo) or ui.configbool('remotefilelog',
197 'server')):
198 198 if isinstance(proto, _sshv1server):
199 199 # legacy getfiles method which only works over ssh
200 200 caps.append(constants.NETWORK_CAP_LEGACY_SSH_GETFILES)
@@ -278,7 +278,7 b' def getfile(repo, proto, file, node):'
278 278 data is a compressed blob with revlog flag and ancestors information. See
279 279 createfileblob for its content.
280 280 """
281 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
281 if shallowutil.isenabled(repo):
282 282 return '1\0' + _('cannot fetch remote files from shallow repo')
283 283 cachepath = repo.ui.config("remotefilelog", "servercachepath")
284 284 if not cachepath:
@@ -291,7 +291,7 b' def getfile(repo, proto, file, node):'
291 291 def getfiles(repo, proto):
292 292 """A server api for requesting particular versions of particular files.
293 293 """
294 if constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
294 if shallowutil.isenabled(repo):
295 295 raise error.Abort(_('cannot fetch remote files from shallow repo'))
296 296 if not isinstance(proto, _sshv1server):
297 297 raise error.Abort(_('cannot fetch remote files over non-ssh protocol'))
@@ -54,7 +54,7 b' def shallowgroup(cls, self, nodelist, rl'
54 54
55 55 class shallowcg1packer(changegroup.cgpacker):
56 56 def generate(self, commonrevs, clnodes, fastpathlinkrev, source):
57 if constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements:
57 if shallowutil.isenabled(self._repo):
58 58 fastpathlinkrev = False
59 59
60 60 return super(shallowcg1packer, self).generate(commonrevs, clnodes,
@@ -69,7 +69,7 b' class shallowcg1packer(changegroup.cgpac'
69 69 linknodes, commonrevs, source = args
70 70 except ValueError:
71 71 commonrevs, source, mfdicts, fastpathlinkrev, fnodes, clrevs = args
72 if constants.SHALLOWREPO_REQUIREMENT in self._repo.requirements:
72 if shallowutil.isenabled(self._repo):
73 73 repo = self._repo
74 74 if isinstance(repo, bundlerepo.bundlerepository):
75 75 # If the bundle contains filelogs, we can't pull from it, since
@@ -91,7 +91,7 b' class shallowcg1packer(changegroup.cgpac'
91 91
92 92 def shouldaddfilegroups(self, source):
93 93 repo = self._repo
94 if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
94 if not shallowutil.isenabled(repo):
95 95 return AllFiles
96 96
97 97 if source == "push" or source == "bundle":
@@ -139,7 +139,7 b' class shallowcg1packer(changegroup.cgpac'
139 139 yield delta
140 140
141 141 def makechangegroup(orig, repo, outgoing, version, source, *args, **kwargs):
142 if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
142 if not shallowutil.isenabled(repo):
143 143 return orig(repo, outgoing, version, source, *args, **kwargs)
144 144
145 145 original = repo.shallowmatch
@@ -168,7 +168,7 b' def makechangegroup(orig, repo, outgoing'
168 168 repo.shallowmatch = original
169 169
170 170 def addchangegroupfiles(orig, repo, source, revmap, trp, expectedfiles, *args):
171 if not constants.SHALLOWREPO_REQUIREMENT in repo.requirements:
171 if not shallowutil.isenabled(repo):
172 172 return orig(repo, source, revmap, trp, expectedfiles, *args)
173 173
174 174 files = 0
@@ -30,6 +30,10 b' from . import constants'
30 30 if not pycompat.iswindows:
31 31 import grp
32 32
33 def isenabled(repo):
34 """returns whether the repository is remotefilelog enabled or not"""
35 return constants.SHALLOWREPO_REQUIREMENT in repo.requirements
36
33 37 def getcachekey(reponame, file, id):
34 38 pathhash = hashlib.sha1(file).hexdigest()
35 39 return os.path.join(reponame, pathhash[:2], pathhash[2:], id)
General Comments 0
You need to be logged in to leave comments. Login now