git-cl: Stop using Change class from presubmit support.

Bug: 1042324
Change-Id: I72db082f086f69bf49256d0613c39dc92ae0a07f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/2101471
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
Reviewed-by: Anthony Polito <apolito@google.com>
diff --git a/split_cl.py b/split_cl.py
index a814eb3..8004826 100644
--- a/split_cl.py
+++ b/split_cl.py
@@ -78,7 +78,7 @@
 
 def UploadCl(refactor_branch, refactor_branch_upstream, directory, files,
              description, comment, reviewers, changelist, cmd_upload,
-             cq_dry_run, enable_auto_submit):
+             cq_dry_run, enable_auto_submit, repository_root):
   """Uploads a CL with all changes to |files| in |refactor_branch|.
 
   Args:
@@ -102,10 +102,17 @@
     return
 
   # Checkout all changes to files in |files|.
-  deleted_files = [f.AbsoluteLocalPath() for f in files if f.Action() == 'D']
+  deleted_files = []
+  modified_files = []
+  for action, f in files:
+    abspath = os.path.abspath(os.path.join(repository_root, f))
+    if action == 'D':
+      deleted_files.append(abspath)
+    else:
+      modified_files.append(abspath)
+
   if deleted_files:
     git.run(*['rm'] + deleted_files)
-  modified_files = [f.AbsoluteLocalPath() for f in files if f.Action() != 'D']
   if modified_files:
     git.run(*['checkout', refactor_branch, '--'] + modified_files)
 
@@ -140,9 +147,9 @@
     values are lists of files sharing an OWNERS file.
   """
   files_split_by_owners = collections.defaultdict(list)
-  for f in files:
-    files_split_by_owners[owners_database.enclosing_dir_with_owners(
-        f.LocalPath())].append(f)
+  for _, f in files:
+    enclosing_dir = owners_database.enclosing_dir_with_owners(f)
+    files_split_by_owners[enclosing_dir].append(f)
   return files_split_by_owners
 
 
@@ -172,7 +179,7 @@
 
 
 def SplitCl(description_file, comment_file, changelist, cmd_upload, dry_run,
-            cq_dry_run, enable_auto_submit):
+            cq_dry_run, enable_auto_submit, repository_root):
   """"Splits a branch into smaller branches and uploads CLs.
 
   Args:
@@ -194,8 +201,11 @@
     EnsureInGitRepository()
 
     cl = changelist()
-    change = cl.GetChange(cl.GetCommonAncestorWithUpstream(), '')
-    files = change.AffectedFiles()
+    upstream = cl.GetCommonAncestorWithUpstream()
+    files = [
+        (action.strip(), f)
+        for action, f in scm.GIT.CaptureStatus(repository_root, upstream)
+    ]
 
     if not files:
       print('Cannot split an empty CL.')
@@ -208,8 +218,8 @@
     assert refactor_branch_upstream, \
         "Branch %s must have an upstream." % refactor_branch
 
-    owners_database = owners.Database(change.RepositoryRoot(), open, os.path)
-    owners_database.load_data_needed_for([f.LocalPath() for f in files])
+    owners_database = owners.Database(repository_root, open, os.path)
+    owners_database.load_data_needed_for([f for _, f in files])
 
     files_split_by_owners = GetFilesSplitByOwners(owners_database, files)
 
@@ -232,7 +242,7 @@
       # Use '/' as a path separator in the branch name and the CL description
       # and comment.
       directory = directory.replace(os.path.sep, '/')
-      file_paths = [f.LocalPath() for f in files]
+      file_paths = [f for _, f in files]
       reviewers = owners_database.reviewers_for(file_paths, author)
 
       if dry_run:
@@ -241,7 +251,7 @@
       else:
         UploadCl(refactor_branch, refactor_branch_upstream, directory, files,
                  description, comment, reviewers, changelist, cmd_upload,
-                 cq_dry_run, enable_auto_submit)
+                 cq_dry_run, enable_auto_submit, repository_root)
 
     # Go back to the original branch.
     git.run('checkout', refactor_branch)