From 97e050fce7a5b19dcaabe84f50452b2fdcdcc57c Mon Sep 17 00:00:00 2001 From: Paul Tarjan Date: Thu, 19 Mar 2020 11:14:19 -0700 Subject: [PATCH] Use a named remote and branches for staging to help git-lfs Summary: I'm working on a fairly large monorepo using phabricator and we are running into a `git-lfs` issue. Every single `arc diff` we have to wait many seconds while all our lfs files are walked before the push goes through. I chatted with the `git-lfs` folks in https://github.com/git-lfs/git-lfs/issues/4076 and they suggested this workflow change. I tested it on our repo and it does indeed seem to fix the issue. Three things were change: 1. The remote url is named 2. Use branches instead of tags 3. Do a `git fetch` (Also, hello after all this time! Hope you're all doing well over at phacility.) Test Plan: Before ``` $ arc diff Linting... LINT OKAY No lint problems. Running unit tests... UNIT OKAY No unit test failures. PUSH STAGING Pushing changes to staging area... Uploading LFS objects: 100% (8211/8211), 1.0 GB | 0 B/s, done. Enumerating objects: 31, done. Counting objects: 100% (31/31), done. Delta compression using up to 12 threads Compressing objects: 100% (21/21), done. Writing objects: 100% (24/24), 1.77 KiB | 8.00 KiB/s, done. Total 24 (delta 19), reused 0 (delta 0) remote: Resolving deltas: 100% (19/19), completed with 6 local objects. To github.com:robinhoodmarkets/web-staging.git * [new tag] 2581578b59b6341c1023377fd8741814e89fcd0c -> phabricator/base/427095 * [new tag] 7d9be50fbca590f15742d8cc20edd4f082dfbb3b -> phabricator/diff/427095 Updated an existing Differential revision: Revision URI: https://phabricator.robinhood.com/D135442 Included changes: M __shared/tools/arcanist-js/src/workflow/RHArcanistDiffWorkflow.php ``` After ``` $ arc diff Linting... LINT OKAY No lint problems. Running unit tests... UNIT OKAY No unit test failures. PUSH STAGING Pushing changes to staging area... Enumerating objects: 15, done. Counting objects: 100% (15/15), done. Delta compression using up to 12 threads Compressing objects: 100% (7/7), done. Writing objects: 100% (8/8), 638 bytes | 2.00 KiB/s, done. Total 8 (delta 6), reused 0 (delta 0) remote: Resolving deltas: 100% (6/6), completed with 6 local objects. To github.com:robinhoodmarkets/web-staging.git * [new branch] 2581578b59b6341c1023377fd8741814e89fcd0c -> phabricator/base/427105 * [new branch] 274cc3a25eb7856291c1d4c078b28b76af8a43b2 -> phabricator/diff/427105 Updated an existing Differential revision: Revision URI: https://phabricator.robinhood.com/D135442 Included changes: M __shared/tools/arcanist-js/src/workflow/RHArcanistDiffWorkflow.php ``` (notice the lack of `Uploading LFS objects`) Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D21041 --- src/workflow/ArcanistDiffWorkflow.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 7f117ca8..1823145d 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -2900,6 +2900,9 @@ EOTEXT 'uri' => $staging_uri, ); + list($stdout) = execx('git ls-files -z -- %s', ':(attr:filter=lfs)'); + $is_lfs = strpos($stdout, "\0") !== false; + // If the base commit is a real commit, we're going to push it. We don't // use this, but pushing it to a ref reduces the amount of redundant work // that Git does on later pushes by helping it figure out that the remote @@ -2923,7 +2926,7 @@ EOTEXT $refs[] = array( 'ref' => $diff_tag, 'type' => 'diff', - 'commit' => $commit, + 'commit' => $is_lfs ? $base_commit : $commit, 'remote' => $remote, ); @@ -2949,6 +2952,14 @@ EOTEXT 'use --skip-staging to skip this step.')); } + if ($is_lfs) { + $ref = '+'.$commit.':'.$diff_tag; + $err = phutil_passthru( + 'git push -- %s %s', + $staging_uri, + $ref); + } + return $refs; }