Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Diff view #396

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -364,16 +364,15 @@ new project:
ln -s /srv/git/zephyr.git repo
export LXR_DATA_DIR=$LXR_PROJ_DIR/data
export LXR_REPO_DIR=$LXR_PROJ_DIR/repo
export LXR_DATA_DIR=$LXR_PROJ_DIR/data
export LXR_REPO_DIR=$LXR_PROJ_DIR/repo

Now, go back to the Elixir sources and test that tags are correctly
extracted:

./script.sh list-tags

Depending on how you want to show the available versions on the Elixir pages,
you may have to apply substitutions to each tag string, for example to add
a `v` prefix if missing, for consistency with how other project versions are
shown. You may also decide to ignore specific tags. All this can be done
by redefining the default `list_tags()` function in a new `projects/<projectname>.sh`
file. Here's an example (`projects/zephyr.sh` file):

Expand Down Expand Up @@ -429,8 +428,6 @@ You can then check that Elixir works through your http server.

== Coding style

If you wish to contribute to Elixir's Python code, please
follow the https://www.python.org/dev/peps/pep-0008/[official coding style for Python].

== How to send patches

Expand Down
4 changes: 2 additions & 2 deletions elixir/filters/configin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches, format_source_link

# Filters for Config.in includes
# source "path/file"
Expand All @@ -23,7 +23,7 @@ def keep_configin(m):
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
def replace_configin(m):
w = self.configin[decode_number(m.group(1)) - 1]
return f'<a href="{ ctx.get_absolute_source_url(w) }">{ w }</a>'
return format_source_link(ctx.get_absolute_source_url(w), w)

return re.sub('__KEEPCONFIGIN__([A-J]+)', replace_configin, html, flags=re.MULTILINE)

5 changes: 2 additions & 3 deletions elixir/filters/cppinc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches, format_source_link

# Filters for cpp includes like these:
# #include "file"
Expand All @@ -24,8 +24,7 @@ def keep_cppinc(m):
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
def replace_cppinc(m):
w = self.cppinc[decode_number(m.group(1)) - 1]
url = ctx.get_relative_source_url(w)
return f'<a href="{ url }">{ w }</a>'
return format_source_link(ctx.get_relative_source_url(w), w)

return re.sub('__KEEPCPPINC__([A-J]+)', replace_cppinc, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/cpppathinc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches, format_source_link

# Filters for cpp includes like these:
# #include <file>
Expand Down Expand Up @@ -36,7 +36,7 @@ def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
def replace_cpppathinc(m):
w = self.cpppathinc[decode_number(m.group(1)) - 1]
path = f'/include/{ w }'
return f'<a href="{ ctx.get_absolute_source_url(path) }">{ w }</a>'
return format_source_link(ctx.get_absolute_source_url(path), w)

return re.sub('__KEEPCPPPATHINC__([A-J]+)', replace_cpppathinc, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/dtsi.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches
from .utils import Filter, FilterContext, encode_number, decode_number, extension_matches, format_source_link

# Filters for dts includes as follows:
# Replaces include directives in dts/dtsi files with links to source
Expand All @@ -24,7 +24,7 @@ def keep_dtsi(m):
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
def replace_dtsi(m):
w = self.dtsi[decode_number(m.group(1)) - 1]
return f'<a href="{ ctx.get_relative_source_url(w) }">{ w }</a>'
return format_source_link(ctx.get_relative_source_url(w), w)

return re.sub('__KEEPDTSI__([A-J]+)', replace_dtsi, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/kconfig.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from .utils import Filter, FilterContext, encode_number, decode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, encode_number, decode_number, filename_without_ext_matches, format_source_link

# Filters for Kconfig includes
# Replaces KConfig includes (source keyword) with links to included files
Expand All @@ -24,7 +24,7 @@ def keep_kconfig(m):
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
def replace_kconfig(m):
w = self.kconfig[decode_number(m.group(1)) - 1]
return f'<a href="{ ctx.get_absolute_source_url(w) }">{ w }</a>'
return format_source_link(ctx.get_absolute_source_url(w), w)

return re.sub('__KEEPKCONFIG__([A-J]+)', replace_kconfig, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/makefiledir.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os.path import dirname
import re
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches, format_source_link

# Filters for Makefile directory includes as follows:
# obj-$(VALUE) += dir/
Expand Down Expand Up @@ -39,7 +39,7 @@ def replace_makefiledir(m):

fpath = f'{ filedir }{ w }/Makefile'

return f'<a href="{ ctx.get_absolute_source_url(fpath) }">{ w }/</a>'
return format_source_link(ctx.get_absolute_source_url(fpath), w)

return re.sub('__KEEPMAKEFILEDIR__([A-J]+)/', replace_makefiledir, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/makefiledtb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os.path import dirname
import re
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches, format_source_link

# Filters for Makefile file includes like these:
# dtb-y += file.dtb
Expand Down Expand Up @@ -30,7 +30,7 @@ def replace_makefiledtb(m):
filedir += '/'

npath = f'{ filedir }{ w }.dts'
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }.dtb</a>'
return format_source_link(ctx.get_absolute_source_url(npath), w+'.dtb')

return re.sub('__KEEPMAKEFILEDTB__([A-J]+)\.dtb', replace_makefiledtb, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/makefilefile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os.path import dirname
import re
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches, format_source_link

# Filters for files listed in Makefiles
# path/file
Expand Down Expand Up @@ -38,7 +38,7 @@ def replace_makefilefile(m):
filedir += '/'

npath = filedir + w
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }</a>'
return format_source_link(ctx.get_absolute_source_url(npath), w)

return re.sub('__KEEPMAKEFILEFILE__([A-J]+)', replace_makefilefile, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/makefileo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os.path import dirname
import re
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches, format_source_link

# Filters for Makefile file includes like these:
# file.o
Expand Down Expand Up @@ -30,7 +30,7 @@ def replace_makefileo(m):
filedir += '/'

npath = f'{ filedir }{ w }.c'
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }.o</a>'
return format_source_link(ctx.get_absolute_source_url(npath), w+'.o')

return re.sub('__KEEPMAKEFILEO__([A-J]+)\.o', replace_makefileo, html, flags=re.MULTILINE)

5 changes: 2 additions & 3 deletions elixir/filters/makefilesrctree.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches, format_source_link

# Filters for files listed in Makefiles using $(srctree)
# $(srctree)/Makefile
Expand Down Expand Up @@ -27,8 +27,7 @@ def keep_makefilesrctree(m):
def untransform_formatted_code(self, ctx: FilterContext, html: str) -> str:
def replace_makefilesrctree(m):
w = self.makefilesrctree[decode_number(m.group(1)) - 1]
url = ctx.get_absolute_source_url(w)
return f'<a href="{ url }">$(srctree)/{ w }</a>'
return format_source_link(ctx.get_absolute_source_url(w), f'$(srctree)/{ w }')

return re.sub('__KEEPMAKEFILESRCTREE__([A-J]+)', replace_makefilesrctree, html, flags=re.MULTILINE)

4 changes: 2 additions & 2 deletions elixir/filters/makefilesubdir.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from os.path import dirname
import re
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches
from .utils import Filter, FilterContext, decode_number, encode_number, filename_without_ext_matches, format_source_link

# Filters for Makefile directory includes as follows:
# subdir-y += dir
Expand Down Expand Up @@ -31,7 +31,7 @@ def replace_makefilesubdir(m):
filedir += '/'

npath = f'{ filedir }{ w }/Makefile'
return f'<a href="{ ctx.get_absolute_source_url(npath) }">{ w }</a>'
return format_source_link(ctx.get_absolute_source_url(npath), w)

return re.sub('__KEEPMAKESUBDIR__([A-J]+)', replace_makefilesubdir, html, flags=re.MULTILINE)

3 changes: 3 additions & 0 deletions elixir/filters/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,6 @@ def decode_number(string):

return int(result)

def format_source_link(url: str, label: str) -> str:
return f'<a class="source-link" href="{ url }">{ label }</a>'

20 changes: 20 additions & 0 deletions elixir/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from . import lib
from . import data
import os
import sys
from collections import OrderedDict
from urllib import parse

Expand Down Expand Up @@ -264,6 +265,25 @@ def query(self, cmd, *args):
else:
return 'Unknown subcommand: ' + cmd + '\n'

def get_diff(self, version, version_other, path):
data = decode(self.script('get-diff', version, version_other, path)).split('\n')
result = []
for line in data:
if len(line) == 0:
continue
elif line[0] == '+':
line_num_left, line_num_right, changes = line[1:].split(':')
result.append(('+', int(line_num_left), int(line_num_right), int(changes)))
elif line[0] == '-':
line_num_left, line_num_right, changes = line[1:].split(':')
result.append(('-', int(line_num_left), int(line_num_right), int(changes)))
elif line[0] == '=':
line_num, changes, other_line_num, other_changes = line[1:].split(':')
result.append(('=', int(line_num), int(changes), int(other_line_num), int(other_changes)))
else:
raise Exception("Invalid line in get-diff: " + line)
return result

def get_file_raw(self, version, path):
return decode(self.script('get-file', version, path))

Expand Down
Loading