@matheusbsbs / matheus-bagliano / commits / 8b41a97f8a
Fork 0

clone and sync --keep-path to keep perforce path to module.

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>

Han-Wen Nienhuys committed May 23, 2007 at 18:20 UTC 8b41a97f8a3e2778ce733cd3d7e181bc28cc43a0
1 file changed +12 -9
contrib/fast-import/git-p4
+12 -9
@@ -11,6 +11,7 @@
11 import optparse, sys, os, marshal, popen2, subprocess, shelve
12 import tempfile, getopt, sha, os.path, time, platform
13 import re
14 +
15 from sets import Set;
16
17 gitdir = os.environ.get("GIT_DIR", "")
@@ -20,7 +21,6 @@ def write_pipe(c, str):
21 if not silent:
22 sys.stderr.write('writing pipe: %s\n' % c)
23
23 - ## todo: check return status
24 pipe = os.popen(c, 'w')
25 val = pipe.write(str)
26 if pipe.close():
@@ -32,7 +32,7 @@ def write_pipe(c, str):
32 def read_pipe(c):
33 if not silent:
34 sys.stderr.write('reading pipe: %s\n' % c)
35 - ## todo: check return status
35 +
36 pipe = os.popen(c, 'rb')
37 val = pipe.read()
38 if pipe.close():
@@ -60,8 +60,6 @@ def system(cmd):
60 if os.system(cmd) != 0:
61 die("command failed: %s" % cmd)
62
63 -
64 -
63 def p4CmdList(cmd):
64 cmd = "p4 -G %s" % cmd
65 pipe = os.popen(cmd, "rb")
@@ -566,7 +564,8 @@ class P4Sync(Command):
564 optparse.make_option("--detect-labels", dest="detectLabels", action="store_true"),
565 optparse.make_option("--verbose", dest="verbose", action="store_true"),
566 optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false"),
569 - optparse.make_option("--max-changes", dest="maxChanges")
567 + optparse.make_option("--max-changes", dest="maxChanges"),
568 + optparse.make_option("--keep-path", dest="keepRepoPath")
569 ]
570 self.description = """Imports from Perforce into a git repository.\n
571 example:
@@ -590,6 +589,7 @@ class P4Sync(Command):
589 self.maxChanges = ""
590 self.isWindows = (platform.system() == "Windows")
591 self.depotPath = None
592 + self.keepRepoPath = False
593
594 if gitConfig("git-p4.syncFromOrigin") == "false":
595 self.syncWithOrigin = False
@@ -617,8 +617,11 @@ class P4Sync(Command):
617 fnum = fnum + 1
618 return files
619
620 - def stripRepoPath(self, path):
621 - return path[len(self.depotPath):]
620 + def stripRepoPath(self, path, prefix):
621 + if self.keepRepoPath:
622 + prefix = re.sub("^(//[^/]+/).*", r'\1', prefix)
623 +
624 + return path[len(prefix):]
625
626 def splitFilesIntoBranches(self, commit):
627 branches = {}
@@ -638,7 +641,7 @@ class P4Sync(Command):
641 file["type"] = commit["type%s" % fnum]
642 fnum = fnum + 1
643
641 - relPath = self.stripRepoPath(path)
644 + relPath = self.stripRepoPath(path, self.depotPath)
645
646 for branch in self.knownBranches.keys():
647
@@ -687,7 +690,7 @@ class P4Sync(Command):
690 continue
691 rev = file["rev"]
692 depotPath = path + "#" + rev
690 - relPath = path[len(branchPrefix):]
693 + relPath = self.stripRepoPath(path, branchPrefix)
694 action = file["action"]
695
696 if file["type"] == "apple":