personal cache change

1. catch exception during init
2. change local cache default path to home when
local disk is not available
diff --git a/project.py b/project.py
index e4ed7d0..3c2a58a 100644
--- a/project.py
+++ b/project.py
@@ -1746,7 +1746,8 @@
         cmd.append(str((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)))
       else:
         cmd.append(str((u'+%s:' % branch) + remote.ToLocal(branch)))
-
+ 
+    ok = False
     for _i in range(2):
       ret = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy, gitdir=self.localcache).Wait()
       if ret == 0:
@@ -2110,8 +2111,12 @@
     if not os.path.exists(self.gitdir):
 
       if self.localcache and not os.path.exists(self.localcache):
-        os.makedirs(self.localcache)
-        self.bare_cache.init()
+        try:
+            os.makedirs(self.localcache)
+            self.bare_cache.init()
+        except:
+            print("init local cache %s failed. %s" % (self.localcache, traceback.format_exc()), file=sys.stderr)
+            self.localcache = None
 
       # Initialize the bare repository, which contains all of the objects.
       if not os.path.exists(self.objdir):
diff --git a/repo b/repo
index 83ab888..6b57673 100755
--- a/repo
+++ b/repo
@@ -4,7 +4,7 @@
 ##
 REPO_URL = 'ssh://mtksgt08:29418/git-repo'
 REPO_REV = 'mediatek/dev'
-LOCAL_CACHE = '{user_home}/.git-objects'
+LOCAL_CACHE = '/git.cache/%s'
 
 # Copyright (C) 2008 Google Inc.
 #
@@ -767,8 +767,14 @@
         '--']
 
   if LOCAL_CACHE:
-    cache = LOCAL_CACHE.format(user_home=os.environ['HOME'])
-    orig_args.insert(0, '--local-cache=%s' % cache)
+    cache = LOCAL_CACHE % os.environ['USER']
+    if not os.path.exists(cache):
+        try:
+            os.makedirs(cache)
+            os.chmod(cache, 0700)
+        except OSError as e:
+            cache = '%s/.git.cache' % (os.environ['HOME'])
+    if cache: orig_args.insert(0, '--local-cache=%s' % cache)
 
   me.extend(orig_args)
   me.extend(extra_args)