Skip to content

Commit

Permalink
Use Mercurial CLI instead of API for remove_file()
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jun 8, 2018
1 parent bd31c3e commit 0ca83cb
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/galaxy/webapps/tool_shed/controllers/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@ def select_files_to_delete(self, trans, id, **kwd):
tip = repository.tip(trans.app)
for selected_file in selected_files_to_delete:
try:
hg_util.remove_file(repo.ui, repo, selected_file, force=True)
hg_util.remove_file(repo_dir, selected_file, force=True)
except Exception as e:
log.debug("Error removing the following file using the mercurial API:\n %s" % str(selected_file))
log.debug("The error was: %s" % str(e))
Expand Down
2 changes: 1 addition & 1 deletion lib/tool_shed/util/commit_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def handle_directory_changes(app, host, username, repository, full_path, filenam
# Remove files in the repository (relative to the upload point) that are not in
# the uploaded archive.
try:
hg_util.remove_file(repo.ui, repo, repo_file, force=True)
hg_util.remove_file(repo_path, repo_file, force=True)
except Exception as e:
log.debug("Error removing files using the mercurial API, so trying a different approach, the error was: %s" % str(e))
relative_selected_file = repo_file.split('repo_%d' % repository.id)[1].lstrip('/')
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 @@ -6,7 +6,6 @@
from time import gmtime

from mercurial import (
commands,
hg,
ui
)
Expand Down Expand Up @@ -309,8 +308,18 @@ def pull_repository(repo_path, repository_clone_url, ctx_rev):
raise Exception(error_message)


def remove_file(repo_ui, repo, selected_file, force=True):
commands.remove(repo_ui, repo, selected_file, force=force)
def remove_file(repo_path, selected_file, force=True):
cmd = ['hg', 'remove']
if force:
cmd.append('--force')
cmd.append(selected_file)
try:
subprocess.check_output(cmd, stderr=subprocess.STDOUT, cwd=repo_path)
except Exception as e:
error_message = "Error removing file '%s': %s" % (selected_file, e)
if isinstance(e, subprocess.CalledProcessError):
error_message += "\nOutput was:\n%s" % e.output
raise Exception(error_message)


def reversed_lower_upper_bounded_changelog(repo, excluded_lower_bounds_changeset_revision, included_upper_bounds_changeset_revision):
Expand Down

0 comments on commit 0ca83cb

Please sign in to comment.