Skip to content

Commit

Permalink
Consolidate use of clone_repository()
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jun 5, 2018
1 parent 17d7c0f commit a777c39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 3 additions & 6 deletions lib/galaxy/webapps/tool_shed/controllers/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import tempfile

import requests
from mercurial import commands

from galaxy import (
util,
Expand Down Expand Up @@ -65,11 +64,9 @@ def upload(self, trans, **kwd):
# Use mercurial clone to fetch repository, contents will then be copied over.
uploaded_directory = tempfile.mkdtemp()
repo_url = 'http%s' % url[len('hg'):]
repo_url = repo_url.encode('ascii', 'replace')
try:
commands.clone(hg_util.get_configured_ui(), repo_url, uploaded_directory)
except Exception as e:
message = 'Error uploading via mercurial clone: %s' % basic_util.to_html_string(str(e))
cloned_ok, error_message = hg_util.clone_repository(repo_url, uploaded_directory)
if not cloned_ok:
message = 'Error uploading via mercurial clone: %s' % error_message
status = 'error'
basic_util.remove_dir(uploaded_directory)
uploaded_directory = None
Expand Down
15 changes: 12 additions & 3 deletions lib/tool_shed/util/hg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
from datetime import datetime
from time import gmtime

from mercurial import cmdutil, commands, hg, ui
from mercurial import (
cmdutil,
commands,
hg,
ui
)

from tool_shed.util import basic_util

Expand All @@ -31,13 +36,17 @@ def archive_repository_revision(app, repository, archive_dir, changeset_revision
raise Exception(error_message)


def clone_repository(repository_clone_url, repository_file_dir, ctx_rev):
def clone_repository(repository_clone_url, repository_file_dir, ctx_rev=None):
"""
Clone the repository up to the specified changeset_revision. No subsequent revisions will be
present in the cloned repository.
"""
cmd = ['hg', 'clone']
if ctx_rev:
cmd.extend(['-r', ctx_rev])
cmd.extend([repository_clone_url, repository_file_dir])
try:
subprocess.check_output(['hg', 'clone', '-r', ctx_rev, repository_clone_url, repository_file_dir], stderr=subprocess.STDOUT)
subprocess.check_output(cmd, stderr=subprocess.STDOUT)
return True, None
except Exception as e:
error_message = 'Error cloning repository: %s' % e
Expand Down

0 comments on commit a777c39

Please sign in to comment.