Files @ b293ec74ef98
Branch filter:

Location: kallithea/scripts/logformat.py

Thomas De Schampheleire
files: restore 'Show Authors' functionality

Commit d66201a7ce6e ("files: change "callbacks" function to the more
descriptive name "post_load_state" and let it take an actual state data
object") broke the 'Show Authors' button when visiting a file
in the files browser. The button normally shows a count of authors and their
avatars, but after the aforementioned commit it did nothing.

Following patch would have fixed the problems in commit d66201a7ce6e:

diff --git a/kallithea/templates/files/files_source.html b/kallithea/templates/files/files_source.html
--- a/kallithea/templates/files/files_source.html
+++ b/kallithea/templates/files/files_source.html
@@ -81,11 +81,13 @@
<script>
$(document).ready(function(){
var state = {
+ data: {
node_list_url: node_list_url.replace('__REV__',${h.js(c.changeset.raw_id)}).replace('__FPATH__', ${h.js(h.safe_unicode(c.file.path))}),
url_base: url_base.replace('__REV__',${h.js(c.changeset.raw_id)}),
rev: ${h.js(c.changeset.raw_id)},
f_path: ${h.js(h.safe_unicode(c.file.path))}
+ }
}
- post_load_state(State.data); // defined in files.html
+ post_load_state(state.data); // defined in files.html
});
</script>


But, later the code got refactored more, and commit 006d68c4d7b9 ("files:
use the web browsers built-in js history instead of native.history.js")
broke the feature further: the click handler for the button no longer got
installed on the 'document-ready' event, but only when a new 'state' is
loaded. And it seems there is never a situation where a new state preserves
the button, so it makes no sense installing the click handler at that
moment.

Instead, move the click handler back to the 'document-ready' event.
#!/usr/bin/env python2

import re
import sys

if len(sys.argv) < 2:
    print 'Cleanup of superfluous % formatting of log statements.'
    print 'Usage:'
    print '''  hg revert `hg loc '*.py'|grep -v logformat.py` && scripts/logformat.py `hg loc '*.py'` && hg diff'''
    raise SystemExit(1)


logre = r'''
(log\.(?:error|info|warning|debug)
[(][ \n]*
)
%s
(
[ \n]*[)]
)
'''
res = [
    # handle % () - keeping spaces around the old %
    (re.compile(logre % r'''("[^"]*"|'[^']*')   ([\n ]*) %  ([\n ]*) \( ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* ) \) ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
    # handle % without () - keeping spaces around the old %
    (re.compile(logre % r'''("[^"]*"|'[^']*')   ([\n ]*) %  ([\n ]*)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* )    ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
    # remove extra space if it is on next line
    (re.compile(logre % r'''("[^"]*"|'[^']*') , (\n [ ]) ([ ][\n ]*)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* )    ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
    # remove extra space if it is on same line
    (re.compile(logre % r'''("[^"]*"|'[^']*') , [ ]+  () (   [\n ]+)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* )    ''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
    # remove trailing , and space
    (re.compile(logre % r'''("[^"]*"|'[^']*') ,       () (   [\n ]*)    ( (?:[^()]|\n)* (?: \( (?:[^()]|\n)* \) (?:[^()]|\n)* )* [^(), \n] ) [ ,]*''', flags=re.MULTILINE|re.VERBOSE), r'\1\2,\3\4\5\6'),
    ]

for f in sys.argv[1:]:
    s = open(f).read()
    for r, t in res:
        s = r.sub(t, s)
    open(f, 'w').write(s)