def comparison(web, req, tmpl): ctx = webutil.changectx(web.repo, req) if 'file' not in req.form: raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') path = webutil.cleanpath(web.repo, req.form['file'][0]) rename = path in ctx and webutil.renamelink(ctx[path]) or [] parsecontext = lambda v: v == 'full' and -1 or int(v) if 'context' in req.form: context = parsecontext(req.form['context'][0]) else: context = parsecontext(web.config('web', 'comparisoncontext', '5')) def filelines(f): if util.binary(f.data()): mt = mimetypes.guess_type(f.path())[0] if not mt: mt = 'application/octet-stream' return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] return f.data().splitlines() parent = ctx.p1() leftrev = parent.rev() leftnode = parent.node() rightrev = ctx.rev() rightnode = ctx.node() if path in ctx: fctx = ctx[path] rightlines = filelines(fctx) if path not in parent: leftlines = () else: pfctx = parent[path] leftlines = filelines(pfctx) else: rightlines = () fctx = ctx.parents()[0][path] leftlines = filelines(fctx) comparison = webutil.compare(tmpl, context, leftlines, rightlines) return tmpl('filecomparison', file=path, node=hex(ctx.node()), rev=ctx.rev(), date=ctx.date(), desc=ctx.description(), extra=ctx.extra(), author=ctx.user(), rename=rename, branch=webutil.nodebranchnodefault(ctx), parent=webutil.parents(fctx), child=webutil.children(fctx), leftrev=leftrev, leftnode=hex(leftnode), rightrev=rightrev, rightnode=hex(rightnode), comparison=comparison)
def comparison(web, req, tmpl): """ /comparison/{revision}/{path} ----------------------------- Show a comparison between the old and new versions of a file from changes made on a particular revision. This is similar to the ``diff`` handler. However, this form features a split or side-by-side diff rather than a unified diff. The ``context`` query string argument can be used to control the lines of context in the diff. The ``filecomparison`` template is rendered. """ ctx = webutil.changectx(web.repo, req) if 'file' not in req.form: raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') path = webutil.cleanpath(web.repo, req.form['file'][0]) rename = path in ctx and webutil.renamelink(ctx[path]) or [] parsecontext = lambda v: v == 'full' and -1 or int(v) if 'context' in req.form: context = parsecontext(req.form['context'][0]) else: context = parsecontext(web.config('web', 'comparisoncontext', '5')) def filelines(f): if util.binary(f.data()): mt = mimetypes.guess_type(f.path())[0] if not mt: mt = 'application/octet-stream' return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] return f.data().splitlines() parent = ctx.p1() leftrev = parent.rev() leftnode = parent.node() rightrev = ctx.rev() rightnode = ctx.node() if path in ctx: fctx = ctx[path] rightlines = filelines(fctx) if path not in parent: leftlines = () else: pfctx = parent[path] leftlines = filelines(pfctx) else: rightlines = () fctx = ctx.parents()[0][path] leftlines = filelines(fctx) comparison = webutil.compare(tmpl, context, leftlines, rightlines) return tmpl('filecomparison', file=path, node=hex(ctx.node()), rev=ctx.rev(), symrev=webutil.symrevorshortnode(req, ctx), date=ctx.date(), desc=ctx.description(), extra=ctx.extra(), author=ctx.user(), rename=rename, branch=webutil.nodebranchnodefault(ctx), parent=webutil.parents(fctx), child=webutil.children(fctx), tags=webutil.nodetagsdict(web.repo, ctx.node()), bookmarks=webutil.nodebookmarksdict(web.repo, ctx.node()), leftrev=leftrev, leftnode=hex(leftnode), rightrev=rightrev, rightnode=hex(rightnode), comparison=comparison)
def comparison(web, req, tmpl): """ /comparison/{revision}/{path} ----------------------------- Show a comparison between the old and new versions of a file from changes made on a particular revision. This is similar to the ``diff`` handler. However, this form features a split or side-by-side diff rather than a unified diff. The ``context`` query string argument can be used to control the lines of context in the diff. The ``filecomparison`` template is rendered. """ ctx = webutil.changectx(web.repo, req) if 'file' not in req.form: raise ErrorResponse(HTTP_NOT_FOUND, 'file not given') path = webutil.cleanpath(web.repo, req.form['file'][0]) rename = path in ctx and webutil.renamelink(ctx[path]) or [] parsecontext = lambda v: v == 'full' and -1 or int(v) if 'context' in req.form: context = parsecontext(req.form['context'][0]) else: context = parsecontext(web.config('web', 'comparisoncontext', '5')) def filelines(f): if util.binary(f.data()): mt = mimetypes.guess_type(f.path())[0] if not mt: mt = 'application/octet-stream' return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] return f.data().splitlines() parent = ctx.p1() leftrev = parent.rev() leftnode = parent.node() rightrev = ctx.rev() rightnode = ctx.node() if path in ctx: fctx = ctx[path] rightlines = filelines(fctx) if path not in parent: leftlines = () else: pfctx = parent[path] leftlines = filelines(pfctx) else: rightlines = () fctx = ctx.parents()[0][path] leftlines = filelines(fctx) comparison = webutil.compare(tmpl, context, leftlines, rightlines) return tmpl('filecomparison', file=path, node=hex(ctx.node()), rev=ctx.rev(), date=ctx.date(), desc=ctx.description(), extra=ctx.extra(), author=ctx.user(), rename=rename, branch=webutil.nodebranchnodefault(ctx), parent=webutil.parents(fctx), child=webutil.children(fctx), leftrev=leftrev, leftnode=hex(leftnode), rightrev=rightrev, rightnode=hex(rightnode), comparison=comparison)
def comparison(web, req, tmpl): ctx = webutil.changectx(web.repo, req) if "file" not in req.form: raise ErrorResponse(HTTP_NOT_FOUND, "file not given") path = webutil.cleanpath(web.repo, req.form["file"][0]) rename = path in ctx and webutil.renamelink(ctx[path]) or [] parsecontext = lambda v: v == "full" and -1 or int(v) if "context" in req.form: context = parsecontext(req.form["context"][0]) else: context = parsecontext(web.config("web", "comparisoncontext", "5")) def filelines(f): if binary(f.data()): mt = mimetypes.guess_type(f.path())[0] if not mt: mt = "application/octet-stream" return [_("(binary file %s, hash: %s)") % (mt, hex(f.filenode()))] return f.data().splitlines() if path in ctx: fctx = ctx[path] rightrev = fctx.filerev() rightnode = fctx.filenode() rightlines = filelines(fctx) parents = fctx.parents() if not parents: leftrev = -1 leftnode = nullid leftlines = () else: pfctx = parents[0] leftrev = pfctx.filerev() leftnode = pfctx.filenode() leftlines = filelines(pfctx) else: rightrev = -1 rightnode = nullid rightlines = () fctx = ctx.parents()[0][path] leftrev = fctx.filerev() leftnode = fctx.filenode() leftlines = filelines(fctx) comparison = webutil.compare(tmpl, context, leftlines, rightlines) return tmpl( "filecomparison", file=path, node=hex(ctx.node()), rev=ctx.rev(), date=ctx.date(), desc=ctx.description(), extra=ctx.extra(), author=ctx.user(), rename=rename, branch=webutil.nodebranchnodefault(ctx), parent=webutil.parents(fctx), child=webutil.children(fctx), leftrev=leftrev, leftnode=hex(leftnode), rightrev=rightrev, rightnode=hex(rightnode), comparison=comparison, )