@matheusbsbs / matheus-bagliano / commits / f9a3a4f796
Fork 0

Added git-p4 clone convenience command

Signed-off-by: Simon Hausmann <simon@lst.de>

Simon Hausmann committed Apr 8, 2007 at 10:08 UTC f9a3a4f796461276bbbcfef965984086e8e00b46
2 files changed +77 -3
contrib/fast-import/git-p4
+55 -2
@@ -440,6 +440,7 @@ class P4Sync(Command):
440 self.detectBranches = False
441 self.detectLabels = False
442 self.changesFile = ""
443 + self.tagLastChange = True
444
445 def p4File(self, depotPath):
446 return os.popen("p4 print -q \"%s\"" % depotPath, "rb").read()
@@ -826,7 +827,6 @@ class P4Sync(Command):
827 self.globalPrefix = ""
828 self.changeRange = ""
829 self.initialParent = ""
829 - self.tagLastChange = True
830
831 if len(self.branch) == 0:
832 self.branch = "p4"
@@ -1062,6 +1062,58 @@ class P4Rebase(Command):
1062 system("git diff-tree --stat --summary -M %s HEAD" % oldHead)
1063 return True
1064
1065 +class P4Clone(P4Sync):
1066 + def __init__(self):
1067 + P4Sync.__init__(self)
1068 + self.description = "Creates a new git repository and imports from Perforce into it"
1069 + self.usage = "usage: %prog [options] //depot/path[@revRange] [directory]"
1070 + self.needsGit = False
1071 + self.tagLastChange = False
1072 +
1073 + def run(self, args):
1074 + if len(args) < 1:
1075 + return False
1076 + depotPath = args[0]
1077 + dir = ""
1078 + if len(args) == 2:
1079 + dir = args[1]
1080 + elif len(args) > 2:
1081 + return False
1082 +
1083 + if not depotPath.startswith("//"):
1084 + return False
1085 +
1086 + if len(dir) == 0:
1087 + dir = depotPath
1088 + atPos = dir.rfind("@")
1089 + if atPos != -1:
1090 + dir = dir[0:atPos]
1091 + hashPos = dir.rfind("#")
1092 + if hashPos != -1:
1093 + dir = dir[0:hashPos]
1094 +
1095 + if dir.endswith("..."):
1096 + dir = dir[:-3]
1097 +
1098 + if dir.endswith("/"):
1099 + dir = dir[:-1]
1100 +
1101 + slashPos = dir.rfind("/")
1102 + if slashPos != -1:
1103 + dir = dir[slashPos + 1:]
1104 +
1105 + print "Importing from %s into %s" % (depotPath, dir)
1106 + os.makedirs(dir)
1107 + os.chdir(dir)
1108 + system("git init")
1109 + if not P4Sync.run(self, [depotPath]):
1110 + return False
1111 + os.wait()
1112 + if self.branch != "master":
1113 + system("git branch master p4")
1114 + system("git checkout -f")
1115 + return True
1116 +
1117 class HelpFormatter(optparse.IndentedHelpFormatter):
1118 def __init__(self):
1119 optparse.IndentedHelpFormatter.__init__(self)
@@ -1085,7 +1137,8 @@ commands = {
1137 "clean-tags" : P4CleanTags(),
1138 "submit" : P4Submit(),
1139 "sync" : P4Sync(),
1088 - "rebase" : P4Rebase()
1140 + "rebase" : P4Rebase(),
1141 + "clone" : P4Clone()
1142 }
1143
1144 if len(sys.argv[1:]) == 0:
contrib/fast-import/git-p4.txt
+22 -1
@@ -10,7 +10,25 @@ done using "git-p4 submit".
10 Importing
11 =========
12
13 -The procedure is simple:
13 +You can simply start with
14 +
15 + git-p4 clone //depot/path/project
16 +
17 +or
18 +
19 + git-p4 clone //depot/path/project myproject
20 +
21 +This will create an empty git repository in a subdirectory called "project" (or
22 +"myproject" with the second command), import the head revision from the
23 +specified perforce path into a git "p4" branch, create a master branch off it
24 +and check it out. If you want the entire history (not just the head revision) then
25 +you can simply append a "@all" to the depot path:
26 +
27 + git-p4 clone //depot/project/main@all myproject
28 +
29 +
30 +
31 +If you want more control you can also use the git-p4 sync command directly:
32
33 mkdir repo-git
34 cd repo-git
@@ -31,6 +49,9 @@ a big import. This may take a while.
49 Support for Perforce integrations is still work in progress. Don't bother
50 trying it unless you want to hack on it :)
51
52 +For convenience there's also the git-p4 clone command that works similar to
53 +git-clone and combines the creation of the git repository with the the initial
54 +import and the branch setup
55
56 Incremental Imports
57 ===================