Exemplo n.º 1
0
def urlencodenested(params):
    """like urlencode, but works with nested parameters.

    For example, if params is {'a': ['b', 'c'], 'd': {'e': 'f'}}, it will be
    flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to
    urlencode. Note: the encoding is consistent with PHP's http_build_query.
    """
    flatparams = util.sortdict()

    def process(prefix, obj):
        if isinstance(obj, bool):
            obj = {True: b'true', False: b'false'}[obj]  # Python -> PHP form
        lister = lambda l: [(b'%d' % k, v) for k, v in enumerate(l)]
        items = {list: lister, dict: lambda x: x.items()}.get(type(obj))
        if items is None:
            flatparams[prefix] = obj
        else:
            for k, v in items(obj):
                if prefix:
                    process(b'%s[%s]' % (prefix, k), v)
                else:
                    process(k, v)

    process(b'', params)
    return util.urlreq.urlencode(flatparams)
Exemplo n.º 2
0
    def __init__(self):
        self._names = util.sortdict()

        # we need current mercurial named objects (bookmarks, tags, and
        # branches) to be initialized somewhere, so that place is here
        bmknames = lambda repo: repo._bookmarks.keys()
        bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name))
        bmknodemap = lambda repo, name: repo.nodebookmarks(name)
        n = namespace("bookmarks", templatename="bookmark",
                      # i18n: column positioning for "hg log"
                      logfmt=_("bookmark:    %s\n"),
                      listnames=bmknames,
                      namemap=bmknamemap, nodemap=bmknodemap)
        self.addnamespace(n)

        tagnames = lambda repo: [t for t, n in repo.tagslist()]
        tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name))
        tagnodemap = lambda repo, name: repo.nodetags(name)
        n = namespace("tags", templatename="tag",
                      # i18n: column positioning for "hg log"
                      logfmt=_("tag:         %s\n"),
                      listnames=tagnames,
                      namemap=tagnamemap, nodemap=tagnodemap,
                      deprecated=set(['tip']))
        self.addnamespace(n)

        bnames = lambda repo: repo.branchmap().keys()
        bnamemap = lambda repo, name: tolist(repo.branchtip(name, True))
        bnodemap = lambda repo, node: [repo[node].branch()]
        n = namespace("branches", templatename="branch",
                      # i18n: column positioning for "hg log"
                      logfmt=_("branch:      %s\n"),
                      listnames=bnames,
                      namemap=bnamemap, nodemap=bnodemap)
        self.addnamespace(n)
Exemplo n.º 3
0
 def __init__(self, ui, repo=None):
     if repo:
         sections = util.sortdict(DEFAULT_SECTIONS)
         custom_sections = getcustomadmonitions(repo)
         if custom_sections:
             sections.update(custom_sections)
         self._sections = list(sections.iteritems())
     else:
         self._sections = list(DEFAULT_SECTIONS)
Exemplo n.º 4
0
    def __init__(self):
        self._names = util.sortdict()

        # we need current mercurial named objects (bookmarks, tags, and
        # branches) to be initialized somewhere, so that place is here
        bmknames = lambda repo: repo._bookmarks.keys()
        bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name))
        bmknodemap = lambda repo, name: repo.nodebookmarks(name)
        n = namespace(
            "bookmarks",
            templatename="bookmark",
            # i18n: column positioning for "hg log"
            logfmt=_("bookmark:    %s\n"),
            listnames=bmknames,
            namemap=bmknamemap,
            nodemap=bmknodemap)
        self.addnamespace(n)

        tagnames = lambda repo: [t for t, n in repo.tagslist()]
        tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name))
        tagnodemap = lambda repo, name: repo.nodetags(name)
        n = namespace(
            "tags",
            templatename="tag",
            # i18n: column positioning for "hg log"
            logfmt=_("tag:         %s\n"),
            listnames=tagnames,
            namemap=tagnamemap,
            nodemap=tagnodemap,
            deprecated=set(['tip']))
        self.addnamespace(n)

        bnames = lambda repo: repo.branchmap().keys()
        bnamemap = lambda repo, name: tolist(repo.branchtip(name, True))
        bnodemap = lambda repo, node: [repo[node].branch()]
        n = namespace(
            "branches",
            templatename="branch",
            # i18n: column positioning for "hg log"
            logfmt=_("branch:      %s\n"),
            listnames=bnames,
            namemap=bnamemap,
            nodemap=bnodemap)
        self.addnamespace(n)
Exemplo n.º 5
0
def urlencodenested(params):
    """like urlencode, but works with nested parameters.

    For example, if params is {'a': ['b', 'c'], 'd': {'e': 'f'}}, it will be
    flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to
    urlencode. Note: the encoding is consistent with PHP's http_build_query.
    """
    flatparams = util.sortdict()
    def process(prefix, obj):
        items = {list: enumerate, dict: lambda x: x.items()}.get(type(obj))
        if items is None:
            flatparams[prefix] = obj
        else:
            for k, v in items(obj):
                if prefix:
                    process(b'%s[%s]' % (prefix, k), v)
                else:
                    process(k, v)
    process(b'', params)
    return util.urlreq.urlencode(flatparams)
Exemplo n.º 6
0
    def __init__(self):
        self._names = util.sortdict()
        columns = templatekw.getlogcolumns()
        #
        # # we need current mercurial named objects (bookmarks, tags, and
        # # branches) to be initialized somewhere, so that place is here
        # bmknames = lambda repo: repo._bookmarks.keys()
        # bmknamemap = lambda repo, name: tolist(repo._bookmarks.get(name))
        # bmknodemap = lambda repo, node: repo.nodebookmarks(node)
        # n = namespace("bookmarks", templatename="bookmark",
        #               logfmt=columns['bookmark'],
        #               listnames=bmknames,
        #               namemap=bmknamemap, nodemap=bmknodemap,
        #               builtin=True)
        # self.addnamespace(n)
        #
        tagnames = lambda repo: [t for t, n in repo.tagslist()]
        tagnamemap = lambda repo, name: tolist(repo._tagscache.tags.get(name))
        tagnodemap = lambda repo, node: repo.nodetags(node)
        n = namespace("tags",
                      templatename="tag",
                      logfmt=columns['tag'],
                      listnames=tagnames,
                      namemap=tagnamemap,
                      nodemap=tagnodemap,
                      deprecated={'tip'},
                      builtin=True)
        self.addnamespace(n)

        bnames = lambda repo: repo.branchmap().keys()
        bnamemap = lambda repo, name: tolist(repo.branchtip(name, True))
        bnodemap = lambda repo, node: [repo[node].branch()]
        n = namespace("branches",
                      templatename="branch",
                      logfmt=columns['branch'],
                      listnames=bnames,
                      namemap=bnamemap,
                      nodemap=bnodemap,
                      builtin=True)
        self.addnamespace(n)
Exemplo n.º 7
0
def urlencodenested(params):
    """like urlencode, but works with nested parameters.

    For example, if params is {'a': ['b', 'c'], 'd': {'e': 'f'}}, it will be
    flattened to {'a[0]': 'b', 'a[1]': 'c', 'd[e]': 'f'} and then passed to
    urlencode. Note: the encoding is consistent with PHP's http_build_query.
    """
    flatparams = util.sortdict()

    def process(prefix, obj):
        items = {list: enumerate, dict: lambda x: x.items()}.get(type(obj))
        if items is None:
            flatparams[prefix] = obj
        else:
            for k, v in items(obj):
                if prefix:
                    process('%s[%s]' % (prefix, k), v)
                else:
                    process(k, v)

    process('', params)
    return util.urlreq.urlencode(flatparams)
Exemplo n.º 8
0
def getconfigs(repo):
    # bypass "repoui.copy = baseui.copy # prevent copying repo configuration"
    ui = repo.ui.__class__.copy(repo.ui)

    # also read from wvfs/.hgdirsync
    filename = '.hgdirsync'
    content = repo.wvfs.tryread(filename)
    if content:
        ui._tcfg.parse(filename, '[dirsync]\n%s' % content, ['dirsync'])

    maps = util.sortdict()
    for key, value in ui.configitems('dirsync'):
        if '.' not in key:
            continue
        name, disambig = key.split('.', 1)
        # Normalize paths to have / at the end. For easy concatenation later.
        if value[-1] != '/':
            value = value + '/'
        if name not in maps:
            maps[name] = []
        maps[name].append(value)
    return maps
Exemplo n.º 9
0
                    mapping[old.node()] = [newnode]
                    # Update diff property
                    writediffproperties(unfi[newnode], diffmap[old.node()])
                # Remove local tags since it's no longer necessary
                tagname = b'D%d' % drevid
                if tagname in repo.tags():
                    tags.tag(repo, tagname, nullid, message=None, user=None,
                             date=None, local=True)
            scmutil.cleanupnodes(repo, mapping, b'phabsend')
            if wnode in mapping:
                unfi.setparents(mapping[wnode][0])

# Map from "hg:meta" keys to header understood by "hg import". The order is
# consistent with "hg export" output.
_metanamemap = util.sortdict([(r'user', b'User'), (r'date', b'Date'),
                              (r'node', b'Node ID'), (r'parent', b'Parent ')])

def _confirmbeforesend(repo, revs, oldmap):
    url, token = readurltoken(repo)
    ui = repo.ui
    for rev in revs:
        ctx = repo[rev]
        desc = ctx.description().splitlines()[0]
        oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None))
        if drevid:
            drevdesc = ui.label(b'D%s' % drevid, b'phabricator.drev')
        else:
            drevdesc = ui.label(_(b'NEW'), b'phabricator.drev')

        ui.write(_(b'%s - %s: %s\n')
                 % (drevdesc,
Exemplo n.º 10
0
def _deduplicate(pointers):
    """Remove any duplicate oids that exist in the list"""
    reduced = util.sortdict()
    for p in pointers:
        reduced[p.oid()] = p
    return reduced.values()
Exemplo n.º 11
0
 def pointer(v):
     # In the file spec, version is first and the other keys are sorted.
     sortkeyfunc = lambda x: (x[0] != 'version', x)
     items = sorted(pointers[v].iteritems(), key=sortkeyfunc)
     return util.sortdict(items)
Exemplo n.º 12
0
                    mapping[old.node()] = [newnode]
                    # Update diff property
                    writediffproperties(unfi[newnode], diffmap[old.node()])
                # Remove local tags since it's no longer necessary
                tagname = b'D%d' % drevid
                if tagname in repo.tags():
                    tags.tag(repo, tagname, nullid, message=None, user=None,
                             date=None, local=True)
            scmutil.cleanupnodes(repo, mapping, b'phabsend', fixphase=True)
            if wnode in mapping:
                unfi.setparents(mapping[wnode][0])

# Map from "hg:meta" keys to header understood by "hg import". The order is
# consistent with "hg export" output.
_metanamemap = util.sortdict([(r'user', b'User'), (r'date', b'Date'),
                              (r'node', b'Node ID'), (r'parent', b'Parent ')])

def _confirmbeforesend(repo, revs, oldmap):
    url, token = readurltoken(repo)
    ui = repo.ui
    for rev in revs:
        ctx = repo[rev]
        desc = ctx.description().splitlines()[0]
        oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None))
        if drevid:
            drevdesc = ui.label(b'D%s' % drevid, b'phabricator.drev')
        else:
            drevdesc = ui.label(_(b'NEW'), b'phabricator.drev')

        ui.write(_(b'%s - %s: %s\n')
                 % (drevdesc,
Exemplo n.º 13
0
                    tags.tag(repo,
                             tagname,
                             nullid,
                             message=None,
                             user=None,
                             date=None,
                             local=True)
            scmutil.cleanupnodes(repo, mapping, b'phabsend', fixphase=True)
            if wnode in mapping:
                unfi.setparents(mapping[wnode][0])


# Map from "hg:meta" keys to header understood by "hg import". The order is
# consistent with "hg export" output.
_metanamemap = util.sortdict([(b'user', b'User'), (b'date', b'Date'),
                              (b'branch', b'Branch'), (b'node', b'Node ID'),
                              (b'parent', b'Parent ')])


def _confirmbeforesend(repo, revs, oldmap):
    url, token = readurltoken(repo.ui)
    ui = repo.ui
    for rev in revs:
        ctx = repo[rev]
        desc = ctx.description().splitlines()[0]
        oldnode, olddiff, drevid = oldmap.get(ctx.node(), (None, None, None))
        if drevid:
            drevdesc = ui.label(b'D%s' % drevid, b'phabricator.drev')
        else:
            drevdesc = ui.label(_(b'NEW'), b'phabricator.drev')