Ejemplo n.º 1
0
def countrate(ui, repo, amap, *pats, **opts):
    """Calculate stats"""
    opts = pycompat.byteskwargs(opts)
    if opts.get(b'dateformat'):

        def getkey(ctx):
            t, tz = ctx.date()
            date = datetime.datetime(*time.gmtime(float(t) - tz)[:6])
            return encoding.strtolocal(
                date.strftime(encoding.strfromlocal(opts[b'dateformat']))
            )

    else:
        tmpl = opts.get(b'oldtemplate') or opts.get(b'template')
        tmpl = logcmdutil.maketemplater(ui, repo, tmpl)

        def getkey(ctx):
            ui.pushbuffer()
            tmpl.show(ctx)
            return ui.popbuffer()

    progress = ui.makeprogress(
        _(b'analyzing'), unit=_(b'revisions'), total=len(repo)
    )
    rate = {}
    df = False
    if opts.get(b'date'):
        df = dateutil.matchdate(opts[b'date'])

    m = scmutil.match(repo[None], pats, opts)

    def prep(ctx, fns):
        rev = ctx.rev()
        if df and not df(ctx.date()[0]):  # doesn't match date format
            return

        key = getkey(ctx).strip()
        key = amap.get(key, key)  # alias remap
        if opts.get(b'changesets'):
            rate[key] = (rate.get(key, (0,))[0] + 1, 0)
        else:
            parents = ctx.parents()
            if len(parents) > 1:
                ui.note(_(b'revision %d is a merge, ignoring...\n') % (rev,))
                return

            ctx1 = parents[0]
            lines = changedlines(ui, repo, ctx1, ctx, fns)
            rate[key] = [r + l for r, l in zip(rate.get(key, (0, 0)), lines)]

        progress.increment()

    for ctx in cmdutil.walkchangerevs(repo, m, opts, prep):
        continue

    progress.complete()

    return rate
Ejemplo n.º 2
0
def revset_pushdate(repo, subset, x):
    """``pushdate(interval)``

    Changesets that were pushed within the interval. See :hg:`help dates`.
    """
    l = revset.getargs(x, 1, 1, 'pushdate requires one argument')

    ds = revset.getstring(l[0], 'pushdate requires a string argument')
    dm = dateutil.matchdate(ds)

    def getrevs():
        to_rev = repo.changelog.rev
        for push in repo.pushlog.pushes():
            if dm(push.when):
                for node in push.nodes:
                    yield to_rev(bin(node))

    return subset & revset.generatorset(getrevs())
Ejemplo n.º 3
0
def ilist(ui, repo, **opts):
    """List issues associated with the project"""

    # Process options
    show_all = opts['all']
    properties = []
    match_date, date_match = False, lambda x: True
    if opts['date']:
        match_date, date_match = True, matchdate(opts['date'])
    order = 'new'
    if opts['order']:
        order = opts['order']

    # Formats
    formats = _read_formats(ui)

    # Find issues
    issues_dir = ui.config('artemis', 'issues', default=default_issues_dir)
    issues_path = os.path.join(repo.root, issues_dir)
    if not os.path.exists(issues_path): return

    issues = glob.glob(os.path.join(issues_path, '*'))

    _create_all_missing_dirs(issues_path, issues)

    # Process filter
    if opts['filter']:
        filters = glob.glob(os.path.join(issues_path, filter_prefix + '*'))
        config = ConfigParser.SafeConfigParser()
        config.read(filters)
        if not config.has_section(opts['filter']):
            ui.write('No filter %s defined\n' % opts['filter'])
        else:
            properties += config.items(opts['filter'])

    cmd_properties = _get_properties(opts['property'])
    list_properties = [p[0] for p in cmd_properties if len(p) == 1]
    list_properties_dict = {}
    properties += filter(lambda p: len(p) > 1, cmd_properties)

    summaries = []
    for issue in issues:
        mbox = mailbox.Maildir(issue, factory=mailbox.MaildirMessage)
        root = _find_root_key(mbox)
        if not root: continue
        property_match = True
        for property, value in properties:
            if value:
                property_match = property_match and (mbox[root][property]
                                                     == value)
            else:
                property_match = property_match and (property
                                                     not in mbox[root])

        if not show_all and (not properties or not property_match) and (
                properties or mbox[root]['State'].upper()
                in [f.upper() for f in state['resolved']]):
            continue
        if match_date and not date_match(parsedate(mbox[root]['date'])[0]):
            continue

        if not list_properties:
            summaries.append((
                _summary_line(mbox, root, issue[len(issues_path) + 1:],
                              formats),  # +1 for trailing /
                _find_mbox_date(mbox, root, order)))
        else:
            for lp in list_properties:
                if lp in mbox[root]:
                    list_properties_dict.setdefault(lp,
                                                    set()).add(mbox[root][lp])

    if not list_properties:
        summaries.sort(lambda (s1, d1), (s2, d2): cmp(d2, d1))
        for s, d in summaries:
            ui.write(s + '\n')
    else:
        for lp in list_properties_dict.keys():
            ui.write("%s:\n" % lp)
            for value in sorted(list_properties_dict[lp]):
                ui.write("  %s\n" % value)