Cleanups
- don't use dir (python builtin) - use re for munging depotPath into destination Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
Han-Wen Nienhuys committed
May 23, 2007 at 16:46 UTC
ce6f33c83537a04a3fb7557d7a74fe81ebccd7e4
1 file changed
+13
-22
contrib/fast-import/git-p4
+13
-22
@@ -10,6 +10,7 @@
10
11
import optparse, sys, os, marshal, popen2, subprocess, shelve
12
import tempfile, getopt, sha, os.path, time, platform
13
+import re
14
from sets import Set;
15
16
gitdir = os.environ.get("GIT_DIR", "")
@@ -842,6 +843,7 @@ class P4Sync(Command):
843
self.changeRange = ""
844
self.initialParent = ""
845
self.previousDepotPath = ""
846
+
847
# map from branch depot path to parent branch
848
self.knownBranches = {}
849
self.initialParents = {}
@@ -1145,37 +1147,26 @@ class P4Clone(P4Sync):
1147
if len(args) < 1:
1148
return False
1149
depotPath = args[0]
1148
- dir = ""
1150
+ destination = ""
1151
if len(args) == 2:
1150
- dir = args[1]
1152
+ destination = args[1]
1153
elif len(args) > 2:
1154
return False
1155
1156
if not depotPath.startswith("//"):
1157
return False
1158
1157
- if len(dir) == 0:
1158
- dir = depotPath
1159
- atPos = dir.rfind("@")
1160
- if atPos != -1:
1161
- dir = dir[0:atPos]
1162
- hashPos = dir.rfind("#")
1163
- if hashPos != -1:
1164
- dir = dir[0:hashPos]
1165
-
1166
- if dir.endswith("..."):
1167
- dir = dir[:-3]
1168
-
1169
- if dir.endswith("/"):
1170
- dir = dir[:-1]
1159
+ depotDir = re.sub("(@[^@]*)$", "", depotPath)
1160
+ depotDir = re.sub("(#[^#]*)$", "", depotDir)
1161
+ depotDir = re.sub(r"\.\.\.$,", "", depotDir)
1162
+ depotDir = re.sub(r"/$", "", depotDir)
1163
1172
- slashPos = dir.rfind("/")
1173
- if slashPos != -1:
1174
- dir = dir[slashPos + 1:]
1164
+ if not destination:
1165
+ destination = os.path.split(depotDir)[-1]
1166
1176
- print "Importing from %s into %s" % (depotPath, dir)
1177
- os.makedirs(dir)
1178
- os.chdir(dir)
1167
+ print "Importing from %s into %s" % (depotPath, destination)
1168
+ os.makedirs(destination)
1169
+ os.chdir(destination)
1170
system("git init")
1171
gitdir = os.getcwd() + "/.git"
1172
if not P4Sync.run(self, [depotPath]):