1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-05-04 03:06:13 +02:00

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:
Han-Wen Nienhuys 2007-05-23 18:49:35 -03:00
parent d2c6dd30ef
commit 86dff6b676

View File

@ -16,40 +16,44 @@ from sets import Set;
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:
sys.stderr.write('writing pipe: %s\n' % c)
sys.stderr.write('Writing pipe: %s\n' % c)
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:
sys.stderr.write('reading pipe: %s\n' % c)
sys.stderr.write('Reading pipe: %s\n' % c)
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:
sys.stderr.write('reading pipe: %s\n' % c)
sys.stderr.write('Reading pipe: %s\n' % c)
## 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
@ -105,10 +109,6 @@ def p4Where(depotPath):
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()
@ -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("--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:
@ -876,10 +877,14 @@ class P4Sync(Command):
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 ?
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"])
@ -911,9 +916,11 @@ class P4Sync(Command):
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)
@ -923,7 +930,8 @@ class P4Sync(Command):
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()
@ -998,7 +1006,7 @@ class P4Sync(Command):
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");
@ -1023,6 +1031,7 @@ class P4Sync(Command):
p4Change = 0
for branch in self.p4BranchesInGit:
print self.p4BranchesInGit
logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
settings = extractSettingsGitLog(logMsg)
@ -1125,7 +1134,7 @@ class P4Sync(Command):
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()) }
@ -1183,7 +1192,7 @@ class P4Sync(Command):
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)
@ -1344,7 +1353,7 @@ class P4Clone(P4Sync):
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")
@ -1357,6 +1366,7 @@ class P4Clone(P4Sync):
system("git checkout -f")
else:
print "Could not detect main branch. No checkout/master branch created."
return True
class HelpFormatter(optparse.IndentedHelpFormatter):