- don't use dir (python builtin)
- use re for munging depotPath into destination

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
This commit is contained in:
Han-Wen Nienhuys
2007-05-23 16:46:29 -03:00
committed by Simon Hausmann
parent a3c55c09ec
commit ce6f33c835

View File

@ -10,6 +10,7 @@
import optparse, sys, os, marshal, popen2, subprocess, shelve import optparse, sys, os, marshal, popen2, subprocess, shelve
import tempfile, getopt, sha, os.path, time, platform import tempfile, getopt, sha, os.path, time, platform
import re
from sets import Set; from sets import Set;
gitdir = os.environ.get("GIT_DIR", "") gitdir = os.environ.get("GIT_DIR", "")
@ -842,6 +843,7 @@ class P4Sync(Command):
self.changeRange = "" self.changeRange = ""
self.initialParent = "" self.initialParent = ""
self.previousDepotPath = "" self.previousDepotPath = ""
# map from branch depot path to parent branch # map from branch depot path to parent branch
self.knownBranches = {} self.knownBranches = {}
self.initialParents = {} self.initialParents = {}
@ -1145,37 +1147,26 @@ class P4Clone(P4Sync):
if len(args) < 1: if len(args) < 1:
return False return False
depotPath = args[0] depotPath = args[0]
dir = "" destination = ""
if len(args) == 2: if len(args) == 2:
dir = args[1] destination = args[1]
elif len(args) > 2: elif len(args) > 2:
return False return False
if not depotPath.startswith("//"): if not depotPath.startswith("//"):
return False return False
if len(dir) == 0: depotDir = re.sub("(@[^@]*)$", "", depotPath)
dir = depotPath depotDir = re.sub("(#[^#]*)$", "", depotDir)
atPos = dir.rfind("@") depotDir = re.sub(r"\.\.\.$,", "", depotDir)
if atPos != -1: depotDir = re.sub(r"/$", "", depotDir)
dir = dir[0:atPos]
hashPos = dir.rfind("#")
if hashPos != -1:
dir = dir[0:hashPos]
if dir.endswith("..."): if not destination:
dir = dir[:-3] destination = os.path.split(depotDir)[-1]
if dir.endswith("/"): print "Importing from %s into %s" % (depotPath, destination)
dir = dir[:-1] os.makedirs(destination)
os.chdir(destination)
slashPos = dir.rfind("/")
if slashPos != -1:
dir = dir[slashPos + 1:]
print "Importing from %s into %s" % (depotPath, dir)
os.makedirs(dir)
os.chdir(dir)
system("git init") system("git init")
gitdir = os.getcwd() + "/.git" gitdir = os.getcwd() + "/.git"
if not P4Sync.run(self, [depotPath]): if not P4Sync.run(self, [depotPath]):