[py-svn] r51470 - py/branch/guido-svn-auth/py/path/svn

hpk at codespeak.net hpk at codespeak.net
Thu Feb 14 08:44:23 CET 2008


Author: hpk
Date: Thu Feb 14 08:44:21 2008
New Revision: 51470

Modified:
   py/branch/guido-svn-auth/py/path/svn/wccommand.py
Log:
remove redundancy in svn auth handling 


Modified: py/branch/guido-svn-auth/py/path/svn/wccommand.py
==============================================================================
--- py/branch/guido-svn-auth/py/path/svn/wccommand.py	(original)
+++ py/branch/guido-svn-auth/py/path/svn/wccommand.py	Thu Feb 14 08:44:21 2008
@@ -71,6 +71,18 @@
     def __str__(self):
         return str(self.localpath)
 
+    def _makeauthoptions(self, auth):
+        if auth is None:
+            auth = self._auth 
+        if auth is None:
+            return ''
+        return str(auth) 
+
+    def _authsvn(self, cmd, args=None, auth=None):
+        args = args and list(args) or [] 
+        args.append(self._makeauthoptions(auth)) 
+        return self._svn(cmd, *args) 
+        
     def _svn(self, cmd, *args):
         l = ['svn %s' % cmd]
         args = [self._escape(item) for item in args]
@@ -104,12 +116,7 @@
 
     def switch(self, url, auth=None):
         """ switch to given URL. """
-        args = []
-        if auth is not None:
-            args.append(str(auth))
-        elif self._auth is not None:
-            args.append(str(self._auth))
-        self._svn('switch', url, *args)
+        self._authsvn('switch', url, [], auth=auth)
 
     def checkout(self, url=None, rev=None, auth=None):
         """ checkout from url to local wcpath. """
@@ -125,20 +132,12 @@
                 url += "@%d" % rev
             else:
                 args.append('-r' + str(rev))
-        if auth is not None:
-            args.append(str(auth))
-        elif self._auth is not None:
-            args.append(str(self._auth))
-        self._svn('co', url, *args)
+        args.append(url)
+        self._authsvn('co', args, auth=auth)
 
     def update(self, rev = 'HEAD', auth=None):
         """ update working copy item to given revision. (None -> HEAD). """
-        args = []
-        if auth is not None:
-            args.append(str(auth))
-        elif self._auth is not None:
-            args.append(str(self._auth))
-        self._svn('up -r %s' % rev, *args)
+        self._authsvn('up', ['-r', rev], auth=auth)
 
     def write(self, content, mode='wb'):
         """ write content into local filesystem wc. """
@@ -216,24 +215,14 @@
 
     def lock(self, auth=None):
         """ set a lock (exclusive) on the resource """
-        args = []
-        if auth is not None:
-            args.append(str(auth))
-        elif self._auth is not None:
-            args.append(str(self._auth))
-        out = self._svn('lock', *args).strip()
+        out = self._authsvn('lock', auth=auth).strip()
         if not out:
             # warning or error, raise exception
             raise Exception(out[4:])
     
     def unlock(self, auth=None):
         """ unset a previously set lock """
-        args = []
-        if auth is not None:
-            args.append(str(auth))
-        elif self._auth is not None:
-            args.append(str(self._auth))
-        out = self._svn('unlock', *args).strip()
+        out = self._authsvn('unlock', auth=auth).strip()
         if out.startswith('svn:'):
             # warning or error, raise exception
             raise Exception(out[4:])
@@ -359,15 +348,10 @@
         """ return a diff of the current path against revision rev (defaulting
             to the last one).
         """
-        if rev is None:
-            out = self._svn('diff')
-        else:
-            args = []
-            if auth is not None:
-                args.append(str(auth))
-            elif self._auth is not None:
-                args.append(str(self._auth))
-            out = self._svn('diff -r %d' % rev, *args)
+        args = []
+        if rev is not None:
+            args.append("-r %d" % rev)
+        out = self._authsvn('diff', args, auth=auth) 
         return out
 
     def blame(self):
@@ -395,12 +379,7 @@
         cmd = 'commit -m "%s" --force-log' % (msg.replace('"', '\\"'),)
         if not rec:
             cmd += ' -N'
-        args = []
-        if auth is not None:
-            args.append(str(auth))
-        elif self._auth is not None:
-            args.append(str(self._auth))
-        out = self._svn(cmd, *args)
+        out = self._authsvn(cmd, auth=auth) 
         try:
             del cache.info[self]
         except KeyError:
@@ -571,14 +550,7 @@
         verbose_opt = verbose and "-v" or ""
         locale_env = svncommon.fixlocale()
         # some blather on stderr
-        auth_opt = ''
-        if auth is not None:
-            auth_opt = '%s' % (auth,)
-        elif self._auth is not None:
-            auth_opt = '%s' % (self._auth,)
-        auth_opt = ((auth is not None and str(auth)) or
-                    (self._auth is not None and str(self._auth)) or
-                    '')
+        auth_opt = self._makeauthargs(auth) 
         stdin, stdout, stderr  = os.popen3(locale_env +
                                            'svn log --xml %s %s %s "%s"' % (
                                             rev_opt, verbose_opt, auth_opt,



More information about the pytest-commit mailing list