summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 5e926ee)
raw | patch | inline | side by side (parent: 5e926ee)
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> | |
Wed, 30 May 2007 16:58:19 +0000 (13:58 -0300) |
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
contrib/fast-import/git-p4 | patch | blob | history |
index 28ea53dea4c45fb3112bea175a4f91d5fe0e0d7d..6501387657cc8c25fc92ee1269a8bdceaba3b12b 100755 (executable)
from sets import Set;
-gitdir = os.environ.get("GIT_DIR", "")
verbose = False
def write_pipe(c, str):
% (fileName, fileName))
def run(self, args):
- global gitdir
# make gitdir absolute so we can cd out into the perforce checkout
- gitdir = os.path.abspath(gitdir)
os.environ["GIT_DIR"] = gitdir
if len(args) == 0:
print "No changes in working directory to submit."
return True
patch = read_pipe("git diff -p --binary --diff-filter=ACMRTUXB HEAD")
- self.diffFile = gitdir + "/p4-git-diff"
+ self.diffFile = self.gitdir + "/p4-git-diff"
f = open(self.diffFile, "wb")
f.write(patch)
f.close();
self.logSubstitutions[tokens[0]] = tokens[1]
self.check()
- self.configFile = gitdir + "/p4-git-sync.cfg"
+ self.configFile = self.gitdir + "/p4-git-sync.cfg"
self.config = shelve.open(self.configFile, writeback=True)
if self.firstTime:
continue
self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
- cache = open(gitdir + "/p4-usercache.txt", "wb")
+ cache = open(self.gitdir + "/p4-usercache.txt", "wb")
for user in self.users.keys():
cache.write("%s\t%s\n" % (user, self.users[user]))
cache.close();
self.users = {}
self.userMapFromPerforceServer = False
try:
- cache = open(gitdir + "/p4-usercache.txt", "rb")
+ cache = open(self.gitdir + "/p4-usercache.txt", "rb")
lines = cache.readlines()
cache.close()
for line in lines:
self.needsGit = False
def run(self, args):
- global gitdir
-
if len(args) < 1:
return False
os.makedirs(self.cloneDestination)
os.chdir(self.cloneDestination)
system("git init")
- gitdir = os.getcwd() + "/.git"
+ self.gitdir = os.getcwd() + "/.git"
if not P4Sync.run(self, depotPaths):
return False
if self.branch != "master":
print ""
commands = {
- "debug" : P4Debug(),
- "submit" : P4Submit(),
- "sync" : P4Sync(),
- "rebase" : P4Rebase(),
- "clone" : P4Clone(),
- "rollback" : P4RollBack()
+ "debug" : P4Debug,
+ "submit" : P4Submit,
+ "sync" : P4Sync,
+ "rebase" : P4Rebase,
+ "clone" : P4Clone,
+ "rollback" : P4RollBack
}
cmd = ""
cmdName = sys.argv[1]
try:
- cmd = commands[cmdName]
+ klass = commands[cmdName]
+ cmd = klass()
except KeyError:
print "unknown command %s" % cmdName
print ""
sys.exit(2)
options = cmd.options
- cmd.gitdir = gitdir
+ cmd.gitdir = os.environ.get("GIT_DIR", None)
args = sys.argv[2:]
global verbose
verbose = cmd.verbose
if cmd.needsGit:
- gitdir = cmd.gitdir
- if len(gitdir) == 0:
- gitdir = ".git"
- if not isValidGitDir(gitdir):
- gitdir = read_pipe("git rev-parse --git-dir").strip()
- if os.path.exists(gitdir):
+ if cmd.gitdir == None:
+ cmd.gitdir = os.path.abspath(".git")
+ if not isValidGitDir(cmd.gitdir):
+ cmd.gitdir = read_pipe("git rev-parse --git-dir").strip()
+ if os.path.exists(cmd.gitdir):
cdup = read_pipe("git rev-parse --show-cdup").strip()
if len(cdup) > 0:
os.chdir(cdup);
- if not isValidGitDir(gitdir):
- if isValidGitDir(gitdir + "/.git"):
- gitdir += "/.git"
+ if not isValidGitDir(cmd.gitdir):
+ if isValidGitDir(cmd.gitdir + "/.git"):
+ cmd.gitdir += "/.git"
else:
- die("fatal: cannot locate git repository at %s" % gitdir)
+ die("fatal: cannot locate git repository at %s" % cmd.gitdir)
- os.environ["GIT_DIR"] = gitdir
+ os.environ["GIT_DIR"] = cmd.gitdir
if not cmd.run(args):
parser.print_help()