summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: d2c6dd3)
raw | patch | inline | side by side (parent: d2c6dd3)
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>
- 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 |
index 1d799708f6969bc0da91adeea6364176db8b9988..cc0b7013dabe75d6b354ff7de9af77fed3847d0f 100755 (executable)
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
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()
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:
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"])
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)
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()
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");
p4Change = 0
for branch in self.p4BranchesInGit:
+ print self.p4BranchesInGit
logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
settings = extractSettingsGitLog(logMsg)
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()) }
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)
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")
system("git checkout -f")
else:
print "Could not detect main branch. No checkout/master branch created."
+
return True
class HelpFormatter(optparse.IndentedHelpFormatter):