Cleanups & import into p4/master for local import
- 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>
This commit is contained in:
parent
d2c6dd30ef
commit
86dff6b676
@ -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):
|
def write_pipe(c, str):
|
||||||
if verbose:
|
if verbose:
|
||||||
sys.stderr.write('writing pipe: %s\n' % c)
|
sys.stderr.write('Writing pipe: %s\n' % c)
|
||||||
|
|
||||||
pipe = os.popen(c, 'w')
|
pipe = os.popen(c, 'w')
|
||||||
val = pipe.write(str)
|
val = pipe.write(str)
|
||||||
if pipe.close():
|
if pipe.close():
|
||||||
sys.stderr.write('Command failed: %s' % c)
|
die('Command failed: %s' % c)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return val
|
return val
|
||||||
|
|
||||||
def read_pipe(c, ignore_error=False):
|
def read_pipe(c, ignore_error=False):
|
||||||
if verbose:
|
if verbose:
|
||||||
sys.stderr.write('reading pipe: %s\n' % c)
|
sys.stderr.write('Reading pipe: %s\n' % c)
|
||||||
|
|
||||||
pipe = os.popen(c, 'rb')
|
pipe = os.popen(c, 'rb')
|
||||||
val = pipe.read()
|
val = pipe.read()
|
||||||
if pipe.close() and not ignore_error:
|
if pipe.close() and not ignore_error:
|
||||||
sys.stderr.write('Command failed: %s\n' % c)
|
die('Command failed: %s' % c)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return val
|
return val
|
||||||
|
|
||||||
|
|
||||||
def read_pipe_lines(c):
|
def read_pipe_lines(c):
|
||||||
if verbose:
|
if verbose:
|
||||||
sys.stderr.write('reading pipe: %s\n' % c)
|
sys.stderr.write('Reading pipe: %s\n' % c)
|
||||||
## todo: check return status
|
## todo: check return status
|
||||||
pipe = os.popen(c, 'rb')
|
pipe = os.popen(c, 'rb')
|
||||||
val = pipe.readlines()
|
val = pipe.readlines()
|
||||||
if pipe.close():
|
if pipe.close():
|
||||||
sys.stderr.write('Command failed: %s\n' % c)
|
die('Command failed: %s' % c)
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
return val
|
return val
|
||||||
|
|
||||||
@ -105,10 +109,6 @@ def p4Where(depotPath):
|
|||||||
clientPath = clientPath[:-3]
|
clientPath = clientPath[:-3]
|
||||||
return clientPath
|
return clientPath
|
||||||
|
|
||||||
def die(msg):
|
|
||||||
sys.stderr.write(msg + "\n")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
def currentGitBranch():
|
def currentGitBranch():
|
||||||
return read_pipe("git name-rev HEAD").split(" ")[1].strip()
|
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",
|
optparse.make_option("--import-local", dest="importIntoRemotes", action="store_false",
|
||||||
help="Import into refs/heads/ , not refs/remotes"),
|
help="Import into refs/heads/ , not refs/remotes"),
|
||||||
optparse.make_option("--max-changes", dest="maxChanges"),
|
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
|
self.description = """Imports from Perforce into a git repository.\n
|
||||||
example:
|
example:
|
||||||
@ -876,10 +877,14 @@ class P4Sync(Command):
|
|||||||
if self.verbose:
|
if self.verbose:
|
||||||
print "Label changes: %s" % self.labels.keys()
|
print "Label changes: %s" % self.labels.keys()
|
||||||
|
|
||||||
|
def guessProjectName(self):
|
||||||
|
for p in self.depotPaths:
|
||||||
|
return p [p.strip().rfind("/") + 1:]
|
||||||
|
|
||||||
def getBranchMapping(self):
|
def getBranchMapping(self):
|
||||||
|
|
||||||
## FIXME - what's a P4 projectName ?
|
## FIXME - what's a P4 projectName ?
|
||||||
self.projectName = self.depotPath[self.depotPath.strip().rfind("/") + 1:]
|
self.projectName = self.guessProjectName()
|
||||||
|
|
||||||
for info in p4CmdList("branches"):
|
for info in p4CmdList("branches"):
|
||||||
details = p4Cmd("branch -o %s" % info["branch"])
|
details = p4Cmd("branch -o %s" % info["branch"])
|
||||||
@ -911,9 +916,11 @@ class P4Sync(Command):
|
|||||||
|
|
||||||
for line in read_pipe_lines(cmdline):
|
for line in read_pipe_lines(cmdline):
|
||||||
line = line.strip()
|
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:
|
if self.importIntoRemotes:
|
||||||
# strip off p4
|
# strip off p4
|
||||||
branch = re.sub ("^p4/", "", line)
|
branch = re.sub ("^p4/", "", line)
|
||||||
@ -923,7 +930,8 @@ class P4Sync(Command):
|
|||||||
|
|
||||||
def createOrUpdateBranchesFromOrigin(self):
|
def createOrUpdateBranchesFromOrigin(self):
|
||||||
if not self.silent:
|
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"):
|
for line in read_pipe_lines("git rev-parse --symbolic --remotes"):
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
@ -998,7 +1006,7 @@ class P4Sync(Command):
|
|||||||
system("git fetch origin")
|
system("git fetch origin")
|
||||||
|
|
||||||
if len(self.branch) == 0:
|
if len(self.branch) == 0:
|
||||||
self.branch = self.refPrefix + "master"
|
self.branch = self.refPrefix + "p4/master"
|
||||||
if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
|
if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
|
||||||
system("git update-ref %s refs/heads/p4" % self.branch)
|
system("git update-ref %s refs/heads/p4" % self.branch)
|
||||||
system("git branch -D p4");
|
system("git branch -D p4");
|
||||||
@ -1023,6 +1031,7 @@ class P4Sync(Command):
|
|||||||
|
|
||||||
p4Change = 0
|
p4Change = 0
|
||||||
for branch in self.p4BranchesInGit:
|
for branch in self.p4BranchesInGit:
|
||||||
|
print self.p4BranchesInGit
|
||||||
logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
|
logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
|
||||||
|
|
||||||
settings = extractSettingsGitLog(logMsg)
|
settings = extractSettingsGitLog(logMsg)
|
||||||
@ -1125,7 +1134,7 @@ class P4Sync(Command):
|
|||||||
self.gitStream = importProcess.stdin
|
self.gitStream = importProcess.stdin
|
||||||
self.gitError = importProcess.stderr
|
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)
|
print "Doing initial import of %s from revision %s" % (' '.join(self.depotPaths), self.revision)
|
||||||
|
|
||||||
details = { "user" : "git perforce import user", "time" : int(time.time()) }
|
details = { "user" : "git perforce import user", "time" : int(time.time()) }
|
||||||
@ -1183,7 +1192,7 @@ class P4Sync(Command):
|
|||||||
changes.sort()
|
changes.sort()
|
||||||
else:
|
else:
|
||||||
if self.verbose:
|
if self.verbose:
|
||||||
print "Getting p4 changes for %s...%s" % (`self.depotPaths`,
|
print "Getting p4 changes for %s...%s" % (', '.join(self.depotPaths),
|
||||||
self.changeRange)
|
self.changeRange)
|
||||||
assert self.depotPaths
|
assert self.depotPaths
|
||||||
output = read_pipe_lines("p4 changes " + ' '.join (["%s...%s" % (p, self.changeRange)
|
output = read_pipe_lines("p4 changes " + ' '.join (["%s...%s" % (p, self.changeRange)
|
||||||
@ -1344,7 +1353,7 @@ class P4Clone(P4Sync):
|
|||||||
if not self.cloneDestination:
|
if not self.cloneDestination:
|
||||||
self.cloneDestination = self.defaultDestination()
|
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.makedirs(self.cloneDestination)
|
||||||
os.chdir(self.cloneDestination)
|
os.chdir(self.cloneDestination)
|
||||||
system("git init")
|
system("git init")
|
||||||
@ -1357,6 +1366,7 @@ class P4Clone(P4Sync):
|
|||||||
system("git checkout -f")
|
system("git checkout -f")
|
||||||
else:
|
else:
|
||||||
print "Could not detect main branch. No checkout/master branch created."
|
print "Could not detect main branch. No checkout/master branch created."
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
class HelpFormatter(optparse.IndentedHelpFormatter):
|
class HelpFormatter(optparse.IndentedHelpFormatter):
|
||||||
|
Loading…
Reference in New Issue
Block a user