Reduce git cl split oversplitting.

Without this change, git cl split will create a separate CL for every
file that has per-file owners rules. This is almost always the wrong
thing to do. With this change, it will at least aggregate all such files
to their parent directory. This may under-split, but is perhaps nearer
the mark.

Change-Id: Iea7997b36d053713fa00f1261ea032e09d9c2818
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2555729
Auto-Submit: Sigurður Ásgeirsson <siggi@chromium.org>
Commit-Queue: Dirk Pranke <dpranke@google.com>
Reviewed-by: Dirk Pranke <dpranke@google.com>
diff --git a/split_cl.py b/split_cl.py
index 65dede1..5ed8a57 100644
--- a/split_cl.py
+++ b/split_cl.py
@@ -152,6 +152,10 @@
   files_split_by_owners = collections.defaultdict(list)
   for action, path in files:
     enclosing_dir = owners_database.enclosing_dir_with_owners(path)
+    # Anything matching a per-file rule will return its own path.
+    # Aggregate up to the parent directory so as not to over-split.
+    if enclosing_dir == path:
+      enclosing_dir = os.path.dirname(path)
     files_split_by_owners[enclosing_dir].append((action, path))
   return files_split_by_owners