1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/changeset/04acee047c2c/ changeset: 04acee047c2c user: greg date: 2011-11-15 17:51:05 summary: Use mercurial's purge extension to remove untracked repository files and empty directories, and fix a bug related to deleting repository files. affected #: 2 files diff -r bdf334e6017658b0864ae38552d103018d956caa -r 04acee047c2c585730e9a8266de81d25d5c25d7f lib/galaxy/webapps/community/controllers/common.py --- a/lib/galaxy/webapps/community/controllers/common.py +++ b/lib/galaxy/webapps/community/controllers/common.py @@ -589,36 +589,36 @@ elif status_and_file_name.startswith( 'M' ) or status_and_file_name.startswith( 'A' ) or status_and_file_name.startswith( 'R' ): files_to_commit.append( os.path.abspath( os.path.join( repo_dir, status_and_file_name.split()[1] ) ) ) # We may have files on disk in the repo directory that aren't being tracked, so they must be removed. - cmd = 'hg status' - tmp_name = tempfile.NamedTemporaryFile().name - tmp_stdout = open( tmp_name, 'wb' ) + # We'll use mercurial's purge extension to do this. Using this extension requires the following entry + # in the repository's hgrc file which was not required for some time, so we'll add it if it's missing. + # [extensions] + # hgext.purge= + lines = repo.opener( 'hgrc', 'rb' ).readlines() + if not '[extensions]\n' in lines: + # No extensions have been added at all, so just append to the file. + fp = repo.opener( 'hgrc', 'a' ) + fp.write( '[extensions]\n' ) + fp.write( 'hgext.purge=\n' ) + fp.close() + elif not 'hgext.purge=\n' in lines: + # The file includes and [extensions] section, but we need to add the + # purge extension. + fp = repo.opener( 'hgrc', 'wb' ) + for line in lines: + if line.startswith( '[extensions]' ): + fp.write( line ) + fp.write( 'hgext.purge=\n' ) + else: + fp.write( line ) + fp.close() + cmd = 'hg purge' os.chdir( repo_dir ) - proc = subprocess.Popen( args=cmd, shell=True, stdout=tmp_stdout.fileno() ) - returncode = proc.wait() + proc = subprocess.Popen( args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT ) + return_code = proc.wait() os.chdir( current_working_dir ) - tmp_stdout.close() - if returncode == 0: - for i, line in enumerate( open( tmp_name ) ): - if line.startswith( '?' ) or line.startswith( 'I' ): - files_to_remove_from_disk.append( os.path.abspath( os.path.join( repo_dir, line.split()[1] ) ) ) - elif line.startswith( 'M' ) or line.startswith( 'A' ) or line.startswith( 'R' ): - files_to_commit.append( os.path.abspath( os.path.join( repo_dir, line.split()[1] ) ) ) - for full_path in files_to_remove_from_disk: - # We'll remove all files that are not tracked or ignored. - if os.path.isdir( full_path ): - try: - os.rmdir( full_path ) - except OSError, e: - # The directory is not empty - pass - elif os.path.isfile( full_path ): - os.remove( full_path ) - dir = os.path.split( full_path )[0] - try: - os.rmdir( dir ) - except OSError, e: - # The directory is not empty - pass + if return_code != 0: + output = proc.stdout.read( 32768 ) + log.debug( 'hg purge failed in repository directory %s, reason: %s' % ( repo_dir, output ) ) if files_to_commit: if not commit_message: commit_message = 'Committed changes to: %s' % ', '.join( files_to_commit ) diff -r bdf334e6017658b0864ae38552d103018d956caa -r 04acee047c2c585730e9a8266de81d25d5c25d7f lib/galaxy/webapps/community/controllers/repository.py --- a/lib/galaxy/webapps/community/controllers/repository.py +++ b/lib/galaxy/webapps/community/controllers/repository.py @@ -1042,13 +1042,11 @@ def __create_hgrc_file( self, 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. - # Create a .hg/hgrc file that looks something like this: - # [web] - # allow_push = test - # name = convert_characters1 - # push_ssl = False # 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 used in the update_for_browsing() method. repo = hg.repository( get_configured_ui(), path=repository.repo_path ) fp = repo.opener( 'hgrc', 'wb' ) fp.write( '[paths]\n' ) @@ -1058,6 +1056,8 @@ 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() @web.expose def browse_repository( self, trans, id, **kwd ): @@ -1150,7 +1150,7 @@ tip = repository.tip for selected_file in selected_files_to_delete: try: - commands.remove( repo.ui, repo, repo_file, force=True ) + commands.remove( repo.ui, repo, selected_file, force=True ) except Exception, e: # I never have a problem with commands.remove on a Mac, but in the test/production # tool shed environment, it throws an exception whenever I delete all files from a Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.