hgext/qsync.py
author Pierre-Yves David <pierre-yves.david@logilab.fr>
Tue, 20 Mar 2012 16:11:57 +0100
changeset 153 c088f503cc97
child 195 ccbadfae1d06
permissions -rw-r--r--
add qsync extension to mutable history
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
153
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     1
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     2
import re
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     3
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     4
from cStringIO import StringIO
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     5
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     6
from mercurial.i18n import _
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     7
from mercurial import commands
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     8
from mercurial import patch
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
     9
from mercurial import util
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    10
from mercurial.node import nullid, hex, short, bin
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    11
from mercurial import cmdutil
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    12
from mercurial import hg
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    13
from mercurial import scmutil
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    14
from mercurial import error
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    15
from mercurial import extensions
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    16
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    17
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    18
import re
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    19
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    20
import json
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    21
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    22
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    23
### old compat code
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    24
#############################
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    25
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    26
BRANCHNAME="qsubmit2"
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    27
OLDBRANCHNAME="pyves-qsubmit"
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    28
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    29
### new command
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    30
#############################
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    31
cmdtable = {}
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    32
command = cmdutil.command(cmdtable)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    33
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    34
@command('^qsync|sync',
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    35
    [
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    36
     ('a', 'review-all', False, _('mark all touched patches ready for review (no editor)')),
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    37
    ],
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    38
    '')
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    39
def cmdsync(ui, repo, **opts):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    40
    '''Export draft changeset as mq patch in a mq patches repository commit.
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    41
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    42
    This command get all changesets in draft phase and create an mq changeset:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    43
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    44
        * on a "qsubmit2" branch (based on the last changeset)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    45
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    46
        * one patch per draft changeset
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    47
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    48
        * a series files listing all generated patch
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    49
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    50
        * qsubmitdata holding useful information
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    51
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    52
    It does use obsolete relation to update patches that already existing in the qsubmit2 branch.
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    53
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    54
    Already existing patch which became public, draft or got killed are remove from the mq repo.
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    55
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    56
    Patch name are generated using the summary line for changeset description.
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    57
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    58
    .. warning:: Series files is ordered topologically. So two series with
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    59
                 interleaved changeset will appear interleaved.
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    60
    '''
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    61
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    62
    review = None
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    63
    review = 'edit'
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    64
    if opts['review_all']:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    65
        review = 'all'
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    66
    mqrepo = repo.mq.qrepo()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    67
    try:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    68
        parent = mqrepo[BRANCHNAME]
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    69
    except error.RepoLookupError:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    70
        try:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    71
            parent =  mqrepo[OLDBRANCHNAME]
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    72
        except error.RepoLookupError:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    73
            parent = initqsubmit(mqrepo)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    74
    store, data, touched = fillstore(repo, parent)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    75
    if not touched:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    76
        raise util.Abort('Nothing changed')
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    77
    files = ['qsubmitdata', 'series'] + touched
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    78
    # mark some as ready for review
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    79
    message = 'qsubmit commit\n\n'
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    80
    review_list = []
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    81
    if review:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    82
        for patch_name in touched:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    83
            try:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    84
                store.getfile(patch_name)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    85
                review_list.append(patch_name)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    86
            except IOError:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    87
                pass
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    88
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    89
    if review:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    90
        message += '\n'.join('* %s ready for review' % x for x in review_list)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    91
    memctx = patch.makememctx(mqrepo, (parent.node(), nullid),
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    92
                              message,
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    93
                              None,
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    94
                              None,
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    95
                              parent.branch(), files, store,
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    96
                              editor=None)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    97
    if review == 'edit':
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    98
        memctx._text = cmdutil.commitforceeditor(mqrepo, memctx, [])
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
    99
    mqrepo.savecommitmessage(memctx.description())
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   100
    n = memctx.commit()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   101
    return 0
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   102
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   103
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   104
def makename(ctx):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   105
    """create a patch name form a changeset"""
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   106
    descsummary = ctx.description().splitlines()[0]
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   107
    descsummary = re.sub(r'\s+', '_', descsummary)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   108
    descsummary = re.sub(r'\W+', '', descsummary)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   109
    if len(descsummary) > 45:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   110
        descsummary = descsummary[:42] + '.'
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   111
    return '%s-%s.diff' % (ctx.branch().upper(), descsummary)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   112
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   113
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   114
def get_old_data(mqctx):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   115
    """read qsubmit data to fetch previous export data
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   116
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   117
    get old data from the content of an mq commit"""
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   118
    try:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   119
        old_data = mqctx['qsubmitdata']
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   120
        return json.loads(old_data.data())
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   121
    except error.LookupError:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   122
        return []
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   123
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   124
def get_current_data(repo):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   125
    """Return what would be exported if not previous data exists"""
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   126
    data = []
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   127
    for ctx in repo.set('draft() - obsolete()'):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   128
        name = makename(ctx)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   129
        data.append([ctx.hex(), makename(ctx)])
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   130
    return data
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   131
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   132
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   133
def patchmq(repo, store, olddata, newdata):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   134
    """export the mq patches and return all useful data to be exported"""
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   135
    finaldata = []
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   136
    touched = set()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   137
    currentdrafts = set(d[0] for d in newdata)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   138
    usednew = set()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   139
    usedold = set()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   140
    obsolete = extensions.find('obsolete')
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   141
    for oldhex, oldname in olddata:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   142
        if oldhex in usedold:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   143
            continue # no duplicate
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   144
        usedold.add(oldhex)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   145
        oldname = str(oldname)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   146
        oldnode = bin(oldhex)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   147
        newnodes = obsolete.newerversion(repo, oldnode)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   148
        if newnodes:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   149
            newnodes = [n for n in newnodes if n] # remove killing
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   150
            if len(newnodes) > 1:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   151
                raise util.Abort('%s have more than one newer version: %s'% (oldname, newnodes))
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   152
            if newnodes:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   153
                # else, changeset have been killed
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   154
                newnode = list(newnodes)[0][0]
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   155
                ctx = repo[newnode]
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   156
                if ctx.hex() != oldhex and ctx.phase():
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   157
                    fp = StringIO()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   158
                    cmdutil.export(repo, [ctx.rev()], fp=fp)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   159
                    data = fp.getvalue()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   160
                    store.setfile(oldname, data, (None, None))
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   161
                    finaldata.append([ctx.hex(), oldname])
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   162
                    usednew.add(ctx.hex())
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   163
                    touched.add(oldname)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   164
                    continue
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   165
        if oldhex in currentdrafts:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   166
            # else changeset is now public or secret
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   167
            finaldata.append([oldhex, oldname])
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   168
            usednew.add(ctx.hex())
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   169
            continue
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   170
        touched.add(oldname)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   171
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   172
    for newhex, newname in newdata:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   173
        if newhex in usednew:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   174
            continue
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   175
        newnode = bin(newhex)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   176
        ctx = repo[newnode]
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   177
        fp = StringIO()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   178
        cmdutil.export(repo, [ctx.rev()], fp=fp)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   179
        data = fp.getvalue()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   180
        store.setfile(newname, data, (None, None))
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   181
        finaldata.append([ctx.hex(), newname])
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   182
        touched.add(newname)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   183
    # sort by branchrev number
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   184
    finaldata.sort(key=lambda x: sort_key(repo[x[0]]))
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   185
    # sort touched too (ease review list)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   186
    stouched = [f[1] for f in finaldata if f[1] in touched]
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   187
    return finaldata, stouched
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   188
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   189
def sort_key(ctx):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   190
    """ctx sort key: (branch, rev)"""
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   191
    return (ctx.branch(), ctx.rev())
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   192
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   193
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   194
def fillstore(repo, basemqctx):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   195
    """file store with patch data"""
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   196
    olddata = get_old_data(basemqctx)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   197
    newdata = get_current_data(repo)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   198
    store = patch.filestore()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   199
    try:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   200
        data, touched = patchmq(repo, store, olddata, newdata)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   201
        # put all name in the series
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   202
        series ='\n'.join(d[1] for d in data) + '\n'
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   203
        store.setfile('series', series, (False, False))
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   204
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   205
        # export data to ease futur work
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   206
        series ='\n'.join(d[1] for d in data) + '\n'
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   207
        store.setfile('qsubmitdata', json.dumps(data, indent=True),
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   208
                      (False, False))
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   209
    finally:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   210
        store.close()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   211
    return store, data, touched
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   212
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   213
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   214
def initqsubmit(mqrepo):
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   215
    """create initial qsubmit branch"""
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   216
    store = patch.filestore()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   217
    try:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   218
        files = set()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   219
        store.setfile('.hgignore', '^status$\n', (False, False))
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   220
        memctx = patch.makememctx(mqrepo, (nullid, nullid),
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   221
                              'qsubmit init',
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   222
                              None,
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   223
                              None,
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   224
                              BRANCHNAME, ('.hgignore',), store,
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   225
                              editor=None)
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   226
        mqrepo.savecommitmessage(memctx.description())
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   227
        n = memctx.commit()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   228
    finally:
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   229
        store.close()
c088f503cc97 add qsync extension to mutable history
Pierre-Yves David <pierre-yves.david@logilab.fr>
parents:
diff changeset
   230
    return mqrepo[n]