command: Move smart sync override logic to Command base class

Deduplicate the logic for loading `smart_sync_override.xml` by
moving it from `forall.py` to the `Command` base class. This allows
other commands to reuse it to respect smart tags.

Bug: 279204331
Change-Id: I6f2f03995266c2a68c3225cacb92b2f580a89178
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/582502
Tested-by: Gavin Mak <gavinmak@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
diff --git a/command.py b/command.py
index ee1f68c..129919c 100644
--- a/command.py
+++ b/command.py
@@ -516,6 +516,22 @@
         )
         return result
 
+    def GetSmartSyncOverridePath(self, manifest=None) -> str:
+        """Return the path where smart sync writes its override manifest."""
+        if manifest is None:
+            manifest = self.manifest
+        return os.path.join(
+            manifest.manifestProject.worktree, "smart_sync_override.xml"
+        )
+
+    def TryOverrideManifestWithSmartSync(self, manifest=None) -> None:
+        """Override manifest with smart_sync_override.xml if it exists."""
+        if manifest is None:
+            manifest = self.manifest
+        smart_sync_manifest_path = self.GetSmartSyncOverridePath(manifest)
+        if os.path.isfile(smart_sync_manifest_path):
+            manifest.Override(smart_sync_manifest_path)
+
     def ManifestList(self, opt):
         """Yields all of the manifests to traverse.
 
diff --git a/subcmds/forall.py b/subcmds/forall.py
index 01c2f0d..2304e43 100644
--- a/subcmds/forall.py
+++ b/subcmds/forall.py
@@ -242,13 +242,7 @@
 
         mirror = self.manifest.IsMirror
 
-        smart_sync_manifest_name = "smart_sync_override.xml"
-        smart_sync_manifest_path = os.path.join(
-            self.manifest.manifestProject.worktree, smart_sync_manifest_name
-        )
-
-        if os.path.isfile(smart_sync_manifest_path):
-            self.manifest.Override(smart_sync_manifest_path)
+        self.TryOverrideManifestWithSmartSync()
 
         if opt.regex:
             projects = self.FindProjects(args, all_manifests=all_trees)
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 291bc62..8c25911 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -2050,9 +2050,7 @@
             manifest.Override(opt.manifest_name)
 
         manifest_name = opt.manifest_name
-        smart_sync_manifest_path = os.path.join(
-            manifest.manifestProject.worktree, "smart_sync_override.xml"
-        )
+        smart_sync_manifest_path = self.GetSmartSyncOverridePath(manifest)
 
         if opt.clone_bundle is None:
             opt.clone_bundle = manifest.CloneBundle