Skip to content

Commit

Permalink
Remove unnecessary calls to get_repo_for_repository()
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jun 8, 2018
1 parent 0ca83cb commit fa78aea
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 34 deletions.
3 changes: 1 addition & 2 deletions lib/galaxy/webapps/galaxy/controllers/admin_toolshed.py
Original file line number Diff line number Diff line change
Expand Up @@ -1634,10 +1634,9 @@ def update_to_changeset_revision(self, trans, **kwd):
repo_files_dir = os.path.abspath(os.path.join(tool_path, relative_install_dir, name))
else:
repo_files_dir = os.path.abspath(os.path.join(relative_install_dir, name))
repo = hg_util.get_repo_for_repository(trans.app, repo_path=repo_files_dir)
repository_clone_url = os.path.join(tool_shed_url, 'repos', owner, name)
hg_util.pull_repository(repo_files_dir, repository_clone_url, latest_ctx_rev)
hg_util.update_repository(repo, latest_ctx_rev)
hg_util.update_repository(repo_files_dir, latest_ctx_rev)
# Remove old Data Manager entries
if repository.includes_data_managers:
dmh = data_manager.DataManagerHandler(trans.app)
Expand Down
4 changes: 2 additions & 2 deletions lib/galaxy/webapps/tool_shed/api/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ def create_changeset_revision(self, trans, id, payload, **kwd):
"err_msg": "You do not have permission to update this repository.",
}

repo = hg_util.get_repo_for_repository(self.app, repository=repository)
repo_dir = repository.repo_path(self.app)

upload_point = commit_util.get_upload_point(repository, **kwd)
tip = repository.tip(self.app)
Expand Down Expand Up @@ -1117,7 +1117,7 @@ def create_changeset_revision(self, trans, id, payload, **kwd):
)
if ok:
# Update the repository files for browsing.
hg_util.update_repository(repo)
hg_util.update_repository(repo_dir)
# Get the new repository tip.
if tip == repository.tip(self.app):
trans.response.status = 400
Expand Down
6 changes: 3 additions & 3 deletions lib/galaxy/webapps/tool_shed/controllers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ def browse_repository(self, trans, id, **kwd):
status = kwd.get('status', 'done')
commit_message = escape(kwd.get('commit_message', 'Deleted selected files'))
repository = repository_util.get_repository_in_tool_shed(trans.app, id)
repo = hg_util.get_repo_for_repository(trans.app, repository=repository)
repo_path = repository.repo_path(trans.app)
# Update repository files for browsing.
hg_util.update_repository(repo)
hg_util.update_repository(repo_path)
changeset_revision = repository.tip(trans.app)
metadata = metadata_util.get_repository_metadata_by_repository_id_changeset_revision(trans.app,
id,
Expand Down Expand Up @@ -2410,7 +2410,7 @@ def select_files_to_delete(self, trans, id, **kwd):
message=commit_message)
suc.handle_email_alerts(trans.app, trans.request.host, repository)
# Update the repository files for browsing.
hg_util.update_repository(repo)
hg_util.update_repository(repo_dir)
# Get the new repository tip.
if tip == repository.tip(trans.app):
message += 'No changes to repository. '
Expand Down
3 changes: 1 addition & 2 deletions lib/galaxy/webapps/tool_shed/controllers/upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ def upload(self, trans, **kwd):
repository_id = kwd.get('repository_id', '')
repository = repository_util.get_repository_in_tool_shed(trans.app, repository_id)
repo_dir = repository.repo_path(trans.app)
repo = hg_util.get_repo_for_repository(trans.app, repo_path=repo_dir)
uncompress_file = util.string_as_bool(kwd.get('uncompress_file', 'true'))
remove_repo_files_not_in_tar = util.string_as_bool(kwd.get('remove_repo_files_not_in_tar', 'true'))
uploaded_file = None
Expand Down Expand Up @@ -230,7 +229,7 @@ def upload(self, trans, **kwd):
admin_only=admin_only)
if ok:
# Update the repository files for browsing.
hg_util.update_repository(repo)
hg_util.update_repository(repo_dir)
# Get the new repository tip.
if tip == repository.tip(trans.app):
message = 'No changes to repository. '
Expand Down
3 changes: 1 addition & 2 deletions lib/tool_shed/galaxy_install/install_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,9 +880,8 @@ def install_tool_shed_repository(self, tool_shed_repository, repo_info_dict, too
current_ctx_rev = changeset_revision_dict.get('ctx_rev', None)
if current_ctx_rev != ctx_rev:
repo_path = os.path.abspath(install_dir)
repo = hg_util.get_repo_for_repository(self.app, repo_path=repo_path)
hg_util.pull_repository(repo_path, repository_clone_url, current_changeset_revision)
hg_util.update_repository(repo, ctx_rev=current_ctx_rev)
hg_util.update_repository(repo_path, ctx_rev=current_ctx_rev)
self.__handle_repository_contents(tool_shed_repository=tool_shed_repository,
tool_path=tool_path,
repository_clone_url=repository_clone_url,
Expand Down
45 changes: 22 additions & 23 deletions lib/tool_shed/util/hg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ def add_changeset(repo_path, path_to_filename_in_archive):

def archive_repository_revision(app, repository, archive_dir, changeset_revision):
'''Create an un-versioned archive of a repository.'''
repo = get_repo_for_repository(app, repository=repository)
repo_path = repository.repo_path(app)
try:
subprocess.check_output(['hg', 'archive', '-r', changeset_revision, archive_dir], stderr=subprocess.STDOUT, cwd=repo.root)
subprocess.check_output(['hg', 'archive', '-r', changeset_revision, archive_dir], stderr=subprocess.STDOUT, cwd=repo_path)
except Exception as e:
error_message = "Error attempting to archive revision '%s' of repository '%s': %s" % (changeset_revision, repository.name, e)
if isinstance(e, subprocess.CalledProcessError):
Expand Down Expand Up @@ -88,25 +88,24 @@ def copy_file_from_manifest(repo, ctx, filename, dir):


def create_hgrc_file(app, repository):
# At this point, an entry for the repository is required to be in the hgweb.config
# file so we can call repository.repo_path( trans.app ). Since we support both
# http and https, we set push_ssl to False to override the default (which is True)
# in the mercurial api. The hg purge extension purges all files and directories
# not being tracked by mercurial in the current repository. It'll remove unknown
# files and empty directories. This is not currently used because it is not supported
# in the mercurial API.
repo = get_repo_for_repository(app, repository=repository)
fp = repo.opener('hgrc', 'wb')
fp.write('[paths]\n')
fp.write('default = .\n')
fp.write('default-push = .\n')
fp.write('[web]\n')
fp.write('allow_push = %s\n' % repository.user.username)
fp.write('name = %s\n' % repository.name)
fp.write('push_ssl = false\n')
fp.write('[extensions]\n')
fp.write('hgext.purge=')
fp.close()
# Since we support both http and https, we set `push_ssl` to False to
# override the default (which is True) in the Mercurial API.
# The hg purge extension purges all files and directories not being tracked
# by Mercurial in the current repository. It will remove unknown files and
# empty directories. This is not currently used because it is not supported
# in the Mercurial API.
repo_path = repository.repo_path(app)
hgrc_path = os.path.join(repo_path, '.hg', 'hgrc')
with open(hgrc_path, 'wb') as fp:
fp.write('[paths]\n')
fp.write('default = .\n')
fp.write('default-push = .\n')
fp.write('[web]\n')
fp.write('allow_push = %s\n' % repository.user.username)
fp.write('name = %s\n' % repository.name)
fp.write('push_ssl = false\n')
fp.write('[extensions]\n')
fp.write('hgext.purge=')


def get_changectx_for_changeset(repo, changeset_revision, **kwd):
Expand Down Expand Up @@ -356,7 +355,7 @@ def reversed_upper_bounded_changelog(repo, included_upper_bounds_changeset_revis
return reversed_lower_upper_bounded_changelog(repo, INITIAL_CHANGELOG_HASH, included_upper_bounds_changeset_revision)


def update_repository(repo, ctx_rev=None):
def update_repository(repo_path, ctx_rev=None):
"""
Update the cloned repository to changeset_revision. It is critical that the installed repository is updated to the desired
changeset_revision before metadata is set because the process for setting metadata uses the repository files on disk.
Expand All @@ -376,7 +375,7 @@ def update_repository(repo, ctx_rev=None):
if ctx_rev:
cmd.extend(['-r', ctx_rev])
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, cwd=repo.root)
subprocess.check_output(cmd, stderr=subprocess.STDOUT, cwd=repo_path)
except Exception as e:
error_message = 'Error updating repository: %s' % e
if isinstance(e, subprocess.CalledProcessError):
Expand Down

0 comments on commit fa78aea

Please sign in to comment.