Andrew's git
/
gitweb.git
/ diff
summary
|
log
|
commit
| diff |
tree
commit
grep
author
committer
pickaxe
?
re
Cleanups & import into p4/master for local import
author
Han-Wen Nienhuys
<hanwen@google.com>
Wed, 23 May 2007 21:49:35 +0000
(18:49 -0300)
committer
Han-Wen Nienhuys
<hanwen@google.com>
Thu, 31 May 2007 15:38:30 +0000
(12:38 -0300)
- import into master/local if --import-local is set
- use Die() for exiting
- if --verbose is set, raise Exception()
- use joined strings iso. `list` for progress printing
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
contrib/fast-import/git-p4
patch
|
blob
|
history
raw
|
patch
|
inline
| side by side (parent:
d2c6dd3
)
diff --git
a/contrib/fast-import/git-p4
b/contrib/fast-import/git-p4
index 1d799708f6969bc0da91adeea6364176db8b9988..cc0b7013dabe75d6b354ff7de9af77fed3847d0f 100755
(executable)
--- a/
contrib/fast-import/git-p4
+++ b/
contrib/fast-import/git-p4
@@
-16,40
+16,44
@@
from sets import Set;
verbose = False
verbose = False
+def die(msg):
+ if verbose:
+ raise Exception(msg)
+ else:
+ sys.stderr.write(msg + "\n")
+ sys.exit(1)
+
def write_pipe(c, str):
if verbose:
def write_pipe(c, str):
if verbose:
- sys.stderr.write('
w
riting pipe: %s\n' % c)
+ sys.stderr.write('
W
riting pipe: %s\n' % c)
pipe = os.popen(c, 'w')
val = pipe.write(str)
if pipe.close():
pipe = os.popen(c, 'w')
val = pipe.write(str)
if pipe.close():
- sys.stderr.write('Command failed: %s' % c)
- sys.exit(1)
+ die('Command failed: %s' % c)
return val
def read_pipe(c, ignore_error=False):
if verbose:
return val
def read_pipe(c, ignore_error=False):
if verbose:
- sys.stderr.write('
r
eading pipe: %s\n' % c)
+ sys.stderr.write('
R
eading pipe: %s\n' % c)
pipe = os.popen(c, 'rb')
val = pipe.read()
if pipe.close() and not ignore_error:
pipe = os.popen(c, 'rb')
val = pipe.read()
if pipe.close() and not ignore_error:
- sys.stderr.write('Command failed: %s\n' % c)
- sys.exit(1)
+ die('Command failed: %s' % c)
return val
def read_pipe_lines(c):
if verbose:
return val
def read_pipe_lines(c):
if verbose:
- sys.stderr.write('
r
eading pipe: %s\n' % c)
+ sys.stderr.write('
R
eading pipe: %s\n' % c)
## todo: check return status
pipe = os.popen(c, 'rb')
val = pipe.readlines()
if pipe.close():
## todo: check return status
pipe = os.popen(c, 'rb')
val = pipe.readlines()
if pipe.close():
- sys.stderr.write('Command failed: %s\n' % c)
- sys.exit(1)
+ die('Command failed: %s' % c)
return val
return val
@@
-105,10
+109,6
@@
def p4Where(depotPath):
clientPath = clientPath[:-3]
return clientPath
clientPath = clientPath[:-3]
return clientPath
-def die(msg):
- sys.stderr.write(msg + "\n")
- sys.exit(1)
-
def currentGitBranch():
return read_pipe("git name-rev HEAD").split(" ")[1].strip()
def currentGitBranch():
return read_pipe("git name-rev HEAD").split(" ")[1].strip()
@@
-583,7
+583,8
@@
class P4Sync(Command):
optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false",
help="Import into refs/heads/ , not refs/remotes"),
optparse.make_option("--max-changes", dest="maxChanges"),
optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false",
help="Import into refs/heads/ , not refs/remotes"),
optparse.make_option("--max-changes", dest="maxChanges"),
- optparse.make_option("--keep-path", dest="keepRepoPath", action='store_true')
+ optparse.make_option("--keep-path", dest="keepRepoPath", action='store_true',
+ help="Keep entire BRANCH/DIR/SUBDIR prefix during import")
]
self.description = """Imports from Perforce into a git repository.\n
example:
]
self.description = """Imports from Perforce into a git repository.\n
example:
@@
-876,10
+877,14
@@
class P4Sync(Command):
if self.verbose:
print "Label changes: %s" % self.labels.keys()
if self.verbose:
print "Label changes: %s" % self.labels.keys()
+ def guessProjectName(self):
+ for p in self.depotPaths:
+ return p [p.strip().rfind("/") + 1:]
+
def getBranchMapping(self):
## FIXME - what's a P4 projectName ?
def getBranchMapping(self):
## FIXME - what's a P4 projectName ?
- self.projectName = self.
depotPath[self.depotPath.strip().rfind("/") + 1:]
+ self.projectName = self.
guessProjectName()
for info in p4CmdList("branches"):
details = p4Cmd("branch -o %s" % info["branch"])
for info in p4CmdList("branches"):
details = p4Cmd("branch -o %s" % info["branch"])
@@
-911,9
+916,11
@@
class P4Sync(Command):
for line in read_pipe_lines(cmdline):
line = line.strip()
for line in read_pipe_lines(cmdline):
line = line.strip()
- if self.importIntoRemotes and ((not line.startswith("p4/")) or line == "p4/HEAD"):
- continue
+ ## only import to p4/
+ if not line.startswith('p4/'):
+ continue
+ branch = line
if self.importIntoRemotes:
# strip off p4
branch = re.sub ("^p4/", "", line)
if self.importIntoRemotes:
# strip off p4
branch = re.sub ("^p4/", "", line)
@@
-923,7
+930,8
@@
class P4Sync(Command):
def createOrUpdateBranchesFromOrigin(self):
if not self.silent:
def createOrUpdateBranchesFromOrigin(self):
if not self.silent:
- print "Creating/updating branch(es) in %s based on origin branch(es)" % self.refPrefix
+ print ("Creating/updating branch(es) in %s based on origin branch(es)"
+ % self.refPrefix)
for line in read_pipe_lines("git rev-parse --symbolic --remotes"):
line = line.strip()
for line in read_pipe_lines("git rev-parse --symbolic --remotes"):
line = line.strip()
@@
-998,7
+1006,7
@@
class P4Sync(Command):
system("git fetch origin")
if len(self.branch) == 0:
system("git fetch origin")
if len(self.branch) == 0:
- self.branch = self.refPrefix + "master"
+ self.branch = self.refPrefix + "
p4/
master"
if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
system("git update-ref %s refs/heads/p4" % self.branch)
system("git branch -D p4");
if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
system("git update-ref %s refs/heads/p4" % self.branch)
system("git branch -D p4");
@@
-1023,6
+1031,7
@@
class P4Sync(Command):
p4Change = 0
for branch in self.p4BranchesInGit:
p4Change = 0
for branch in self.p4BranchesInGit:
+ print self.p4BranchesInGit
logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
settings = extractSettingsGitLog(logMsg)
logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
settings = extractSettingsGitLog(logMsg)
@@
-1125,7
+1134,7
@@
class P4Sync(Command):
self.gitStream = importProcess.stdin
self.gitError = importProcess.stderr
self.gitStream = importProcess.stdin
self.gitError = importProcess.stderr
- if
len(self.revision) > 0
:
+ if
self.revision
:
print "Doing initial import of %s from revision %s" % (' '.join(self.depotPaths), self.revision)
details = { "user" : "git perforce import user", "time" : int(time.time()) }
print "Doing initial import of %s from revision %s" % (' '.join(self.depotPaths), self.revision)
details = { "user" : "git perforce import user", "time" : int(time.time()) }
@@
-1183,7
+1192,7
@@
class P4Sync(Command):
changes.sort()
else:
if self.verbose:
changes.sort()
else:
if self.verbose:
- print "Getting p4 changes for %s...%s" % (
`self.depotPaths`
,
+ print "Getting p4 changes for %s...%s" % (
', '.join(self.depotPaths)
,
self.changeRange)
assert self.depotPaths
output = read_pipe_lines("p4 changes " + ' '.join (["%s...%s" % (p, self.changeRange)
self.changeRange)
assert self.depotPaths
output = read_pipe_lines("p4 changes " + ' '.join (["%s...%s" % (p, self.changeRange)
@@
-1344,7
+1353,7
@@
class P4Clone(P4Sync):
if not self.cloneDestination:
self.cloneDestination = self.defaultDestination()
if not self.cloneDestination:
self.cloneDestination = self.defaultDestination()
- print "Importing from %s into %s" % (
`depotPaths`
, self.cloneDestination)
+ print "Importing from %s into %s" % (
', '.join(depotPaths)
, self.cloneDestination)
os.makedirs(self.cloneDestination)
os.chdir(self.cloneDestination)
system("git init")
os.makedirs(self.cloneDestination)
os.chdir(self.cloneDestination)
system("git init")
@@
-1357,6
+1366,7
@@
class P4Clone(P4Sync):
system("git checkout -f")
else:
print "Could not detect main branch. No checkout/master branch created."
system("git checkout -f")
else:
print "Could not detect main branch. No checkout/master branch created."
+
return True
class HelpFormatter(optparse.IndentedHelpFormatter):
return True
class HelpFormatter(optparse.IndentedHelpFormatter):