##// END OF EJS Templates
hgweb: handle a "linerange" request parameter in filelog command...
Denis Laxalde -
r31665:5e6d4451 default
parent child Browse files
Show More
@@ -28,6 +28,7 b' from .common import ('
28
28
29 from .. import (
29 from .. import (
30 archival,
30 archival,
31 context,
31 encoding,
32 encoding,
32 error,
33 error,
33 graphmod,
34 graphmod,
@@ -968,6 +969,8 b' def filelog(web, req, tmpl):'
968 except ValueError:
969 except ValueError:
969 pass
970 pass
970
971
972 lrange = webutil.linerange(req)
973
971 lessvars = copy.copy(tmpl.defaults['sessionvars'])
974 lessvars = copy.copy(tmpl.defaults['sessionvars'])
972 lessvars['revcount'] = max(revcount / 2, 1)
975 lessvars['revcount'] = max(revcount / 2, 1)
973 morevars = copy.copy(tmpl.defaults['sessionvars'])
976 morevars = copy.copy(tmpl.defaults['sessionvars'])
@@ -996,24 +999,49 b' def filelog(web, req, tmpl):'
996 path = fctx.path()
999 path = fctx.path()
997 return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle)
1000 return webutil.diffs(web, tmpl, ctx, basectx, [path], diffstyle)
998
1001
999 for i in revs:
1002 linerange = None
1000 iterfctx = fctx.filectx(i)
1003 if lrange is not None:
1001 diffs = None
1004 linerange = webutil.formatlinerange(*lrange)
1002 if patch:
1005 # deactivate numeric nav links when linerange is specified as this
1003 diffs = diff(iterfctx)
1006 # would required a dedicated "revnav" class
1004 entries.append(dict(
1007 nav = None
1005 parity=next(parity),
1008 ancestors = context.blockancestors(fctx, *lrange)
1006 filerev=i,
1009 for i, (c, lr) in enumerate(ancestors, 1):
1007 file=f,
1010 diffs = None
1008 diff=diffs,
1011 if patch:
1009 rename=webutil.renamelink(iterfctx),
1012 diffs = diff(c)
1010 **webutil.commonentry(repo, iterfctx)))
1013 # follow renames accross filtered (not in range) revisions
1011 entries.reverse()
1014 path = c.path()
1015 entries.append(dict(
1016 parity=next(parity),
1017 filerev=c.rev(),
1018 file=path,
1019 diff=diffs,
1020 linerange=webutil.formatlinerange(*lr),
1021 **webutil.commonentry(repo, c)))
1022 if i == revcount:
1023 break
1024 lessvars['linerange'] = webutil.formatlinerange(*lrange)
1025 morevars['linerange'] = lessvars['linerange']
1026 else:
1027 for i in revs:
1028 iterfctx = fctx.filectx(i)
1029 diffs = None
1030 if patch:
1031 diffs = diff(iterfctx)
1032 entries.append(dict(
1033 parity=next(parity),
1034 filerev=i,
1035 file=f,
1036 diff=diffs,
1037 rename=webutil.renamelink(iterfctx),
1038 **webutil.commonentry(repo, iterfctx)))
1039 entries.reverse()
1040 revnav = webutil.filerevnav(web.repo, fctx.path())
1041 nav = revnav.gen(end - 1, revcount, count)
1012
1042
1013 latestentry = entries[:1]
1043 latestentry = entries[:1]
1014
1044
1015 revnav = webutil.filerevnav(web.repo, fctx.path())
1016 nav = revnav.gen(end - 1, revcount, count)
1017 return tmpl("filelog",
1045 return tmpl("filelog",
1018 file=f,
1046 file=f,
1019 nav=nav,
1047 nav=nav,
@@ -1021,6 +1049,7 b' def filelog(web, req, tmpl):'
1021 entries=entries,
1049 entries=entries,
1022 patch=patch,
1050 patch=patch,
1023 latestentry=latestentry,
1051 latestentry=latestentry,
1052 linerange=linerange,
1024 revcount=revcount,
1053 revcount=revcount,
1025 morevars=morevars,
1054 morevars=morevars,
1026 lessvars=lessvars,
1055 lessvars=lessvars,
@@ -18,6 +18,7 b' from ..node import hex, nullid, short'
18
18
19 from .common import (
19 from .common import (
20 ErrorResponse,
20 ErrorResponse,
21 HTTP_BAD_REQUEST,
21 HTTP_NOT_FOUND,
22 HTTP_NOT_FOUND,
22 paritygen,
23 paritygen,
23 )
24 )
@@ -317,6 +318,26 b' def filectx(repo, req):'
317
318
318 return fctx
319 return fctx
319
320
321 def linerange(req):
322 linerange = req.form.get('linerange')
323 if linerange is None:
324 return None
325 if len(linerange) > 1:
326 raise ErrorResponse(HTTP_BAD_REQUEST,
327 'redundant linerange parameter')
328 try:
329 fromline, toline = map(int, linerange[0].split(':', 1))
330 except ValueError:
331 raise ErrorResponse(HTTP_BAD_REQUEST,
332 'invalid linerange parameter')
333 try:
334 return util.processlinerange(fromline, toline)
335 except error.ParseError as exc:
336 raise ErrorResponse(HTTP_BAD_REQUEST, str(exc))
337
338 def formatlinerange(fromline, toline):
339 return '%d:%d' % (fromline + 1, toline)
340
320 def commonentry(repo, ctx):
341 def commonentry(repo, ctx):
321 node = ctx.node()
342 node = ctx.node()
322 return {
343 return {
@@ -47,6 +47,8 b''
47 <h3>
47 <h3>
48 log {file|escape} @ {rev}:<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>
48 log {file|escape} @ {rev}:<a href="{url|urlescape}rev/{node|short}{sessionvars%urlparameter}">{node|short}</a>
49 {branch%changelogbranchname}{tags%changelogtag}{bookmarks%changelogtag}
49 {branch%changelogbranchname}{tags%changelogtag}{bookmarks%changelogtag}
50 {if(linerange,
51 ' (following lines {linerange} <a href="{url|urlescape}log/{symrev}/{file|urlescape}{sessionvars%urlparameter}">back to filelog</a>)')}
50 </h3>
52 </h3>
51
53
52 <form class="search" action="{url|urlescape}log">
54 <form class="search" action="{url|urlescape}log">
@@ -190,6 +190,7 b' tip - two revisions'
190 <h3>
190 <h3>
191 log a @ 4:<a href="/rev/3f41bc784e7e">3f41bc784e7e</a>
191 log a @ 4:<a href="/rev/3f41bc784e7e">3f41bc784e7e</a>
192 <span class="branchname">a-branch</span>
192 <span class="branchname">a-branch</span>
193
193 </h3>
194 </h3>
194
195
195 <form class="search" action="/log">
196 <form class="search" action="/log">
@@ -311,6 +312,7 b' second version - two revisions'
311 <h3>
312 <h3>
312 log a @ 4:<a href="/rev/3f41bc784e7e">3f41bc784e7e</a>
313 log a @ 4:<a href="/rev/3f41bc784e7e">3f41bc784e7e</a>
313 <span class="branchname">a-branch</span>
314 <span class="branchname">a-branch</span>
315
314 </h3>
316 </h3>
315
317
316 <form class="search" action="/log">
318 <form class="search" action="/log">
@@ -432,6 +434,7 b' first deleted - one revision'
432 <h3>
434 <h3>
433 log a @ 1:<a href="/rev/5ed941583260">5ed941583260</a>
435 log a @ 1:<a href="/rev/5ed941583260">5ed941583260</a>
434 <span class="tag">a-tag</span> <span class="tag">a-bookmark</span>
436 <span class="tag">a-tag</span> <span class="tag">a-bookmark</span>
437
435 </h3>
438 </h3>
436
439
437 <form class="search" action="/log">
440 <form class="search" action="/log">
@@ -544,6 +547,7 b' first version - one revision'
544 <h3>
547 <h3>
545 log a @ 1:<a href="/rev/5ed941583260">5ed941583260</a>
548 log a @ 1:<a href="/rev/5ed941583260">5ed941583260</a>
546 <span class="tag">a-tag</span> <span class="tag">a-bookmark</span>
549 <span class="tag">a-tag</span> <span class="tag">a-bookmark</span>
550
547 </h3>
551 </h3>
548
552
549 <form class="search" action="/log">
553 <form class="search" action="/log">
@@ -660,6 +664,264 b' before addition - error'
660
664
661 [1]
665 [1]
662
666
667 $ hg log -r 'followlines(c, 1:2, startrev=tip) and follow(c)'
668 changeset: 0:6563da9dcf87
669 user: test
670 date: Thu Jan 01 00:00:00 1970 +0000
671 summary: b
672
673 changeset: 7:46c1a66bd8fc
674 branch: a-branch
675 tag: tip
676 user: test
677 date: Thu Jan 01 00:00:00 1970 +0000
678 summary: change c
679
680 $ (get-with-headers.py localhost:$HGPORT 'log/tip/c?linerange=1:2')
681 200 Script output follows
682
683 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
684 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
685 <head>
686 <link rel="icon" href="/static/hgicon.png" type="image/png" />
687 <meta name="robots" content="index, nofollow" />
688 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
689 <script type="text/javascript" src="/static/mercurial.js"></script>
690
691 <title>test: c history</title>
692 <link rel="alternate" type="application/atom+xml"
693 href="/atom-log/tip/c" title="Atom feed for test:c" />
694 <link rel="alternate" type="application/rss+xml"
695 href="/rss-log/tip/c" title="RSS feed for test:c" />
696 </head>
697 <body>
698
699 <div class="container">
700 <div class="menu">
701 <div class="logo">
702 <a href="https://mercurial-scm.org/">
703 <img src="/static/hglogo.png" alt="mercurial" /></a>
704 </div>
705 <ul>
706 <li><a href="/shortlog/tip">log</a></li>
707 <li><a href="/graph/tip">graph</a></li>
708 <li><a href="/tags">tags</a></li>
709 <li><a href="/bookmarks">bookmarks</a></li>
710 <li><a href="/branches">branches</a></li>
711 </ul>
712 <ul>
713 <li><a href="/rev/tip">changeset</a></li>
714 <li><a href="/file/tip">browse</a></li>
715 </ul>
716 <ul>
717 <li><a href="/file/tip/c">file</a></li>
718 <li><a href="/diff/tip/c">diff</a></li>
719 <li><a href="/comparison/tip/c">comparison</a></li>
720 <li><a href="/annotate/tip/c">annotate</a></li>
721 <li class="active">file log</li>
722 <li><a href="/raw-file/tip/c">raw</a></li>
723 </ul>
724 <ul>
725 <li><a href="/help">help</a></li>
726 </ul>
727 <div class="atom-logo">
728 <a href="/atom-log/tip/c" title="subscribe to atom feed">
729 <img class="atom-logo" src="/static/feed-icon-14x14.png" alt="atom feed" />
730 </a>
731 </div>
732 </div>
733
734 <div class="main">
735 <h2 class="breadcrumb"><a href="/">Mercurial</a> </h2>
736 <h3>
737 log c @ 7:<a href="/rev/46c1a66bd8fc">46c1a66bd8fc</a>
738 <span class="branchname">a-branch</span> <span class="tag">tip</span>
739 (following lines 1:2 <a href="/log/tip/c">back to filelog</a>)
740 </h3>
741
742 <form class="search" action="/log">
743
744 <p><input name="rev" id="search1" type="text" size="30" /></p>
745 <div id="hint">Find changesets by keywords (author, files, the commit message), revision
746 number or hash, or <a href="/help/revsets">revset expression</a>.</div>
747 </form>
748
749 <div class="navigate">
750 <a href="/log/tip/c?linerange=1%3A2&revcount=30">less</a>
751 <a href="/log/tip/c?linerange=1%3A2&revcount=120">more</a>
752 | </div>
753
754 <table class="bigtable">
755 <thead>
756 <tr>
757 <th class="age">age</th>
758 <th class="author">author</th>
759 <th class="description">description</th>
760 </tr>
761 </thead>
762 <tbody class="stripes2">
763 <tr>
764 <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
765 <td class="author">test</td>
766 <td class="description">
767 <a href="/rev/46c1a66bd8fc">change c</a>
768 <span class="branchhead">a-branch</span> <span class="tag">tip</span>
769 </td>
770 </tr>
771
772 <tr>
773 <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
774 <td class="author">test</td>
775 <td class="description">
776 <a href="/rev/6563da9dcf87">b</a>
777
778 </td>
779 </tr>
780
781
782 </tbody>
783 </table>
784
785 <div class="navigate">
786 <a href="/log/tip/c?linerange=1%3A2&revcount=30">less</a>
787 <a href="/log/tip/c?linerange=1%3A2&revcount=120">more</a>
788 |
789 </div>
790
791 </div>
792 </div>
793
794
795
796 </body>
797 </html>
798
799 $ (get-with-headers.py localhost:$HGPORT 'log/tip/c?linerange=1%3A2&revcount=1')
800 200 Script output follows
801
802 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
803 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US">
804 <head>
805 <link rel="icon" href="/static/hgicon.png" type="image/png" />
806 <meta name="robots" content="index, nofollow" />
807 <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
808 <script type="text/javascript" src="/static/mercurial.js"></script>
809
810 <title>test: c history</title>
811 <link rel="alternate" type="application/atom+xml"
812 href="/atom-log/tip/c" title="Atom feed for test:c" />
813 <link rel="alternate" type="application/rss+xml"
814 href="/rss-log/tip/c" title="RSS feed for test:c" />
815 </head>
816 <body>
817
818 <div class="container">
819 <div class="menu">
820 <div class="logo">
821 <a href="https://mercurial-scm.org/">
822 <img src="/static/hglogo.png" alt="mercurial" /></a>
823 </div>
824 <ul>
825 <li><a href="/shortlog/tip?revcount=1">log</a></li>
826 <li><a href="/graph/tip?revcount=1">graph</a></li>
827 <li><a href="/tags?revcount=1">tags</a></li>
828 <li><a href="/bookmarks?revcount=1">bookmarks</a></li>
829 <li><a href="/branches?revcount=1">branches</a></li>
830 </ul>
831 <ul>
832 <li><a href="/rev/tip?revcount=1">changeset</a></li>
833 <li><a href="/file/tip?revcount=1">browse</a></li>
834 </ul>
835 <ul>
836 <li><a href="/file/tip/c?revcount=1">file</a></li>
837 <li><a href="/diff/tip/c?revcount=1">diff</a></li>
838 <li><a href="/comparison/tip/c?revcount=1">comparison</a></li>
839 <li><a href="/annotate/tip/c?revcount=1">annotate</a></li>
840 <li class="active">file log</li>
841 <li><a href="/raw-file/tip/c">raw</a></li>
842 </ul>
843 <ul>
844 <li><a href="/help?revcount=1">help</a></li>
845 </ul>
846 <div class="atom-logo">
847 <a href="/atom-log/tip/c" title="subscribe to atom feed">
848 <img class="atom-logo" src="/static/feed-icon-14x14.png" alt="atom feed" />
849 </a>
850 </div>
851 </div>
852
853 <div class="main">
854 <h2 class="breadcrumb"><a href="/">Mercurial</a> </h2>
855 <h3>
856 log c @ 7:<a href="/rev/46c1a66bd8fc?revcount=1">46c1a66bd8fc</a>
857 <span class="branchname">a-branch</span> <span class="tag">tip</span>
858 (following lines 1:2 <a href="/log/tip/c?revcount=1">back to filelog</a>)
859 </h3>
860
861 <form class="search" action="/log">
862 <input type="hidden" name="revcount" value="1" />
863 <p><input name="rev" id="search1" type="text" size="30" /></p>
864 <div id="hint">Find changesets by keywords (author, files, the commit message), revision
865 number or hash, or <a href="/help/revsets">revset expression</a>.</div>
866 </form>
867
868 <div class="navigate">
869 <a href="/log/tip/c?linerange=1%3A2&revcount=1">less</a>
870 <a href="/log/tip/c?linerange=1%3A2&revcount=2">more</a>
871 | </div>
872
873 <table class="bigtable">
874 <thead>
875 <tr>
876 <th class="age">age</th>
877 <th class="author">author</th>
878 <th class="description">description</th>
879 </tr>
880 </thead>
881 <tbody class="stripes2">
882 <tr>
883 <td class="age">Thu, 01 Jan 1970 00:00:00 +0000</td>
884 <td class="author">test</td>
885 <td class="description">
886 <a href="/rev/46c1a66bd8fc?revcount=1">change c</a>
887 <span class="branchhead">a-branch</span> <span class="tag">tip</span>
888 </td>
889 </tr>
890
891
892 </tbody>
893 </table>
894
895 <div class="navigate">
896 <a href="/log/tip/c?linerange=1%3A2&revcount=1">less</a>
897 <a href="/log/tip/c?linerange=1%3A2&revcount=2">more</a>
898 |
899 </div>
900
901 </div>
902 </div>
903
904
905
906 </body>
907 </html>
908
909 $ (get-with-headers.py localhost:$HGPORT 'log/3/a?linerange=1' --headeronly)
910 400 invalid linerange parameter
911 [1]
912 $ (get-with-headers.py localhost:$HGPORT 'log/3/a?linerange=1:a' --headeronly)
913 400 invalid linerange parameter
914 [1]
915 $ (get-with-headers.py localhost:$HGPORT 'log/3/a?linerange=1:2&linerange=3:4' --headeronly)
916 400 redundant linerange parameter
917 [1]
918 $ (get-with-headers.py localhost:$HGPORT 'log/3/a?linerange=3:2' --headeronly)
919 400 line range must be positive
920 [1]
921 $ (get-with-headers.py localhost:$HGPORT 'log/3/a?linerange=0:1' --headeronly)
922 400 fromline must be strictly positive
923 [1]
924
663 should show base link, use spartan because it shows it
925 should show base link, use spartan because it shows it
664
926
665 $ (get-with-headers.py localhost:$HGPORT 'log/tip/c?style=spartan')
927 $ (get-with-headers.py localhost:$HGPORT 'log/tip/c?style=spartan')
@@ -829,6 +1091,7 b' filelog with patch'
829 <h3>
1091 <h3>
830 log a @ 4:<a href="/rev/3f41bc784e7e">3f41bc784e7e</a>
1092 log a @ 4:<a href="/rev/3f41bc784e7e">3f41bc784e7e</a>
831 <span class="branchname">a-branch</span>
1093 <span class="branchname">a-branch</span>
1094
832 </h3>
1095 </h3>
833
1096
834 <form class="search" action="/log">
1097 <form class="search" action="/log">
General Comments 0
You need to be logged in to leave comments. Login now