Skip to content
Browse files

make svn external clone/command work better

  • Loading branch information...
1 parent 8b518a9 commit 4b89b0f0816ad269c771d65bdc7fe51ac568c30e @stettberger stettberger committed Sep 27, 2010
Showing with 54 additions and 30 deletions.
  1. +5 −5 gmp/listers.py
  2. +4 −3 gmp/main.py
  3. +2 −2 gmp/policy.py
  4. +5 −5 gmp/repository.py
  5. +30 −14 gmp/scm.py
  6. +8 −1 gmp/tools.py
View
10 gmp/listers.py
@@ -127,8 +127,8 @@ def upload(self, local, remote):
push_url = "%s:%s" %(self.host,
os.path.join(self.directory, remote))
- cmd = "scp -r '%s' '%s'"% (esc(local),
- esc(push_url))
+ cmd = "scp -r %s %s"% (esc(local),
+ esc(push_url))
print cmd
a = subprocess.Popen(cmd, shell = True)
a.wait()
@@ -215,8 +215,8 @@ def upload(self, local, remote):
sys.exit(-1)
xml.close()
- cmd = "cd '%s'; git push '%s' master" % (esc(local),
- esc(self.github_url(remote)))
+ cmd = "cd %s; git push %s master" % (esc(local),
+ esc(self.github_url(remote)))
print cmd
a = subprocess.Popen(cmd, shell = True)
a.wait()
@@ -247,7 +247,7 @@ def get_list(self):
self.clone_urls = []
for repo in process.stdout.readlines():
- repo = esc(repo.strip())
+ repo = repo.strip()
self.clone_urls.append((repo, os.path.join(os.path.join(self.svn_repo, repo), self.postfix)))
class Gitorious(RepoLister):
View
7 gmp/main.py
@@ -156,7 +156,7 @@ def cmd_clone(self, selector):
os.makedirs(directory)
if os.path.exists(repo.local_url):
continue
- repo.execute("clone", [repo.clone_url, repo.local_url])
+ repo.execute("clone", [repo.clone_url, repo.local_url] + selector[1:])
def _shortcut(self, args):
if len(args) == 0:
@@ -268,8 +268,9 @@ def cmd_upload(self, args):
# Changing the origin remote
if origin:
- cmd = "cd '%s'; git remote rm origin; git remote add origin '%s'" \
- %(esc(repo.local_url), esc(repo.clone_url))
+ cmd = "cd %s; git remote rm origin; git remote add origin %s" \
+ %(esc(repo.local_url),
+ esc(repo.clone_url))
print cmd
a = subprocess.Popen(cmd, shell = True)
a.wait()
View
4 gmp/policy.py
@@ -30,7 +30,7 @@ def check_policy(self, hostname = getfqdn()):
def policy_serialize(self):
ret = ""
for (regexp, policy) in self.policies[1:]:
- ret += ".add_policy('%s', '%s')" %(esc(regexp),
- esc(policy))
+ ret += ".add_policy(%s, %s)" %(repr(regexp),
+ repr(policy))
return ret
View
10 gmp/repository.py
@@ -35,7 +35,7 @@ def __init__(self, clone_url, local_url = None,
m = re.match(".*/([^/]+?)(\\." + scm.binary + ")?$", clone_url)
if m:
# Remove .git / .hg or whatever
- self.local_url = os.path.join(into, esc(m.group(1)))
+ self.local_url = os.path.join(into, m.group(1))
else:
self.local_url = into
else:
@@ -48,11 +48,11 @@ def __init__(self, clone_url, local_url = None,
def __str__(self):
"""A Repository can be serialized"""
- ret = "%s('%s', '%s', default_policy = '%s', scm = %s)" %(
+ ret = "%s(%s, %s, default_policy = %s, scm = %s)" %(
self.__class__.__name__,
- esc(self.clone_url),
- esc(self.local_url),
- esc(self.policies[0][1]),
+ repr(self.clone_url),
+ repr(self.local_url),
+ repr(self.policies[0][1]),
str(self.scm))
ret += self.policy_serialize()
View
44 gmp/scm.py
@@ -1,4 +1,5 @@
import subprocess
+import re
import os
from tools import *
@@ -71,7 +72,7 @@ def __alias(self, command):
def __exec_string(self, command, args = []):
"""Produces an shell command for <command> + <args>"""
# Escape all ' characters
- args = ["'" + esc(x) + "'" for x in args]
+ args = [esc(x) for x in args]
return " ".join([self.binary, self.__alias(command),
self.__option(command)] + args)
def execute(self, command, args = [], destdir = None):
@@ -90,7 +91,7 @@ def bare_execute(self, command, args = [], destdir = None):
# Maybe we have to change the directory first
if destdir:
- command = "cd '%s'; %s" %(esc(destdir), command)
+ command = "cd %s; %s" %(esc(destdir), command)
if parallel:
command += " >/dev/null"
@@ -107,8 +108,8 @@ def __str__(self):
for cmd in self.options.keys():
for option in self.options[cmd]:
- ret += ".add_option('%s', '%s')" %( esc(cmd),
- esc(option))
+ ret += ".add_option(%s, %s)" %(repr(cmd),
+ repr(option))
return ret
def __str_keyword_arguments__(self):
@@ -156,46 +157,61 @@ class GitSvn(Git):
name = "git-svn"
- def __init__(self, externals = []):
+ def __init__(self, externals = [], headonly = False):
Git.__init__(self)
self.externals = externals
+ self.headonly = headonly
def __str_keyword_arguments__(self):
- return "(externals = %s)" % str(self.externals)
+ return "(externals = %s, headonly = %s)" % str(self.externals, self.headonly)
def __externals(self, destdir):
- process = subprocess.Popen("cd '%s'; git svn propget svn:externals" % destdir,
+ process = subprocess.Popen("cd %s; git svn propget svn:externals" % esc(destdir),
shell = True,
stderr = subprocess.PIPE,
stdout = subprocess.PIPE)
- externals = [ x.strip().split(" ") for x in process.stdout.readlines() if x != "\n" ]
+ externals = [ re.split("\\s+", x.strip()) for x in process.stdout.readlines()
+ if x != "\n" ]
process.wait()
+
return externals
def execute(self, command, args, destdir = None):
"""Call execute for every external, if this command is in the externals attribute"""
+ if command in dir(self):
+ return getattr(self, command)(args = args, destdir = destdir)
+
procs = Git.execute(self, command,args = args, destdir = destdir)
- if command in self.externals:
+
+ if self.externals == True or command in self.externals:
for [path, clone_url] in self.__externals(destdir):
- procs.extend( Git.execute(self, command, args = args,
+ procs.extend( self.execute(command, args = args,
destdir = os.path.join(destdir, path)))
return procs
def clone(self, args, destdir = None):
- # Call the actual git svn clone (with aliases!)
+ # Append -r HEAD to command, so only the top commit is cloned
+ if self.headonly:
+ headonly = ['-r', 'HEAD']
+ else:
+ headonly = []
+
destdir = args[1]
procs = []
- procs.extend(self.bare_execute("clone", args = args))
+ # Call the actual git svn clone (with aliases!)
+ procs.extend(self.bare_execute("clone", args = args + headonly))
fd = open(os.path.join(destdir, ".git/info/exclude"), "a+")
fd.write("\n# Metagit svn external excludes\n")
- if "clone" in self.externals:
+ if self.externals == True or "clone" in self.externals:
for [path, clone_url] in self.__externals(destdir):
local_url = os.path.join(destdir, path)
fd.write(path + "/\n")
- procs.extend(self.bare_execute("clone", args = [clone_url, local_url]))
+ # Call clone with other clone and local url
+ procs.extend( self.execute("clone", args = [clone_url, local_url] + args[2:],
+ destdir = local_url) )
return procs
git_svn = gitsvn = GitSvn()
View
9 gmp/tools.py
@@ -36,7 +36,14 @@ def execute():
def esc(str):
- return str.replace("'", "\\'")
+ str = str.replace("\\", "\\\\")
+ quote = False
+ for c in " ;&|{}()$":
+ if c in str:
+ quote = True
+ if quote:
+ return "'" + str.replace("'", "\\'") + "'"
+ return str
def execute(cmd):
if Options.opt('screen'):

0 comments on commit 4b89b0f

Please sign in to comment.
Something went wrong with that request. Please try again.