示例#1
0
def tagslist(repo, beg_rev, end_rev):
    tags = repo.tagslist()
    i = 0
    while context.changectx(repo, tags[i][1]).rev() < beg_rev:
        i += 1
    j = len(tags) - 1
    while context.changectx(repo, tags[j][1]).rev() > end_rev:
        j -= 1
    return tags[i:j + 1]
示例#2
0
文件: jcheck.py 项目: edvbld/jcheck
def repo_bugids(ui, repo):
    def addbugids(bugids, ctx):
        lns = ctx.description().splitlines()
        for ln in lns:
            m = bug_check.match(ln)
            if m:
                b = int(m.group(1))
                if not b in bugids:
                    bugids[b] = ctx.rev()

    # Should cache this, eventually
    bugids = { }                        # bugid -> rev
    opts = { 'rev' : ['0:tip'] }
    ui.debug("Gathering bugids ...\n")
    try:
        nop = lambda c, fns: None
        iter = cmdutil.walkchangerevs(repo, _matchall(repo), opts, nop)
        for ctx in iter:
            addbugids(bugids, ctx)
    except (AttributeError, TypeError):
        # AttributeError:  matchall does not exist in hg < 1.1
        # TypeError:  walkchangerevs args differ in hg <= 1.3.1
        get = util.cachefunc(lambda r: repo.changectx(r).changeset())
        changeiter, matchfn = cmdutil.walkchangerevs(ui, repo, [], get, opts)
        for st, rev, fns in changeiter:
            if st == 'add':
                node = repo.changelog.node(rev)
                addbugids(bugids, context.changectx(repo, node))
    return bugids
示例#3
0
    def get_file_metas(self, source_files):
        
        from mercurial import ui, hg
        from mercurial.context import changectx, filectx
        self.repo = hg.repository(ui.ui(), self.rootpath)
        
        files = []
        
        cctx = changectx(self.repo)
        for afile in source_files:
            idx = 0
            fdict = self._init_ctx(afile)
            authors = []
            fctx = filectx(self.repo, afile.replace(self.rootpath,''), changectx=cctx)
            idx = 0
            
            for id in fctx.filelog():
                fctx_parent = fctx.filectx(id)
                if idx == 0:
                    fdict.update(self._secs_to_str(fctx_parent.date()[0]))
                authors.append(fctx_parent.user())
                idx += 1

            fdict['author']  = ', '.join([u for u in set(authors) if u != self.method])
            files.append(fdict)
            
        return files
示例#4
0
def newbinsize(ui, repo, node=None, **kwargs):
    '''forbid to add binary files over a given size'''
    forbid = False
    # default limit is 10 MB
    limit = int(ui.config('limits', 'maxnewbinsize', 10000000))
    ctx = repo[node]
    for rev in xrange(ctx.rev(), len(repo)):
        ctx = context.changectx(repo, rev)

        # do not check the size of files that have been removed
        # files that have been removed do not have filecontexts
        # to test for whether a file was removed, test for the existence of a filecontext
        filecontexts = list(ctx)

        def file_was_removed(f):
            """Returns True if the file was removed"""
            if f not in filecontexts:
                return True
            else:
                return False

        for f in itertools.ifilterfalse(file_was_removed, ctx.files()):
            fctx = ctx.filectx(f)
            filecontent = fctx.data()
            # check only for new files
            if not fctx.parents():
                if len(filecontent) > limit and util.binary(filecontent):
                    msg = 'new binary file %s of %s is too large: %ld > %ld\n'
                    hname = dpynode.short(ctx.node())
                    ui.write(_(msg) % (f, hname, len(filecontent), limit))
                    forbid = True
    return forbid
示例#5
0
 def get_rev_msg(self, revision_hash, template=TEMPLATE):
     self.displayer = show_changeset(self.ui, self.repo, {'template': template}, False)
     self.ui.pushbuffer()
     rev = self.repo.lookup(revision_hash)
     ctx = context.changectx(self.repo, rev)
     self.displayer.show(ctx)
     msg = self.ui.popbuffer()
     return msg
示例#6
0
 def check(self, rev, node):
     self.summarized = False
     self.cs_bugids = []
     self.cs_author = None
     self.cs_reviewers = []
     self.cs_contributor = None
     try:
         ctx = context.changectx(self.repo, node)
     except TypeError:
         ctx = context.changectx(self.repo, rev, node)
     self.ui.note(oneline(ctx))
     if hex(node) in changeset_whitelist:
         self.ui.note("%s in whitelist; skipping\n" % hex(node))
         return Pass
     for c in self.checks:
         cf = checker.__dict__[c]
         cf(self, ctx)
     return self.rv
示例#7
0
文件: jcheck.py 项目: edvbld/jcheck
 def check(self, rev, node):
     self.summarized = False
     self.cs_bugids = [ ]
     self.cs_author = None
     self.cs_reviewers = [ ]
     self.cs_contributor = None
     if len(inspect.getargspec(context.changectx.__init__).args) == 4:
         ctx = context.changectx(self.repo, rev, node)
     else:
         ctx = context.changectx(self.repo, node)
     self.ui.note(oneline(ctx))
     if hex(node) in changeset_whitelist:
         self.ui.note("%s in whitelist; skipping\n" % hex(node))
         return Pass
     for c in self.checks:
         cf = checker.__dict__[c]
         cf(self, ctx)
     return self.rv
示例#8
0
文件: hgfilesize.py 项目: AMDmi3/gem5
def limit_file_size(ui, repo, node=None, **kwargs):
    '''forbid files over a given size'''

    # default limit is 1 MB
    limit = int(ui.config('limit_file_size', 'maximum_file_size', 1024*1024))
    existing_tip = context.changectx(repo, node).rev()
    new_tip = context.changectx(repo, 'tip').rev()
    for rev in xrange(existing_tip, new_tip + 1):
        ctx = context.changectx(repo, rev)
        for f in ctx.files():
            if f not in ctx:
                continue
            fctx = ctx.filectx(f)
            if fctx.size() > limit:
                ui.write(_('file %s of %s is too large: %d > %d\n') % \
                             (f, ctx, fctx.size(), limit))
                return True # This is invalid

    return False # Things are OK.
示例#9
0
def limit_file_size(ui, repo, node=None, **kwargs):
    '''forbid files over a given size'''

    # default limit is 1 MB
    limit = int(ui.config('limit_file_size', 'maximum_file_size', 1024 * 1024))
    existing_tip = context.changectx(repo, node).rev()
    new_tip = context.changectx(repo, 'tip').rev()
    for rev in xrange(existing_tip, new_tip + 1):
        ctx = context.changectx(repo, rev)
        for f in ctx.files():
            if f not in ctx:
                continue
            fctx = ctx.filectx(f)
            if fctx.size() > limit:
                ui.write(_('file %s of %s is too large: %d > %d\n') % \
                             (f, ctx, fctx.size(), limit))
                return True  # This is invalid

    return False  # Things are OK.
示例#10
0
文件: core.py 项目: code2u/jsb
def handle_version(bot, ievent):
    """ no arguments - show bot's version. """
    from jsb.version import getversion
    version = getversion(bot.type.upper())
    try: 
        from mercurial import context, hg, node, repo, ui
        repository = hg.repository(ui.ui(), '.')
        ctx = context.changectx(repository)
        tip = str(ctx.rev())
    except: tip = None
    if tip: version2 = version + " HG " + tip
    else: version2 = version
    ievent.reply(version2)
示例#11
0
文件: version.py 项目: buzzworkers/tl
def getfullversion(txt="", repo=False):
    v = str(version)
    from tl.lib.config import getmainconfig
    cfg = getmainconfig()
    if cfg.dbenable: v += " -=- " + cfg.dbtype.upper()
    tip = None
    if repo:
        try:
            from mercurial import context, hg, node, repo, ui
            repository = hg.repository(ui.ui(), '.')
            ctx = context.changectx(repository)
            tip = str(ctx.rev())
        except: tip = None
    if tip: version2 = v + " -=- HG " + tip
    else: version2 = v
    return "T I M E L I N E -=- %s -=- %s" % (txt, version2)
示例#12
0
文件: core.py 项目: Petraea/jsonbot
def handle_version(bot, ievent):
    """ no arguments - show bot's version. """
    from jsb.version import getversion
    version = getversion(bot.type.upper())
    cfg = getmainconfig()
    if cfg.dbenable: version += " " + cfg.dbtype.upper()
    if ievent.rest and ievent.rest == "repo":
        try:
            from mercurial import context, hg, node, repo, ui
            repository = hg.repository(ui.ui(), '.')
            ctx = context.changectx(repository)
            tip = str(ctx.rev())
        except:
            tip = None
        if tip: version2 = version + " HG " + tip
    else: version2 = version
    ievent.reply(version2)
示例#13
0
 def _remotebranches(self):
     remotebranches = {}
     bfile = self.join("remotebranches")
     if os.path.exists(bfile):
         f = open(bfile)
         for line in f:
             line = line.strip()
             if line:
                 hash, name = line.split(" ", 1)
                 # look up the hash in the changelog directly
                 # to avoid infinite recursion if the hash is bogus
                 n = self.changelog._match(hash)
                 if n:
                     # we need rev since node will recurse lookup
                     ctx = context.changectx(self, self.changelog.rev(n))
                     if not ctx.extra().get("close"):
                         remotebranches[name] = n
     return remotebranches
示例#14
0
 def _remotebranches(self):
     remotebranches = {}
     bfile = self.join('remotebranches')
     if os.path.exists(bfile):
         f = open(bfile)
         for line in f:
             line = line.strip()
             if line:
                 hash, name = line.split(' ', 1)
                 # look up the hash in the changelog directly
                 # to avoid infinite recursion if the hash is bogus
                 n = self.changelog._match(hash)
                 if n:
                     # we need rev since node will recurse lookup
                     ctx = context.changectx(self,
                                             self.changelog.rev(n))
                     if not ctx.extra().get('close'):
                         remotebranches[name] = n
     return remotebranches
示例#15
0
 def _remotebranches(self):
     remotebranches = {}
     try:
         bfile = self.vfs.join('remotebranches')
     except AttributeError:
         # old hg
         bfile = self.join('remotebranches')
     if os.path.exists(bfile):
         f = open(bfile)
         for line in f:
             line = line.strip()
             if line:
                 hash, name = line.split(' ', 1)
                 # look up the hash in the changelog directly
                 # to avoid infinite recursion if the hash is bogus
                 n = self.changelog._match(hash)
                 if n:
                     # we need rev since node will recurse lookup
                     ctx = context.changectx(self,
                                             self.changelog.rev(n))
                     if not ctx.extra().get('close'):
                         remotebranches[name] = n
     return remotebranches
示例#16
0
def describe(ui, repo, **opts):
    """show most recent tag

    Finds the most recent tag reachable from the current revision.
     
    If the current revision has been tagged, only the tag is
    printed:
     
      v1.2.3
     
    Otherwise the long form is printed which includes the tag, the
    number of commits after the tag, and the node of the current
    changeset:

      v1.2.3-8-2789c05b6c3b
     
    If the closest, tagged revision has multiple tags, each is
    printed on a separate line unless the --single-tag option is
    used, in which case an error is raised.

    If multiple revisions are equally reachable from the root and
    one is on the current branch, it is chosen.  Otherwise each tag
    from each revision is printed on a separate line unless the
    --single-rev option is used, in which case an error is raised.

    If the --prefer-branch option is used, the closest tag on the
    current branch will override closer tags that are reachable but
    not on the same branch.  In the example below, tag A is
    normally chosen since it is closer to the root than B (3
    commits vs 4 commits).  However, if --prefer-branch is used, B
    will be chosen because it is on the the same branch.

            o-A-o
           /     \\
        o-o-B-o-o-o-o <-- root

    The --require-branch option requires the tag to be on the same
    branch.  This is similar to the --prefer-branch option but raises an
    error if no tags are found on the current branch.
    """
    if not repo.local():
        raise util.Abort(_("must be a local repository"))

    if opts['rev']:
        ctx = context.changectx(repo, opts['rev'])
    else:
        ctx = context.workingctx(repo).parents()[0]

    tags, count = _find_closest_tag(ui, repo, ctx, opts)

    uselong = opts['long'] or (count != 0 and not opts['short'])

    if uselong:
        hexfunc = (opts['full'] or ui.debugflag) and hex or short
        node = hexfunc(ctx.node())
        sep = opts['spaces'] and ' ' or '-'
        count = str(count)

        for tag in tags:
            ui.write("%s\n" % sep.join([tag, count, node]))

    else:
        for tag in tags:
            ui.write("%s\n" % tag)
示例#17
0
def _verlist(repo, revspec):
    beg, end = splitrevspec(revspec)
    beg = beg and context.changectx(repo, beg).rev() or 0
    end = context.changectx(repo, end or 'tip').rev()
    return tagslist(repo, beg, end)
示例#18
0
文件: jcheck.py 项目: edvbld/jcheck
 def repoitem(self, arg):
     return context.changectx(self, arg)
示例#19
0
 def getctx(r):
     if r not in ccache:
         ccache[r] = context.changectx(repo, r)
     return ccache[r]
示例#20
0
    def diff_generator(self, node1, node2):
        repo = self.repo

        ccache = {}
        def getctx(r):
            if r not in ccache:
                ccache[r] = context.changectx(repo, r)
            return ccache[r]

        flcache = {}
        def getfilectx(f, ctx):
            flctx = ctx.filectx(f, filelog=flcache.get(f))
            if f not in flcache:
                flcache[f] = flctx._filelog
            return flctx

        ctx1 = context.changectx(repo, node1) # parent
        ctx2 = context.changectx(repo, node2) # current

        if node1 == repo.changelog.parents(node2)[0]:
            filelist = ctx2.files()
        else:
            changes = repo.status(node1, node2, None)[:5]
            modified, added, removed, deleted, unknown = changes
            filelist = modified + added + removed


        # force manifest reading
        man1 = ctx1.manifest()
        date1 = util.datestr(ctx1.date())

        execf2 = ctx2.manifest().execf
        linkf2 = ctx2.manifest().linkf

        # returns False if there was no rename between ctx1 and ctx2
        # returns None if the file was created between ctx1 and ctx2
        # returns the (file, node) present in ctx1 that was renamed to f in ctx2
        # This will only really work if c1 is the Nth 1st parent of c2.
        def renamed(c1, c2, man, f):
            startrev = c1.rev()
            c = c2
            crev = c.rev()
            if crev is None:
                crev = repo.changelog.count()
            orig = f
            files = (f,)
            while crev > startrev:
                if f in files:
                    try:
                        src = getfilectx(f, c).renamed()
                    except revlog.LookupError:
                        return None
                    if src:
                        f = src[0]
                crev = c.parents()[0].rev()
                # try to reuse
                c = getctx(crev)
                files = c.files()
            if f not in man:
                return None
            if f == orig:
                return False
            return f

        status = {}
        def filestatus(f):
            if f in status:
                return status[f]
            try:
                # Determine file status by presence in manifests
                s = 'R'
                ctx2.filectx(f)
                s = 'A'
                ctx1.filectx(f)
                s = 'M'
            except revlog.LookupError:
                pass
            status[f] = s
            return s

        copied = {}
        for f in filelist:
            src = renamed(ctx1, ctx2, man1, f)
            if src:
                copied[f] = src

        srcs = [x[1] for x in copied.iteritems() if filestatus(x[0]) == 'A']

        gone = {}
        for f in filelist:
            s = filestatus(f)
            to = None
            tn = None
            dodiff = True
            header = []
            if f in man1:
                to = getfilectx(f, ctx1).data()
            if s != 'R':
                tn = getfilectx(f, ctx2).data()
            a, b = f, f
            def gitmode(x, l):
                return l and '120000' or (x and '100755' or '100644')
            def addmodehdr(header, omode, nmode):
                if omode != nmode:
                    header.append('old mode %s\n' % omode)
                    header.append('new mode %s\n' % nmode)

            if s == 'A':
                mode = gitmode(execf2(f), linkf2(f))
                if f in copied:
                    a = copied[f]
                    omode = gitmode(man1.execf(a), man1.linkf(a))
                    addmodehdr(header, omode, mode)
                    if filestatus(a) == 'R' and a not in gone:
                        op = 'rename'
                        gone[a] = 1
                    else:
                        op = 'copy'
                    header.append('%s from %s\n' % (op, a))
                    header.append('%s to %s\n' % (op, f))
                    to = getfilectx(a, ctx1).data()
                else:
                    header.append('new file mode %s\n' % mode)
                if util.binary(tn):
                    dodiff = 'binary'
            elif s == 'R':
                if f in srcs:
                    dodiff = False
                else:
                    mode = gitmode(man1.execf(f), man1.linkf(f))
                    header.append('deleted file mode %s\n' % mode)
            else:
                omode = gitmode(man1.execf(f), man1.linkf(f))
                nmode = gitmode(execf2(f), linkf2(f))
                addmodehdr(header, omode, nmode)
                if util.binary(to) or util.binary(tn):
                    dodiff = 'binary'
            header.insert(0, 'diff --git a/%s b/%s\n' % (a, b))
            if dodiff == 'binary':
                text = 'binary file has changed.\n'
            elif dodiff:
                try:
                    text = patch.mdiff.unidiff(to, date1,
                                    tn, util.datestr(ctx2.date()),
                                    fn1=a, fn2=b, r=None,
                                    opts=patch.mdiff.defaultopts)
                except TypeError:
                    # hg-0.9.5 and before
                    text = patch.mdiff.unidiff(to, date1,
                                    tn, util.datestr(ctx2.date()),
                                    f, None, opts=patch.mdiff.defaultopts)
            else:
                text = ''
            if header or text: yield (s, f, ''.join(header) + text)