Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Side by Side Diff: gcl.py

Issue 387067: Fix looking for local versions of cached files (Closed) Base URL: svn://chrome-svn/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Wrapper script around Rietveld's upload.py that groups files into 6 """Wrapper script around Rietveld's upload.py that groups files into
7 changelists.""" 7 changelists."""
8 8
9 import getpass 9 import getpass
10 import os 10 import os
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 if filename not in FILES_CACHE: 107 if filename not in FILES_CACHE:
108 # Don't try to look up twice. 108 # Don't try to look up twice.
109 FILES_CACHE[filename] = None 109 FILES_CACHE[filename] = None
110 # First we check if we have a cached version. 110 # First we check if we have a cached version.
111 try: 111 try:
112 cached_file = os.path.join(GetCacheDir(), filename) 112 cached_file = os.path.join(GetCacheDir(), filename)
113 except gclient_utils.Error: 113 except gclient_utils.Error:
114 return None 114 return None
115 if (not os.path.exists(cached_file) or 115 if (not os.path.exists(cached_file) or
116 os.stat(cached_file).st_mtime > max_age): 116 os.stat(cached_file).st_mtime > max_age):
117 local_dir = os.path.dirname(os.path.abspath(filename))
118 local_base = os.path.basename(filename)
119 dir_info = SVN.CaptureInfo(".") 117 dir_info = SVN.CaptureInfo(".")
120 repo_root = dir_info["Repository Root"] 118 repo_root = dir_info["Repository Root"]
121 if use_root: 119 if use_root:
122 url_path = repo_root 120 url_path = repo_root
123 else: 121 else:
124 url_path = dir_info["URL"] 122 url_path = dir_info["URL"]
125 content = "" 123 content = ""
126 while True: 124 while True:
127 # First, look for a locally modified version of the file if we can. 125 # Look in the repository at the current level for the file.
128 r = "" 126 svn_path = url_path + "/" + filename
129 if not use_root: 127 content, rc = RunShellWithReturnCode(["svn", "cat", svn_path])
130 local_path = os.path.join(local_dir, local_base)
131 r = SVN.CaptureStatus((local_path,))
132 rc = -1
133 if r:
134 status = r[0][0]
135 rc = 0
136 if not rc and status[0] in ('A','M'):
137 content = ReadFile(local_path)
138 rc = 0
139 else:
140 # Look in the repository if we didn't find something local.
141 svn_path = url_path + "/" + filename
142 content, rc = RunShellWithReturnCode(["svn", "cat", svn_path])
143
144 if not rc: 128 if not rc:
145 # Exit the loop if the file was found. Override content. 129 # Exit the loop if the file was found. Override content.
146 break 130 break
147 # Make sure to mark settings as empty if not found. 131 # Make sure to mark settings as empty if not found.
148 content = "" 132 content = ""
149 if url_path == repo_root: 133 if url_path == repo_root:
150 # Reached the root. Abandoning search. 134 # Reached the root. Abandoning search.
151 break 135 break
152 # Go up one level to try again. 136 # Go up one level to try again.
153 url_path = os.path.dirname(url_path) 137 url_path = os.path.dirname(url_path)
154 local_dir = os.path.dirname(local_dir)
155 # Write a cached version even if there isn't a file, so we don't try to 138 # Write a cached version even if there isn't a file, so we don't try to
156 # fetch it each time. 139 # fetch it each time.
157 WriteFile(cached_file, content) 140 WriteFile(cached_file, content)
158 else: 141 else:
159 content = ReadFile(cached_file) 142 content = ReadFile(cached_file)
160 # Keep the content cached in memory. 143 # Keep the content cached in memory.
161 FILES_CACHE[filename] = content 144 FILES_CACHE[filename] = content
162 return FILES_CACHE[filename] 145 return FILES_CACHE[filename]
163 146
164 147
(...skipping 1118 matching lines...) Expand 10 before | Expand all | Expand 10 after
1283 return 0 1266 return 0
1284 args =["svn", command] 1267 args =["svn", command]
1285 root = GetRepositoryRoot() 1268 root = GetRepositoryRoot()
1286 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()]) 1269 args.extend([os.path.join(root, x) for x in change_info.GetFileNames()])
1287 RunShell(args, True) 1270 RunShell(args, True)
1288 return 0 1271 return 0
1289 1272
1290 1273
1291 if __name__ == "__main__": 1274 if __name__ == "__main__":
1292 sys.exit(main()) 1275 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698