@matheusbsbs / matheus-bagliano / commits / b86f73782e
Fork 0

remove global .gitdir

Signed-off-by: Han-Wen Nienhuys <hanwen@google.com>

Han-Wen Nienhuys committed May 23, 2007 at 18:49 UTC b86f73782eafd1c61bb706ec5ca3d1ec548d82f5
1 file changed +24 -29
contrib/fast-import/git-p4
+24 -29
@@ -14,7 +14,6 @@ import re
14
15 from sets import Set;
16
17 -gitdir = os.environ.get("GIT_DIR", "")
17 verbose = False
18
19 def write_pipe(c, str):
@@ -469,9 +468,7 @@ class P4Submit(Command):
468 % (fileName, fileName))
469
470 def run(self, args):
472 - global gitdir
471 # make gitdir absolute so we can cd out into the perforce checkout
474 - gitdir = os.path.abspath(gitdir)
472 os.environ["GIT_DIR"] = gitdir
473
474 if len(args) == 0:
@@ -510,7 +507,7 @@ class P4Submit(Command):
507 print "No changes in working directory to submit."
508 return True
509 patch = read_pipe("git diff -p --binary --diff-filter=ACMRTUXB HEAD")
513 - self.diffFile = gitdir + "/p4-git-diff"
510 + self.diffFile = self.gitdir + "/p4-git-diff"
511 f = open(self.diffFile, "wb")
512 f.write(patch)
513 f.close();
@@ -535,7 +532,7 @@ class P4Submit(Command):
532 self.logSubstitutions[tokens[0]] = tokens[1]
533
534 self.check()
538 - self.configFile = gitdir + "/p4-git-sync.cfg"
535 + self.configFile = self.gitdir + "/p4-git-sync.cfg"
536 self.config = shelve.open(self.configFile, writeback=True)
537
538 if self.firstTime:
@@ -799,7 +796,7 @@ class P4Sync(Command):
796 continue
797 self.users[output["User"]] = output["FullName"] + " <" + output["Email"] + ">"
798
802 - cache = open(gitdir + "/p4-usercache.txt", "wb")
799 + cache = open(self.gitdir + "/p4-usercache.txt", "wb")
800 for user in self.users.keys():
801 cache.write("%s\t%s\n" % (user, self.users[user]))
802 cache.close();
@@ -809,7 +806,7 @@ class P4Sync(Command):
806 self.users = {}
807 self.userMapFromPerforceServer = False
808 try:
812 - cache = open(gitdir + "/p4-usercache.txt", "rb")
809 + cache = open(self.gitdir + "/p4-usercache.txt", "rb")
810 lines = cache.readlines()
811 cache.close()
812 for line in lines:
@@ -1283,8 +1280,6 @@ class P4Clone(P4Sync):
1280 self.needsGit = False
1281
1282 def run(self, args):
1286 - global gitdir
1287 -
1283 if len(args) < 1:
1284 return False
1285
@@ -1310,7 +1305,7 @@ class P4Clone(P4Sync):
1305 os.makedirs(self.cloneDestination)
1306 os.chdir(self.cloneDestination)
1307 system("git init")
1313 - gitdir = os.getcwd() + "/.git"
1308 + self.gitdir = os.getcwd() + "/.git"
1309 if not P4Sync.run(self, depotPaths):
1310 return False
1311 if self.branch != "master":
@@ -1340,12 +1335,12 @@ def printUsage(commands):
1335 print ""
1336
1337 commands = {
1343 - "debug" : P4Debug(),
1344 - "submit" : P4Submit(),
1345 - "sync" : P4Sync(),
1346 - "rebase" : P4Rebase(),
1347 - "clone" : P4Clone(),
1348 - "rollback" : P4RollBack()
1338 + "debug" : P4Debug,
1339 + "submit" : P4Submit,
1340 + "sync" : P4Sync,
1341 + "rebase" : P4Rebase,
1342 + "clone" : P4Clone,
1343 + "rollback" : P4RollBack
1344 }
1345
1346
@@ -1357,7 +1352,8 @@ def main():
1352 cmd = ""
1353 cmdName = sys.argv[1]
1354 try:
1360 - cmd = commands[cmdName]
1355 + klass = commands[cmdName]
1356 + cmd = klass()
1357 except KeyError:
1358 print "unknown command %s" % cmdName
1359 print ""
@@ -1365,7 +1361,7 @@ def main():
1361 sys.exit(2)
1362
1363 options = cmd.options
1368 - cmd.gitdir = gitdir
1364 + cmd.gitdir = os.environ.get("GIT_DIR", None)
1365
1366 args = sys.argv[2:]
1367
@@ -1381,23 +1377,22 @@ def main():
1377 global verbose
1378 verbose = cmd.verbose
1379 if cmd.needsGit:
1384 - gitdir = cmd.gitdir
1385 - if len(gitdir) == 0:
1386 - gitdir = ".git"
1387 - if not isValidGitDir(gitdir):
1388 - gitdir = read_pipe("git rev-parse --git-dir").strip()
1389 - if os.path.exists(gitdir):
1380 + if cmd.gitdir == None:
1381 + cmd.gitdir = os.path.abspath(".git")
1382 + if not isValidGitDir(cmd.gitdir):
1383 + cmd.gitdir = read_pipe("git rev-parse --git-dir").strip()
1384 + if os.path.exists(cmd.gitdir):
1385 cdup = read_pipe("git rev-parse --show-cdup").strip()
1386 if len(cdup) > 0:
1387 os.chdir(cdup);
1388
1394 - if not isValidGitDir(gitdir):
1395 - if isValidGitDir(gitdir + "/.git"):
1396 - gitdir += "/.git"
1389 + if not isValidGitDir(cmd.gitdir):
1390 + if isValidGitDir(cmd.gitdir + "/.git"):
1391 + cmd.gitdir += "/.git"
1392 else:
1398 - die("fatal: cannot locate git repository at %s" % gitdir)
1393 + die("fatal: cannot locate git repository at %s" % cmd.gitdir)
1394
1400 - os.environ["GIT_DIR"] = gitdir
1395 + os.environ["GIT_DIR"] = cmd.gitdir
1396
1397 if not cmd.run(args):
1398 parser.print_help()