From bfd09ce88602ec030fb44576028afe7a0969dc1b Mon Sep 17 00:00:00 2001 From: "estade@chromium.org" Date: Wed, 5 Aug 2009 21:17:23 +0000 Subject: [PATCH] Get rid of annoying empty changelists! 1) don't save empty changelists to begin with. This guards against an accidental or canceled "gcl change" creating an empty file. 2) create a "clearempties" command which clears all changelists that don't have any files in them. Review URL: http://codereview.chromium.org/160139 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@22538 0039d316-1c4b-4281-b951-d872f2087c98 --- gcl.py | 24 +++++++++++++++++++++++- tests/gcl_unittest.py | 3 ++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gcl.py b/gcl.py index 054126758..70084d27f 100755 --- a/gcl.py +++ b/gcl.py @@ -681,6 +681,10 @@ Advanced commands: of changenames. --> Use 'gcl help try' for more information! + gcl deleteempties + Deletes all changelists that have no files associated with them. Careful, + you can lose your descriptions. + gcl help [command] Print this help menu, or help for the given command if it exists. """) @@ -973,7 +977,7 @@ def Change(change_info, override_description): description = change_info.description other_files = GetFilesNotInCL() - + #Edited files will have a letter for the first character in a string. #This regex looks for the presence of that character. file_re = re.compile(r"^[a-z].+\Z", re.IGNORECASE) @@ -1023,6 +1027,11 @@ def Change(change_info, override_description): status = line[:7] file = line[7:] new_cl_files.append((status, file)) + + if (not len(change_info._files)) and (not change_info.issue) and \ + (not len(new_description) and (not new_cl_files)): + ErrorExit("Empty changelist not saved") + change_info._files = new_cl_files change_info.Save() @@ -1094,6 +1103,16 @@ def Changes(): print "".join(file) +def DeleteEmptyChangeLists(): + """Delete all changelists that have no files.""" + print "\n--- Deleting:" + for cl in GetCLs(): + change_info = ChangeInfo.Load(cl, GetRepositoryRoot(), True, True) + if not len(change_info._files): + print change_info.name + change_info.Delete() + + def main(argv=None): if argv is None: argv = sys.argv @@ -1151,6 +1170,9 @@ def main(argv=None): print '\n'.join(("%s: %s" % (str(k), str(v)) for (k,v) in CODEREVIEW_SETTINGS.iteritems())) return 0 + if command == "deleteempties": + DeleteEmptyChangeLists() + return 0 if len(argv) == 2: if command == "change": diff --git a/tests/gcl_unittest.py b/tests/gcl_unittest.py index 3d3116765..48e5642a0 100755 --- a/tests/gcl_unittest.py +++ b/tests/gcl_unittest.py @@ -41,7 +41,8 @@ class GclUnittest(GclTestsBase): self.mox.ReplayAll() members = [ 'CODEREVIEW_SETTINGS', 'CODEREVIEW_SETTINGS_FILE', 'CPP_EXTENSIONS', - 'Change', 'ChangeInfo', 'Changes', 'Commit', 'DoPresubmitChecks', + 'Change', 'ChangeInfo', 'Changes', 'DeleteEmptyChangeLists', 'Commit', + 'DoPresubmitChecks', 'ErrorExit', 'FILES_CACHE', 'FilterFlag', 'GenerateChangeName', 'GenerateDiff', 'GetCacheDir', 'GetCachedFile', 'GetChangesDir', 'GetCLs',