2011-06-23 7 views
2

すべての絶対svn:externals URLをリポジトリ全体の相対URLに変換したいとします。リポジトリのトランクにあるすべてのsvn:externalsを書き換えるスクリプト/ユーティリティ

また、tip in the svn:externals docs(「あなたは真剣にリビジョン番号を使用することを検討する必要があります...」)、リポジトリ全体のさまざまな場所で外部の新しいリビジョンを定期的に取得する必要があるかもしれません。

多くのsvn:externalsプロパティをプログラムで更新するにはどうすればよいですか?

私のソリューションは以下の通りです。

答えて

3

はここでSVNの単一ラインから部品を抽出するために私のクラスです:外観プロパティ:

from urlparse import urlparse 
import re 
class SvnExternalsLine: 
    '''Consult https://subversion.apache.org/docs/release-notes/1.5.html#externals for parsing algorithm. 
    The old svn:externals format consists of: 
     <local directory> [revision] <absolute remote URL> 

    The NEW svn:externals format consists of: 
     [revision] <absolute or relative remote URL> <local directory> 

    Therefore, "relative" remote paths always come *after* the local path. 
    One complication is the possibility of local paths with spaces. 
    We just assume that the remote path cannot have spaces, and treat all other 
    tokens (except the revision specifier) as part of the local path. 
    ''' 

    REVISION_ARGUMENT_REGEXP = re.compile("-r(\d+)") 

    def __init__(self, original_line): 
     self.original_line = original_line 

     self.pinned_revision_number = None 
     self.repo_url = None 
     self.local_pathname_components = [] 

     for token in self.original_line.split(): 

      revision_match = self.REVISION_ARGUMENT_REGEXP.match(token) 
      if revision_match: 
       self.pinned_revision_number = int(revision_match.group(1)) 
      elif urlparse(token).scheme or any(map(lambda p: token.startswith(p), ["^", "//", "/", "../"])): 
       self.repo_url = token 
      else: 
       self.local_pathname_components.append(token) 

    # --------------------------------------------------------------------- 
    def constructLine(self): 
     '''Reconstruct the externals line in the Subversion 1.5+ format''' 

     tokens = [] 

     # Update the revision specifier if one existed 
     if self.pinned_revision_number is not None: 
      tokens.append("-r%d" % (self.pinned_revision_number)) 

     tokens.append(self.repo_url) 
     tokens.extend(self.local_pathname_components) 

     if self.repo_url is None: 
      raise Exception("Found a bad externals property: %s; Original definition: %s" % (str(tokens), repr(self.original_line))) 

     return " ".join(tokens) 

私はSVNを持つすべてのディレクトリを再帰的に反復するpysvnライブラリを使用:externalsプロパティは、スプリットそのプロパティ値を改行で区切り、解析されたSvnExternalsLineに従って各行に作用します。

プロセスは、リポジトリのローカル・チェックアウトで実行する必要があります。

client.propget("svn:externals", base_checkout_path, recurse=True) 

反復は、この関数の戻り値によって、および各ディレクトリのプロパティを変更した後、

client.propset("svn:externals", new_externals_property, path) 
:ここでは外観を取得するために使用することができますか pysvnpropget)です
関連する問題