Ejemplo n.º 1
0
    def write(path):
        fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
                         pathname=os.path.join(prefix, path))
        data = ctx[path].data()
        if not opts.get('text') and util.binary(data):
            fp.write("%s: binary file\n" % path)
            return

        for (num, line) in enumerate(data.split("\n"), start=1):
            line = line + "\n"
            fp.write("%s:%s: %s" % (path, num, line))
        fp.close()
Ejemplo n.º 2
0
def overridecat(orig, ui, repo, file1, *pats, **opts):
    ctx = scmutil.revsingle(repo, opts.get('rev'))
    err = 1
    notbad = set()
    m = scmutil.match(ctx, (file1, ) + pats, opts)
    origmatchfn = m.matchfn

    def lfmatchfn(f):
        if origmatchfn(f):
            return True
        lf = lfutil.splitstandin(f)
        if lf is None:
            return False
        notbad.add(lf)
        return origmatchfn(lf)

    m.matchfn = lfmatchfn
    origbadfn = m.bad

    def lfbadfn(f, msg):
        if not f in notbad:
            origbadfn(f, msg)

    m.bad = lfbadfn
    for f in ctx.walk(m):
        fp = cmdutil.makefileobj(repo,
                                 opts.get('output'),
                                 ctx.node(),
                                 pathname=f)
        lf = lfutil.splitstandin(f)
        if lf is None or origmatchfn(f):
            # duplicating unreachable code from commands.cat
            data = ctx[f].data()
            if opts.get('decode'):
                data = repo.wwritedata(f, data)
            fp.write(data)
        else:
            hash = lfutil.readstandin(repo, lf, ctx.rev())
            if not lfutil.inusercache(repo.ui, hash):
                store = basestore._openstore(repo)
                success, missing = store.get([(lf, hash)])
                if len(success) != 1:
                    raise util.Abort(
                        _('largefile %s is not in cache and could not be '
                          'downloaded') % lf)
            path = lfutil.usercachepath(repo.ui, hash)
            fpin = open(path, "rb")
            for chunk in util.filechunkiter(fpin, 128 * 1024):
                fp.write(chunk)
            fpin.close()
        fp.close()
        err = 0
    return err
Ejemplo n.º 3
0
def catlfile(repo, lfile, rev, filename):
    hash = lfutil.readstandin(repo, lfile, rev)
    if not lfutil.inusercache(repo.ui, hash):
        store = basestore._openstore(repo)
        success, missing = store.get([(lfile, hash)])
        if len(success) != 1:
            raise util.Abort(_("largefile %s is not in cache and could not be downloaded") % lfile)
    path = lfutil.usercachepath(repo.ui, hash)
    fpout = cmdutil.makefileobj(repo, filename)
    fpin = open(path, "rb")
    fpout.write(fpin.read())
    fpout.close()
    fpin.close()
    return 0
Ejemplo n.º 4
0
def catlfile(repo, lfile, rev, filename):
    hash = lfutil.readstandin(repo, lfile, rev)
    if not lfutil.inusercache(repo.ui, hash):
        store = basestore._openstore(repo)
        success, missing = store.get([(lfile, hash)])
        if len(success) != 1:
            raise util.Abort(
                _('largefile %s is not in cache and could not be downloaded')
                    % lfile)
    path = lfutil.usercachepath(repo.ui, hash)
    fpout = cmdutil.makefileobj(repo, filename)
    fpin = open(path, "rb")
    fpout.write(fpin.read())
    fpout.close()
    fpin.close()
    return 0
Ejemplo n.º 5
0
def overridecat(orig, ui, repo, file1, *pats, **opts):
    ctx = scmutil.revsingle(repo, opts.get('rev'))
    err = 1
    notbad = set()
    m = scmutil.match(ctx, (file1,) + pats, opts)
    origmatchfn = m.matchfn
    def lfmatchfn(f):
        if origmatchfn(f):
            return True
        lf = lfutil.splitstandin(f)
        if lf is None:
            return False
        notbad.add(lf)
        return origmatchfn(lf)
    m.matchfn = lfmatchfn
    origbadfn = m.bad
    def lfbadfn(f, msg):
        if not f in notbad:
            origbadfn(f, msg)
    m.bad = lfbadfn
    for f in ctx.walk(m):
        fp = cmdutil.makefileobj(repo, opts.get('output'), ctx.node(),
                                 pathname=f)
        lf = lfutil.splitstandin(f)
        if lf is None or origmatchfn(f):
            # duplicating unreachable code from commands.cat
            data = ctx[f].data()
            if opts.get('decode'):
                data = repo.wwritedata(f, data)
            fp.write(data)
        else:
            hash = lfutil.readstandin(repo, lf, ctx.rev())
            if not lfutil.inusercache(repo.ui, hash):
                store = basestore._openstore(repo)
                success, missing = store.get([(lf, hash)])
                if len(success) != 1:
                    raise util.Abort(
                        _('largefile %s is not in cache and could not be '
                          'downloaded')  % lf)
            path = lfutil.usercachepath(repo.ui, hash)
            fpin = open(path, "rb")
            for chunk in util.filechunkiter(fpin, 128 * 1024):
                fp.write(chunk)
            fpin.close()
        fp.close()
        err = 0
    return err