[PATCH 2 of 2 RFC V2] largefiles: abort push on server when file fit largefiles (issue3245)

liscju piotr.listkiewicz at gmail.com
Fri Aug 26 02:23:13 EDT 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1472122627 -7200
#      Thu Aug 25 12:57:07 2016 +0200
# Node ID cc9384381d9f7995947b7294df1d7f8b5188237d
# Parent  7fa71874c771a76bcc0e04d77e435242b9b3ad12
largefiles: abort push on server when file fit largefiles  (issue3245)

This is done by adding function that when set up as pretxnchangegroup
hook checks if ordinary files that are about to be pushed fit
the largefiles pattern or exceed size specified in largefiles.minsize.
For now there is only hook for checking all revisions, maybe it should
be another for checking only head revisions, im waiting for opinions
about it.
Another issue is whether all ordinary files should be checked or
only ones that are modified/added. Now it checks all the files
so the ordinary file that fit largefile pattern added in some
older revision and exist in newer revision is detected as largefile
and push is aborted. I don't know if it is possible to recover from
this situation - is there a way to make ordinary file in some older
revision a largefile without converting whole repository.

diff --git a/hgext/largefiles/uisetup.py b/hgext/largefiles/uisetup.py
--- a/hgext/largefiles/uisetup.py
+++ b/hgext/largefiles/uisetup.py
@@ -35,6 +35,7 @@ from mercurial import (
 )
 
 from . import (
+    localstore,
     overrides,
     proto,
 )
@@ -205,3 +206,18 @@ def uisetup(ui):
 
     pushkey.register('largefiles', proto.pushlfilespattern,
                      proto.listlfilespattern)
+
+def _checkhook(ui, repo, node):
+    # Get revisions to check
+    revs = set()
+    for rev in xrange(repo[node].rev(), len(repo)):
+        revs.add(rev)
+
+    # remote is set to repo to force usage of local repo
+    store = localstore.localstore(ui, repo, repo)
+    store.checkfiletopush(revs)
+
+def checkallhook(ui, repo, node, hooktype, **kwargs):
+    """verify all ordinary files pushed to server
+    are not fitting largefiles pattern"""
+    _checkhook(ui, repo, node)
diff --git a/tests/test-largefiles-wireproto.t b/tests/test-largefiles-wireproto.t
--- a/tests/test-largefiles-wireproto.t
+++ b/tests/test-largefiles-wireproto.t
@@ -524,6 +524,55 @@ Client can disable checking by putting d
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
 
+  $ cd ..
+  $ rm hg.pid
+  $ killdaemons.py
+
+User can enable server side checking by adding checkallhook
+
+  $ cat >> enforcingserver/.hg/hgrc <<EOF
+  > [hooks]
+  > pretxnchangegroup.checklargefiles=python:hgext.largefiles.uisetup.checkallhook
+  > EOF
+  $ hg serve -R enforcingserver -d -p $HGPORT --pid-file hg.pid
+  $ cat hg.pid >> $DAEMON_PIDS
+  $ cd encorcingclient
+  $ echo "d.jpg" >> d.jpg
+  $ hg add d.jpg
+  $ hg commit -m "d.jpg"
+  Invoking status precommit hook
+  A d.jpg
+  $ hg log -G
+  @  changeset:   2:40898419adba
+  |  tag:         tip
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     d.jpg
+  |
+  o  changeset:   1:d83de3df768d
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     b
+  |
+  o  changeset:   0:b348129d325a
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     a
+  
+  $ hg push
+  pushing to http://localhost:$HGPORT/
+  searching for changes
+  remote: adding changesets
+  remote: adding manifests
+  remote: adding file changes
+  remote: added 1 changesets with 1 changes to 1 files
+  remote: error: pretxnchangegroup.checklargefiles hook failed: Files b.jpg in revision 2 should be marked as largefiles
+  remote: transaction abort!
+  remote: rollback completed
+  remote: Files b.jpg in revision 2 should be marked as largefiles
+  abort: push failed on remote
+  [255]
+
   $ killdaemons.py
 
 #endif


More information about the Mercurial-devel mailing list