Patchwork lfs: defer registering the pre-push hook until blobs are committed

login
register
mail settings
Submitter Matt Harbison
Date Jan. 19, 2018, 2:21 a.m.
Message ID <4e88280e794b1caafabf.1516328462@Envy>
Download mbox | patch
Permalink /patch/26941/
State Accepted
Headers show

Comments

Matt Harbison - Jan. 19, 2018, 2:21 a.m.
# HG changeset patch
# User Matt Harbison <matt_harbison@yahoo.com>
# Date 1516328290 18000
#      Thu Jan 18 21:18:10 2018 -0500
# Node ID 4e88280e794b1caafabf903a6afadbe0bd4402c0
# Parent  45b678bf3a787085d56fad5bee494e0c160aa120
lfs: defer registering the pre-push hook until blobs are committed

The hook searches outgoing commits for blobs, and uploads them before letting
the push occur.  No reason to search for that which isn't there.
Yuya Nishihara - Jan. 19, 2018, 3:09 p.m.
On Thu, 18 Jan 2018 21:21:02 -0500, Matt Harbison wrote:
> # HG changeset patch
> # User Matt Harbison <matt_harbison@yahoo.com>
> # Date 1516328290 18000
> #      Thu Jan 18 21:18:10 2018 -0500
> # Node ID 4e88280e794b1caafabf903a6afadbe0bd4402c0
> # Parent  45b678bf3a787085d56fad5bee494e0c160aa120
> lfs: defer registering the pre-push hook until blobs are committed

Queued, thanks.

Patch

diff --git a/hgext/lfs/__init__.py b/hgext/lfs/__init__.py
--- a/hgext/lfs/__init__.py
+++ b/hgext/lfs/__init__.py
@@ -156,9 +156,6 @@ 
     repo.svfs.lfslocalblobstore = blobstore.local(repo)
     repo.svfs.lfsremoteblobstore = blobstore.remote(repo)
 
-    # Push hook
-    repo.prepushoutgoinghooks.add('lfs', wrapper.prepush)
-
     class lfsrepo(repo.__class__):
         @localrepo.unfilteredmethod
         def commitctx(self, ctx, error=False):
@@ -181,10 +178,13 @@ 
                 if any(ctx[f].islfs() for f in ctx.files() if f in ctx):
                     repo.requirements.add('lfs')
                     repo._writerequirements()
+                    repo.prepushoutgoinghooks.add('lfs', wrapper.prepush)
                     break
 
         ui.setconfig('hooks', 'commit.lfs', checkrequireslfs, 'lfs')
         ui.setconfig('hooks', 'pretxnchangegroup.lfs', checkrequireslfs, 'lfs')
+    else:
+        repo.prepushoutgoinghooks.add('lfs', wrapper.prepush)
 
 def _trackedmatcher(repo, ctx):
     """Return a function (path, size) -> bool indicating whether or not to