remove global .gitdir
Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>
This commit is contained in:
parent
5e926eed9f
commit
b86f73782e
@ -14,7 +14,6 @@ import re
|
|||||||
|
|
||||||
from sets import Set;
|
from sets import Set;
|
||||||
|
|
||||||
gitdir = os.environ.get("GIT_DIR", "")
|
|
||||||
verbose = False
|
verbose = False
|
||||||
|
|
||||||
def write_pipe(c, str):
|
def write_pipe(c, str):
|
||||||
@ -469,9 +468,7 @@ class P4Submit(Command):
|
|||||||
% (fileName, fileName))
|
% (fileName, fileName))
|
||||||
|
|
||||||
def run(self, args):
|
def run(self, args):
|
||||||
global gitdir
|
|
||||||
# make gitdir absolute so we can cd out into the perforce checkout
|
# make gitdir absolute so we can cd out into the perforce checkout
|
||||||
gitdir = os.path.abspath(gitdir)
|
|
||||||
os.environ["GIT_DIR"] = gitdir
|
os.environ["GIT_DIR"] = gitdir
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
@ -510,7 +507,7 @@ class P4Submit(Command):
|
|||||||
print "No changes in working directory to submit."
|
print "No changes in working directory to submit."
|
||||||
return True
|
return True
|
||||||
patch = read_pipe("git diff -p --binary --diff-filter=ACMRTUXB HEAD")
|
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 = open(self.diffFile, "wb")
|
||||||
f.write(patch)
|
f.write(patch)
|
||||||
f.close();
|
f.close();
|
||||||
@ -535,7 +532,7 @@ class P4Submit(Command):
|
|||||||
self.logSubstitutions[tokens[0]] = tokens[1]
|
self.logSubstitutions[tokens[0]] = tokens[1]
|
||||||
|
|
||||||
self.check()
|
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)
|
self.config = shelve.open(self.configFile, writeback=True)
|
||||||
|
|
||||||
if self.firstTime:
|
if self.firstTime:
|
||||||
@ -799,7 +796,7 @@ class P4Sync(Command):
|
|||||||
continue
|
continue
|
||||||
self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
|
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():
|
for user in self.users.keys():
|
||||||
cache.write("%s\t%s\n" % (user, self.users[user]))
|
cache.write("%s\t%s\n" % (user, self.users[user]))
|
||||||
cache.close();
|
cache.close();
|
||||||
@ -809,7 +806,7 @@ class P4Sync(Command):
|
|||||||
self.users = {}
|
self.users = {}
|
||||||
self.userMapFromPerforceServer = False
|
self.userMapFromPerforceServer = False
|
||||||
try:
|
try:
|
||||||
cache = open(gitdir + "/p4-usercache.txt", "rb")
|
cache = open(self.gitdir + "/p4-usercache.txt", "rb")
|
||||||
lines = cache.readlines()
|
lines = cache.readlines()
|
||||||
cache.close()
|
cache.close()
|
||||||
for line in lines:
|
for line in lines:
|
||||||
@ -1283,8 +1280,6 @@ class P4Clone(P4Sync):
|
|||||||
self.needsGit = False
|
self.needsGit = False
|
||||||
|
|
||||||
def run(self, args):
|
def run(self, args):
|
||||||
global gitdir
|
|
||||||
|
|
||||||
if len(args) < 1:
|
if len(args) < 1:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -1310,7 +1305,7 @@ class P4Clone(P4Sync):
|
|||||||
os.makedirs(self.cloneDestination)
|
os.makedirs(self.cloneDestination)
|
||||||
os.chdir(self.cloneDestination)
|
os.chdir(self.cloneDestination)
|
||||||
system("git init")
|
system("git init")
|
||||||
gitdir = os.getcwd() + "/.git"
|
self.gitdir = os.getcwd() + "/.git"
|
||||||
if not P4Sync.run(self, depotPaths):
|
if not P4Sync.run(self, depotPaths):
|
||||||
return False
|
return False
|
||||||
if self.branch != "master":
|
if self.branch != "master":
|
||||||
@ -1340,12 +1335,12 @@ def printUsage(commands):
|
|||||||
print ""
|
print ""
|
||||||
|
|
||||||
commands = {
|
commands = {
|
||||||
"debug" : P4Debug(),
|
"debug" : P4Debug,
|
||||||
"submit" : P4Submit(),
|
"submit" : P4Submit,
|
||||||
"sync" : P4Sync(),
|
"sync" : P4Sync,
|
||||||
"rebase" : P4Rebase(),
|
"rebase" : P4Rebase,
|
||||||
"clone" : P4Clone(),
|
"clone" : P4Clone,
|
||||||
"rollback" : P4RollBack()
|
"rollback" : P4RollBack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1357,7 +1352,8 @@ def main():
|
|||||||
cmd = ""
|
cmd = ""
|
||||||
cmdName = sys.argv[1]
|
cmdName = sys.argv[1]
|
||||||
try:
|
try:
|
||||||
cmd = commands[cmdName]
|
klass = commands[cmdName]
|
||||||
|
cmd = klass()
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print "unknown command %s" % cmdName
|
print "unknown command %s" % cmdName
|
||||||
print ""
|
print ""
|
||||||
@ -1365,7 +1361,7 @@ def main():
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
options = cmd.options
|
options = cmd.options
|
||||||
cmd.gitdir = gitdir
|
cmd.gitdir = os.environ.get("GIT_DIR", None)
|
||||||
|
|
||||||
args = sys.argv[2:]
|
args = sys.argv[2:]
|
||||||
|
|
||||||
@ -1381,23 +1377,22 @@ def main():
|
|||||||
global verbose
|
global verbose
|
||||||
verbose = cmd.verbose
|
verbose = cmd.verbose
|
||||||
if cmd.needsGit:
|
if cmd.needsGit:
|
||||||
gitdir = cmd.gitdir
|
if cmd.gitdir == None:
|
||||||
if len(gitdir) == 0:
|
cmd.gitdir = os.path.abspath(".git")
|
||||||
gitdir = ".git"
|
if not isValidGitDir(cmd.gitdir):
|
||||||
if not isValidGitDir(gitdir):
|
cmd.gitdir = read_pipe("git rev-parse --git-dir").strip()
|
||||||
gitdir = read_pipe("git rev-parse --git-dir").strip()
|
if os.path.exists(cmd.gitdir):
|
||||||
if os.path.exists(gitdir):
|
|
||||||
cdup = read_pipe("git rev-parse --show-cdup").strip()
|
cdup = read_pipe("git rev-parse --show-cdup").strip()
|
||||||
if len(cdup) > 0:
|
if len(cdup) > 0:
|
||||||
os.chdir(cdup);
|
os.chdir(cdup);
|
||||||
|
|
||||||
if not isValidGitDir(gitdir):
|
if not isValidGitDir(cmd.gitdir):
|
||||||
if isValidGitDir(gitdir + "/.git"):
|
if isValidGitDir(cmd.gitdir + "/.git"):
|
||||||
gitdir += "/.git"
|
cmd.gitdir += "/.git"
|
||||||
else:
|
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):
|
if not cmd.run(args):
|
||||||
parser.print_help()
|
parser.print_help()
|
||||||
|
Loading…
Reference in New Issue
Block a user