def CMDchange(args): """Creates or edits a changelist. Only scans the current directory and subdirectories. """ # Verify the user is running the change command from a read-write checkout. svn_info = SVN.CaptureLocalInfo([], '.') if not svn_info: ErrorExit("Current checkout is unversioned. Please retry with a versioned " "directory.") if len(args) == 0: # Generate a random changelist name. changename = GenerateChangeName() elif args[0] == '--force': changename = GenerateChangeName() else: changename = args[0] change_info = ChangeInfo.Load(changename, GetRepositoryRoot(), False, True) if len(args) == 2: if not os.path.isfile(args[1]): ErrorExit('The change "%s" doesn\'t exist.' % args[1]) f = open(args[1], 'rU') override_description = f.read() f.close() else: override_description = None if change_info.issue and not change_info.NeedsUpload(): try: description = change_info.GetIssueDescription() except urllib2.HTTPError, err: if err.code == 404: # The user deleted the issue in Rietveld, so forget the old issue id. description = change_info.description change_info.issue = 0 change_info.Save() else: ErrorExit("Error getting the description from Rietveld: " + err)
def GetCachedFile(filename, max_age=60*60*24*3, use_root=False): """Retrieves a file from the repository and caches it in GetCacheDir() for max_age seconds. use_root: If False, look up the arborescence for the first match, otherwise go directory to the root repository. Note: The cache will be inconsistent if the same file is retrieved with both use_root=True and use_root=False. Don't be stupid. """ if filename not in FILES_CACHE: # Don't try to look up twice. FILES_CACHE[filename] = None # First we check if we have a cached version. try: cached_file = os.path.join(GetCacheDir(), filename) except (gclient_utils.Error, subprocess2.CalledProcessError): return None if (not os.path.exists(cached_file) or (time.time() - os.stat(cached_file).st_mtime) > max_age): dir_info = SVN.CaptureLocalInfo([], '.') repo_root = dir_info['Repository Root'] if use_root: url_path = repo_root else: url_path = dir_info['URL'] while True: # Look in the repository at the current level for the file. for _ in range(5): content = None try: # Take advantage of the fact that svn won't output to stderr in case # of success but will do in case of failure so don't mind putting # stderr into content_array. content_array = [] svn_path = url_path + '/' + filename args = ['svn', 'cat', svn_path] if sys.platform != 'darwin': # MacOSX 10.5.2 has a bug with svn 1.4.4 that will trigger the # 'Can\'t get username or password' and can be fixed easily. # The fix doesn't work if the user upgraded to svn 1.6.x. Bleh. # I don't have time to fix their broken stuff. args.append('--non-interactive') gclient_utils.CheckCallAndFilter( args, cwd='.', filter_fn=content_array.append) # Exit the loop if the file was found. Override content. content = '\n'.join(content_array) break except (gclient_utils.Error, subprocess2.CalledProcessError): if content_array[0].startswith( 'svn: Can\'t get username or password'): ErrorExit('Your svn credentials expired. Please run svn update ' 'to fix the cached credentials') if content_array[0].startswith('svn: Can\'t get password'): ErrorExit('If are using a Mac and svn --version shows 1.4.x, ' 'please hack gcl.py to remove --non-interactive usage, it\'s' 'a bug on your installed copy') if (content_array[0].startswith('svn: File not found:') or content_array[0].endswith('path not found')): break # Otherwise, fall through to trying again. if content: break if url_path == repo_root: # Reached the root. Abandoning search. break # Go up one level to try again. url_path = os.path.dirname(url_path) if content is not None or filename != CODEREVIEW_SETTINGS_FILE: # Write a cached version even if there isn't a file, so we don't try to # fetch it each time. codereview.settings must always be present so do # not cache negative. gclient_utils.FileWrite(cached_file, content or '') else: content = gclient_utils.FileRead(cached_file, 'r') # Keep the content cached in memory. FILES_CACHE[filename] = content return FILES_CACHE[filename]