Commits

Anonymous committed 7611929

Only create repository object when we really need them, preventing superfluous authorization prompts

  • Participants
  • Parent commits 801481d
  • Tags 0.1.2

Comments (0)

Files changed (2)

mercurialrecipe/__init__.py

 import os
 import logging
-from mercurial import commands, ui, hg, repo
+from mercurial import commands, ui, hg
 
 def get_repository(location):
-	if '://' not in location and not os.path.exists(location):
-		return VirtualRepo(location)
 	return hg.repository(ui.ui(), location)
 
-class VirtualRepo(repo.repository):
-	
-	def __init__(self, path):
-		self.path = "file:%s" % path
-	
-	def url(self):
-		return self.path
-
 class Recipe(object):
 	
 	def __init__(self, buildout, name, options):
 		self.options = options
 		self.options.setdefault('location', os.path.join(buildout.get('buildout').get('parts-directory'), name))
-		self.source = get_repository(self.options.get('repository'))
-		self.destination = get_repository(self.options.get('location'))
+		self.source = self.options.get('repository')
+		self.destination = self.options.get('location')
 		self.newest = options.get('newest', buildout.get('buildout').get('newest', 'true')).lower() != 'false'
 		self.log = logging.getLogger(name)
 	
 	def install(self):
-		self.log.info("Cloning repository %s to %s" % (self.source.url(), self.destination.url()))
-		commands.clone(ui.ui(), self.source, self.destination.url())
-		self.destination = get_repository(self.destination.url())
-		return self.options.get('location')
+		self.log.info("Cloning repository %s to %s" % (self.source, self.destination))
+		commands.clone(ui.ui(), get_repository(self.source), self.destination)
+		return self.destination
 	
 	def update(self):
 		if self.newest:
-			self.log.info("Pulling repository %s and updating %s" % (self.source.url(), self.destination.url()))
-			commands.pull(ui.ui(), self.destination, self.source.url(), update = True)
+			self.log.info("Pulling repository %s and updating %s" % (self.source, self.destination))
+			commands.pull(ui.ui(), get_repository(self.destination), self.source, update = True)
 
 setup(
 	name = 'MercurialRecipe',
-	version = '0.1.1',
+	version = '0.1.2',
 	description = 'zc.buildout recipe for cloning and/or pulling a Mercurial repository',
 	author = 'Tim Molendijk',
 	author_email = 'tim@timmolendijk.nl',