hgext/pushexperiment.py
author Shubhanshu Agrawal <agrawal.shubhanshu@gmail.com>
Fri, 11 Dec 2015 10:42:46 -0800
changeset 1563 6a9f0261b181
parent 1549 81a221db8a72
child 1757 86e71a0b3319
permissions -rw-r--r--
prune: remove a list of bookmarks Currently prune works with a single bookmark, the changes in this patch modifies the prune module to work with a list of bookmarks Building on this we can take a list of bookmarks as input and remove all of them in a single go
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     1
"""Small extension altering some push behavior
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     2
731
63ce4384be50 pushexperiment: fix doc typos
Julien Cristau <julien.cristau@logilab.fr>
parents: 729
diff changeset
     3
- Add a new wire protocol command to exchange obsolescence markers. Sending the
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     4
  raw file as a binary instead of using pushkey hack.
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
     5
- Add a "push done" notification
1549
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
     6
- Push obsolescence marker before anything else (This works around the lack
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
     7
of global transaction)
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     8
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
     9
"""
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    10
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    11
import errno
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    12
from StringIO import StringIO
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    13
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    14
from mercurial.i18n import _
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    15
from mercurial import extensions
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    16
from mercurial import wireproto
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    17
from mercurial import obsolete
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    18
from mercurial import localrepo
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    19
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    20
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    21
def client_pushobsmarkers(self, obsfile):
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    22
    """wireprotocol peer method"""
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    23
    self.requirecap('_push_experiment_pushobsmarkers_0',
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    24
                    _('push obsolete markers faster'))
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    25
    ret, output = self._callpush('push_experiment_pushobsmarkers_0', obsfile)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    26
    for l in output.splitlines(True):
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    27
        self.ui.status(_('remote: '), l)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    28
    return ret
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    29
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    30
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    31
def srv_pushobsmarkers(repo, proto):
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    32
    """wireprotocol command"""
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    33
    fp = StringIO()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    34
    proto.redirect()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    35
    proto.getfile(fp)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    36
    data = fp.getvalue()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    37
    fp.close()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    38
    lock = repo.lock()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    39
    try:
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    40
        tr = repo.transaction('pushkey: obsolete markers')
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    41
        try:
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    42
            repo.obsstore.mergemarkers(tr, data)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    43
            tr.close()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    44
        finally:
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    45
            tr.release()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    46
    finally:
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    47
        lock.release()
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    48
    return wireproto.pushres(0)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    49
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    50
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    51
def syncpush(orig, repo, remote):
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    52
    """wraper for obsolete.syncpush to use the fast way if possible"""
1217
196c650d5ba9 pushexperiment: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 732
diff changeset
    53
    if not (obsolete.isenabled(repo, obsolete.exchangeopt) and
196c650d5ba9 pushexperiment: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 732
diff changeset
    54
            repo.obsstore):
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    55
        return
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    56
    if remote.capable('_push_experiment_pushobsmarkers_0'):
729
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    57
        return # already pushed before changeset
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    58
        remote.push_experiment_pushobsmarkers_0(obsfp)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    59
        return
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    60
    return orig(repo, remote)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    61
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    62
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    63
def client_notifypushend(self):
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    64
    """wire peer  command to notify a push is done"""
1549
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
    65
    self.requirecap('_push_experiment_notifypushend_0',
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
    66
                    _('hook once push is all done'))
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    67
    return self._call('push_experiment_notifypushend_0')
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    68
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    69
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    70
def srv_notifypushend(repo, proto):
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    71
    """wire protocol command to notify a push is done"""
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    72
    proto.redirect()
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    73
    repo.hook('notifypushend')
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    74
    return wireproto.pushres(0)
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    75
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    76
729
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    77
def augmented_push(orig, repo, remote, *args, **kwargs):
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    78
    """push wrapped that call the wire protocol command"""
732
05ec92d8150d pushexperiment: guard against non-push-capable remotes
Julien Cristau <julien.cristau@logilab.fr>
parents: 731
diff changeset
    79
    if not remote.canpush():
1549
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
    80
        raise error.Abort(_("destination does not support push"))
1217
196c650d5ba9 pushexperiment: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 732
diff changeset
    81
    if (obsolete.isenabled(repo, obsolete.exchangeopt) and repo.obsstore
729
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    82
        and remote.capable('_push_experiment_pushobsmarkers_0')):
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    83
        # push marker early to limit damage of pushing too early.
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    84
        try:
1465
777e5c369d99 compat: use svfs instead of sopener
Pierre-Yves David <pierre-yves.david@fb.com>
parents: 1217
diff changeset
    85
            obsfp = repo.svfs('obsstore')
729
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    86
        except IOError as e:
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    87
            if e.errno != errno.ENOENT:
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    88
                raise
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    89
        else:
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
    90
            remote.push_experiment_pushobsmarkers_0(obsfp)
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    91
    ret = orig(repo, remote, *args, **kwargs)
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    92
    if remote.capable('_push_experiment_notifypushend_0'):
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    93
        remote.push_experiment_notifypushend_0()
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    94
    return ret
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    95
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
    96
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    97
def capabilities(orig, repo, proto):
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    98
    """wrapper to advertise new capability"""
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
    99
    caps = orig(repo, proto)
1217
196c650d5ba9 pushexperiment: remove use of obsolete._enabled
Durham Goode <durham@fb.com>
parents: 732
diff changeset
   100
    if obsolete.isenabled(repo, obsolete.exchangeopt):
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   101
        caps += ' _push_experiment_pushobsmarkers_0'
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
   102
    caps += ' _push_experiment_notifypushend_0'
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   103
    return caps
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   104
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   105
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   106
def extsetup(ui):
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   107
    wireproto.wirepeer.push_experiment_pushobsmarkers_0 = client_pushobsmarkers
728
5d368ae3d5a0 add notification at the end of push
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 727
diff changeset
   108
    wireproto.wirepeer.push_experiment_notifypushend_0 = client_notifypushend
1549
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
   109
    wireproto.commands['push_experiment_pushobsmarkers_0'] = \
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
   110
        (srv_pushobsmarkers, '')
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
   111
    wireproto.commands['push_experiment_notifypushend_0'] = \
81a221db8a72 check-code: make pushexperiment.py comply with check-code
Laurent Charignon <lcharignon@fb.com>
parents: 1465
diff changeset
   112
        (srv_notifypushend, '')
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   113
    extensions.wrapfunction(wireproto, 'capabilities', capabilities)
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   114
    extensions.wrapfunction(obsolete, 'syncpush', syncpush)
729
2e46caeb2890 push obsolescence marker before anything else
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents: 728
diff changeset
   115
    extensions.wrapfunction(localrepo.localrepository, 'push', augmented_push)
727
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   116
cb907cf3b556 Add a new pushexperiment extension
Julien Cristau <julien.cristau@logilab.fr>
parents:
diff changeset
   117