[patchew-devel] [PATCH] cli: clone recursively only for tester

Fam Zheng posted 1 patch 6 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20180301025034.20913-1-famz@redhat.com
patchew-cli | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
[patchew-devel] [PATCH] cli: clone recursively only for tester
Posted by Fam Zheng 6 years, 1 month ago
Both tester and apply (applier mode) subcommands call git_clone_repo.
"--recursive" option was added so that repos that contain submodules
will likely just work with all the submodules present (although that can
be optimized too, to save time and bandwidth), but it is not necessary
for appliers and can significantly slow down the process because the
submodule repos are not cached.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 patchew-cli | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/patchew-cli b/patchew-cli
index eb8b91c..52329e1 100755
--- a/patchew-cli
+++ b/patchew-cli
@@ -29,7 +29,7 @@ COOKIE_FILENAME = os.path.expanduser("~/.patchew.cookie")
 class APIError(Exception):
     pass
 
-def git_clone_repo(clone, remote, head, logf, checkout=True):
+def git_clone_repo(clone, remote, head, logf, checkout=True, recursive=False):
     cache_repo = os.path.join(os.path.expanduser("~/.cache/patchew-git-cache"),
                               "".join([x for x in remote if x.isalnum()]) + "-" + \
                                       hashlib.sha1(remote.encode("utf-8")).hexdigest())
@@ -46,8 +46,11 @@ def git_clone_repo(clone, remote, head, logf, checkout=True):
     subprocess.check_call(["git", "remote", "add", "-f", "--mirror=fetch",
                           remote_name, remote], cwd=cache_repo,
                           stdout=logf, stderr=logf)
-    subprocess.check_call(["git", "clone", "-q", "--recursive", cache_repo, clone],
-                          stderr=logf, stdout=logf)
+    clone_cmd = ["git", "clone", "-q"]
+    if recursive:
+        clone_cmd += ["--recursive"]
+    clone_cmd += [cache_repo, clone]
+    subprocess.check_call(clone_cmd, stderr=logf, stdout=logf)
     if checkout:
         subprocess.check_call(["git", "checkout", head, "-b", "test"],
                               stderr=logf, stdout=logf,
@@ -510,7 +513,7 @@ class TesterCommand(SubCommand):
         is_timeout = False
         try:
             clone = os.path.join(wd, "src")
-            git_clone_repo(clone, r["repo"], r["head"], logf)
+            git_clone_repo(clone, r["repo"], r["head"], logf, True)
             base = r["base"]
             if base:
                 subprocess.check_call(["git", "branch", "base", base],
-- 
2.14.3


[patchew-devel] Re: [PATCH] cli: clone recursively only for tester
Posted by Paolo Bonzini 6 years, 1 month ago
On 01/03/2018 03:50, Fam Zheng wrote:
> Both tester and apply (applier mode) subcommands call git_clone_repo.
> "--recursive" option was added so that repos that contain submodules
> will likely just work with all the submodules present (although that can
> be optimized too, to save time and bandwidth), but it is not necessary
> for appliers and can significantly slow down the process because the
> submodule repos are not cached.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
>  patchew-cli | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/patchew-cli b/patchew-cli
> index eb8b91c..52329e1 100755
> --- a/patchew-cli
> +++ b/patchew-cli
> @@ -29,7 +29,7 @@ COOKIE_FILENAME = os.path.expanduser("~/.patchew.cookie")
>  class APIError(Exception):
>      pass
>  
> -def git_clone_repo(clone, remote, head, logf, checkout=True):
> +def git_clone_repo(clone, remote, head, logf, checkout=True, recursive=False):
>      cache_repo = os.path.join(os.path.expanduser("~/.cache/patchew-git-cache"),
>                                "".join([x for x in remote if x.isalnum()]) + "-" + \
>                                        hashlib.sha1(remote.encode("utf-8")).hexdigest())
> @@ -46,8 +46,11 @@ def git_clone_repo(clone, remote, head, logf, checkout=True):
>      subprocess.check_call(["git", "remote", "add", "-f", "--mirror=fetch",
>                            remote_name, remote], cwd=cache_repo,
>                            stdout=logf, stderr=logf)
> -    subprocess.check_call(["git", "clone", "-q", "--recursive", cache_repo, clone],
> -                          stderr=logf, stdout=logf)
> +    clone_cmd = ["git", "clone", "-q"]
> +    if recursive:
> +        clone_cmd += ["--recursive"]
> +    clone_cmd += [cache_repo, clone]
> +    subprocess.check_call(clone_cmd, stderr=logf, stdout=logf)
>      if checkout:
>          subprocess.check_call(["git", "checkout", head, "-b", "test"],
>                                stderr=logf, stdout=logf,
> @@ -510,7 +513,7 @@ class TesterCommand(SubCommand):
>          is_timeout = False
>          try:
>              clone = os.path.join(wd, "src")
> -            git_clone_repo(clone, r["repo"], r["head"], logf)
> +            git_clone_repo(clone, r["repo"], r["head"], logf, True)
>              base = r["base"]
>              if base:
>                  subprocess.check_call(["git", "branch", "base", base],
> 

Applied, thanks.

Paolo