From: Scott Lamb <slamb@slamb.org>
To: git@vger.kernel.org, Junio C Hamano <junkio@cox.net>
Cc: Scott Lamb <slamb@slamb.org>
Subject: [PATCH 2/4] git-p4import: use lists of subcommand arguments
Date: Sat, 2 Jun 2007 20:58:44 -0700 [thread overview]
Message-ID: <11808431291938-git-send-email-slamb@slamb.org> (raw)
In-Reply-To: <1180843126948-git-send-email-slamb@slamb.org>
This fixes problems with spaces in filenames.
Signed-off-by: Scott Lamb <slamb@slamb.org>
---
git-p4import.py | 84 +++++++++++++++++++++++++++++-------------------------
1 files changed, 45 insertions(+), 39 deletions(-)
diff --git a/git-p4import.py b/git-p4import.py
index 002f8d8..54e5e9e 100644
--- a/git-p4import.py
+++ b/git-p4import.py
@@ -73,11 +73,12 @@ class p4_command:
if p4.wait() != 0:
die("Could not run the \"p4\" command: %r" % (err,))
- def p4(self, cmd, *args):
+ def p4(self, args):
global logfile
- cmd = "%s %s" % (cmd, ' '.join(args))
- cmdlist = ['p4', '-G'] + cmd.split(' ')
+ cmd = ' '.join(args)
report(2, "P4:", cmd)
+ cmdlist = ['p4', '-G']
+ cmdlist.extend(args)
p4 = subprocess.Popen(cmdlist,
stdout=subprocess.PIPE,
stderr=logfile)
@@ -97,13 +98,14 @@ class p4_command:
def sync(self, id, force=False, trick=False, test=False):
try:
if force:
- self.p4("sync -f %s@%s"%(self.repopath, id))
+ extra = ["-f"]
elif trick:
- self.p4("sync -k %s@%s"%(self.repopath, id))
+ extra = ["-k"]
elif test:
- self.p4("sync -n %s@%s"%(self.repopath, id))
+ extra = ["-n"]
else:
- self.p4("sync %s@%s"%(self.repopath, id))
+ extra = []
+ self.p4(["sync"] + extra + ["%s@%s"%(self.repopath, id)])
except P4Exception, e:
data = e.errmsg.upper()
if data.find('VIEW') > 0:
@@ -115,7 +117,8 @@ class p4_command:
def changes(self, since=0):
try:
list = []
- for rec in self.p4("changes %s@%s,#head" % (self.repopath, since+1)):
+ for rec in self.p4(["changes", "%s@%s,#head"
+ % (self.repopath, since+1)]):
list.append(rec['change'])
list.reverse()
return list
@@ -134,7 +137,7 @@ class p4_command:
def _get_user(self, id):
if not self.userlist.has_key(id):
try:
- user = self.p4("users", id)[0]
+ user = self.p4(["users", id])[0]
self.userlist[id] = (user['FullName'], user['Email'])
except P4Exception, e:
report(2, "P4: missing user %s" % (id,))
@@ -157,12 +160,12 @@ class p4_command:
def where(self):
try:
- return self.p4("where %s" % self.repopath)[-1]['path']
+ return self.p4(["where", self.repopath])[-1]['path']
except P4Exception, e:
return ""
def describe(self, num):
- desc = self.p4("describe -s", num)[0]
+ desc = self.p4(["describe", "-s", num])[0]
self.msg = desc['desc']
self.author, self.email = self._get_user(desc['user'])
self.date = self._format_date(time.localtime(long(desc['time'])))
@@ -173,16 +176,16 @@ class GitException(Exception): pass
class git_command:
def __init__(self):
try:
- self.version = self.git("--version")[0][12:].rstrip()
+ self.version = self.git(["--version"])[0][12:].rstrip()
except GitException, e:
die(e)
try:
- self.gitdir = self.get_single("rev-parse --git-dir")
+ self.gitdir = self.get_single(["rev-parse", "--git-dir"])
report(2, "gdir:", self.gitdir)
except GitException, e:
die("Not a git repository... did you forget to \"git init\" ?")
try:
- self.cdup = self.get_single("rev-parse --show-cdup")
+ self.cdup = self.get_single(["rev-parse", "--show-cdup"])
if self.cdup != "":
os.chdir(self.cdup)
self.topdir = os.getcwd()
@@ -190,9 +193,11 @@ class git_command:
except GitException, e:
die("Could not find top git directory")
- def git(self, cmd, stdin=None):
+ def git(self, args, stdin=None):
+ cmd = ' '.join(args)
report(2, "GIT:", cmd)
- cmdlist = ['git'] + cmd.split(' ')
+ cmdlist = ['git']
+ cmdlist.extend(args)
git = subprocess.Popen(cmdlist,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
@@ -204,37 +209,37 @@ class git_command:
report(2, stderr)
return re.findall(r'.*\n', stdout)
- def get_single(self, cmd):
- list = self.git(cmd)
+ def get_single(self, args, stdin=None):
+ list = self.git(args, stdin=stdin)
if len(list) != 1:
- raise GitException("%r returned %r" % (cmd, list))
+ raise GitException("%r returned %r" % (' '.join(args), list))
return list[0].rstrip()
def current_branch(self):
try:
- testit = self.git("rev-parse --verify HEAD")[0]
- return self.git("symbolic-ref HEAD")[0][11:].rstrip()
+ testit = self.git(["rev-parse", "--verify", "HEAD"])[0]
+ return self.git(["symbolic-ref", "HEAD"])[0][11:].rstrip()
except GitException, e:
return None
def get_config(self, variable):
try:
- return self.git("config --get %s" % variable)[0].rstrip()
+ return self.git(["config", "--get", variable])[0].rstrip()
except GitException, e:
return None
def set_config(self, variable, value):
try:
- self.git("config %s %s"%(variable, value) )
+ self.git(["config", variable, value])
except GitException, e:
die(e)
def make_tag(self, name, head):
- self.git("tag -f %s %s"%(name,head))
+ self.git(["tag", "-f", name, head])
def top_change(self, branch):
try:
- a=self.get_single("name-rev --tags refs/heads/%s" % branch)
+ a=self.get_single(["name-rev", "--tags", "refs/heads/%s" % branch])
loc = a.find(' tags/') + 6
if a[loc:loc+3] != "p4/":
raise
@@ -243,22 +248,23 @@ class git_command:
return 0
def update_index(self):
- files = self.git("ls-files -m -d -o -z")
- self.git("update-index --add --remove -z --stdin", stdin=files)
+ files = self.git("ls-files -m -d -o -z".split(" "))
+ self.git("update-index --add --remove -z --stdin".split(" "),
+ stdin=files)
def checkout(self, branch):
- self.git("checkout %s" % branch)
+ self.git(["checkout", branch])
def repoint_head(self, branch):
- self.git("symbolic-ref HEAD refs/heads/%s" % branch)
+ self.git(["symbolic-ref", "HEAD", "refs/heads/%s" % branch])
def remove_files(self):
- files = self.git("ls-files")
+ files = self.git(["ls-files"])
for file in files:
os.unlink(file)
def clean_directories(self):
- self.git("clean -d")
+ self.git(["clean", "-d"])
def fresh_branch(self, branch):
report(1, "Creating new branch", branch)
@@ -269,7 +275,7 @@ class git_command:
if e.errno != errno.ENOENT:
raise
self.repoint_head(branch)
- self.git("clean -d")
+ self.clean_directories()
def basedir(self):
return self.topdir
@@ -277,18 +283,18 @@ class git_command:
def commit(self, author, email, date, msg, id):
self.update_index()
try:
- current = self.get_single("rev-parse --verify HEAD")
- head = "-p HEAD"
+ current = [self.get_single(["rev-parse", "--verify", "HEAD"])]
+ head = ["-p", "HEAD"]
except GitException, e:
- current = ""
- head = ""
- tree = self.get_single("write-tree")
+ current = []
+ head = []
+ tree = self.get_single(["write-tree"])
for r,l in [('DATE',date),('NAME',author),('EMAIL',email)]:
os.environ['GIT_AUTHOR_%s'%r] = l
os.environ['GIT_COMMITTER_%s'%r] = l
- commit = self.get_single("commit-tree %s %s" % (tree,head), stdin=msg)
+ commit = self.get_single(["commit-tree", tree] + head, stdin=msg)
self.make_tag("p4/%s"%id, commit)
- self.git("update-ref HEAD %s %s" % (commit, current) )
+ self.git(["update-ref", "HEAD", commit] + current)
try:
opts, args = getopt.getopt(sys.argv[1:], "qhvt:",
--
1.5.2
next prev parent reply other threads:[~2007-06-03 3:59 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-31 16:47 git-p4import.py robustness changes Scott Lamb
2007-05-31 23:53 ` Junio C Hamano
2007-06-02 20:41 ` Scott Lamb
2007-06-02 21:33 ` Junio C Hamano
2007-06-02 23:21 ` Scott Lamb
2007-06-02 23:52 ` Junio C Hamano
2007-06-03 13:11 ` Simon Hausmann
2007-06-03 20:12 ` Scott Lamb
2007-06-04 5:54 ` Shawn O. Pearce
2007-06-04 6:09 ` Dana How
2007-06-04 6:18 ` Shawn O. Pearce
2007-06-04 7:19 ` Scott Lamb
2007-06-05 7:21 ` Simon Hausmann
2007-06-04 8:41 ` Marius Storm-Olsen
2007-06-04 5:56 ` Shawn O. Pearce
2007-06-12 21:46 ` Simon Hausmann
2007-06-13 21:06 ` Scott Lamb
2007-06-13 22:34 ` Simon Hausmann
2007-06-14 5:35 ` Shawn O. Pearce
2007-06-14 21:44 ` Simon Hausmann
2007-06-15 3:13 ` Shawn O. Pearce
2007-06-15 5:30 ` Marius Storm-Olsen, mstormo_git
2007-06-03 3:58 ` [PATCH 1/4] git-p4import: fix subcommand error handling Scott Lamb
2007-06-03 3:58 ` Scott Lamb [this message]
2007-06-03 3:58 ` [PATCH 3/4] git-p4import: resume on correct p4 changeset Scott Lamb
2007-06-03 3:58 ` [PATCH 4/4] git-p4import: partial history Scott Lamb
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=11808431291938-git-send-email-slamb@slamb.org \
--to=slamb@slamb.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).