Skip to content

Commit

Permalink
Use Mercurial CLI instead of API for archive_repository_revision()
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jun 5, 2018
1 parent eb67e4a commit eaec9d2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
11 changes: 5 additions & 6 deletions lib/tool_shed/capsule/capsule_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,14 @@ def generate_repository_archive(self, repository, changeset_revision, work_dir):
tdah = attribute_handlers.ToolDependencyAttributeHandler(self.app, unpopulate=True)
file_type_str = basic_util.get_file_type_str(changeset_revision, self.file_type)
file_name = '%s-%s' % (repository.name, file_type_str)
return_code, error_message = hg_util.archive_repository_revision(self.app,
repository,
work_dir,
changeset_revision)
if return_code:
return None, error_message
try:
hg_util.archive_repository_revision(self.app, repository, work_dir, changeset_revision)
except Exception as e:
return None, str(e)
repository_archive_name = os.path.join(work_dir, file_name)
# Create a compressed tar archive that will contain only valid files and possibly altered dependency definition files.
repository_archive = tarfile.open(repository_archive_name, "w:%s" % self.file_type)
error_message = ''
for root, dirs, files in os.walk(work_dir):
if root.find('.hg') < 0 and root.find('hgrc') < 0:
for dir in dirs:
Expand Down
13 changes: 5 additions & 8 deletions lib/tool_shed/util/hg_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ def add_changeset(repo_ui, repo, 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=None, create=False)
options_dict = get_mercurial_default_options_dict('archive')
options_dict['rev'] = changeset_revision
error_message = ''
return_code = None
try:
return_code = commands.archive(get_configured_ui, repo, archive_dir, **options_dict)
subprocess.check_output(['hg', 'archive', '-r', changeset_revision, archive_dir], stderr=subprocess.STDOUT, cwd=repo.root)
except Exception as e:
error_message = "Error attempting to archive revision <b>%s</b> of repository %s: %s\nReturn code: %s\n" % \
(str(changeset_revision), str(repository.name), str(e), str(return_code))
error_message = "Error attempting to archive revision '%s' of repository '%s': %s" % (changeset_revision, repository.name, e)
if isinstance(e, subprocess.CalledProcessError):
error_message += "\nOutput was:\n%s" % e.output
log.exception(error_message)
return return_code, error_message
raise Exception(error_message)


def clone_repository(repository_clone_url, repository_file_dir, ctx_rev):
Expand Down

0 comments on commit eaec9d2

Please sign in to comment.