Refactor cache-updating code to eliminate unnecessary fetches.

This is an update of the following reverted change:

https://codereview.chromium.org/344443002/

R=hinoka@chromium.org,agable@chromium.org
BUG=

Review URL: https://codereview.chromium.org/343523002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@277931 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/git_cache.py b/git_cache.py
index 686d0e1..ca21a3c 100755
--- a/git_cache.py
+++ b/git_cache.py
@@ -318,6 +318,7 @@
 
   def populate(self, depth=None, shallow=False, bootstrap=False,
                verbose=False):
+    assert self.GetCachePath()
     if shallow and not depth:
       depth = 10000
     gclient_utils.safe_makedirs(self.GetCachePath())
@@ -429,6 +430,8 @@
   @classmethod
   def UnlockAll(cls):
     cachepath = cls.GetCachePath()
+    if not cachepath:
+      return
     dirlist = os.listdir(cachepath)
     repo_dirs = set([os.path.join(cachepath, path) for path in dirlist
                      if os.path.isdir(os.path.join(cachepath, path))])