Skip to content

Commit

Permalink
Make fetch_new() a class method.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed Mar 22, 2019
1 parent 3690943 commit a829362
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/pip/_internal/vcs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,8 @@ def compare_urls(self, url1, url2):
"""
return (self.normalize_url(url1) == self.normalize_url(url2))

def fetch_new(self, dest, url, rev_options):
@classmethod
def fetch_new(cls, dest, url, rev_options):
"""
Fetch a revision from a repository, in the case that this is the
first fetch from the repository.
Expand Down
5 changes: 3 additions & 2 deletions src/pip/_internal/vcs/bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def export(self, location):
show_stdout=False,
)

def fetch_new(self, dest, url, rev_options):
@classmethod
def fetch_new(cls, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Checking out %s%s to %s',
Expand All @@ -55,7 +56,7 @@ def fetch_new(self, dest, url, rev_options):
display_path(dest),
)
cmd_args = ['branch', '-q'] + rev_options.to_args() + [url, dest]
self.run_command(cmd_args)
cls.run_command(cmd_args)

def switch(self, dest, url, rev_options):
self.run_command(['switch', url], cwd=dest)
Expand Down
17 changes: 9 additions & 8 deletions src/pip/_internal/vcs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,35 +201,36 @@ def is_commit_id_equal(cls, dest, name):

return cls.get_revision(dest) == name

def fetch_new(self, dest, url, rev_options):
@classmethod
def fetch_new(cls, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Cloning %s%s to %s', redact_password_from_url(url),
rev_display, display_path(dest),
)
self.run_command(['clone', '-q', url, dest])
cls.run_command(['clone', '-q', url, dest])

if rev_options.rev:
# Then a specific revision was requested.
rev_options = self.resolve_revision(dest, url, rev_options)
rev_options = cls.resolve_revision(dest, url, rev_options)
branch_name = getattr(rev_options, 'branch_name', None)
if branch_name is None:
# Only do a checkout if the current commit id doesn't match
# the requested revision.
if not self.is_commit_id_equal(dest, rev_options.rev):
if not cls.is_commit_id_equal(dest, rev_options.rev):
cmd_args = ['checkout', '-q'] + rev_options.to_args()
self.run_command(cmd_args, cwd=dest)
elif self.get_current_branch(dest) != branch_name:
cls.run_command(cmd_args, cwd=dest)
elif cls.get_current_branch(dest) != branch_name:
# Then a specific branch was requested, and that branch
# is not yet checked out.
track_branch = 'origin/{}'.format(branch_name)
cmd_args = [
'checkout', '-b', branch_name, '--track', track_branch,
]
self.run_command(cmd_args, cwd=dest)
cls.run_command(cmd_args, cwd=dest)

#: repo may contain submodules
self.update_submodules(dest)
cls.update_submodules(dest)

def switch(self, dest, url, rev_options):
self.run_command(['config', 'remote.origin.url', url], cwd=dest)
Expand Down
7 changes: 4 additions & 3 deletions src/pip/_internal/vcs/mercurial.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ def export(self, location):
['archive', location], show_stdout=False, cwd=temp_dir.path
)

def fetch_new(self, dest, url, rev_options):
@classmethod
def fetch_new(cls, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Cloning hg %s%s to %s',
url,
rev_display,
display_path(dest),
)
self.run_command(['clone', '--noupdate', '-q', url, dest])
cls.run_command(['clone', '--noupdate', '-q', url, dest])
cmd_args = ['update', '-q'] + rev_options.to_args()
self.run_command(cmd_args, cwd=dest)
cls.run_command(cmd_args, cwd=dest)

def switch(self, dest, url, rev_options):
repo_config = os.path.join(dest, self.dirname, 'hgrc')
Expand Down
5 changes: 3 additions & 2 deletions src/pip/_internal/vcs/subversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def export(self, location):
cmd_args = ['export'] + rev_options.to_args() + [url, location]
self.run_command(cmd_args, show_stdout=False)

def fetch_new(self, dest, url, rev_options):
@classmethod
def fetch_new(cls, dest, url, rev_options):
rev_display = rev_options.to_display()
logger.info(
'Checking out %s%s to %s',
Expand All @@ -55,7 +56,7 @@ def fetch_new(self, dest, url, rev_options):
display_path(dest),
)
cmd_args = ['checkout', '-q'] + rev_options.to_args() + [url, dest]
self.run_command(cmd_args)
cls.run_command(cmd_args)

def switch(self, dest, url, rev_options):
cmd_args = ['switch'] + rev_options.to_args() + [url, dest]
Expand Down

0 comments on commit a829362

Please sign in to comment.