Skip to content

Commit d08ca1c

Browse files
committed
add a note if files are the same
1 parent 9f94f99 commit d08ca1c

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

elixir/query.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ def get_versions(self):
176176
def get_file_type(self, version, path):
177177
return decode(self.script('get-type', version, path)).strip()
178178

179+
def get_blob_id(self, version, path):
180+
return decode(self.script('get-blob-id', version, path)).strip()
181+
179182
# Returns identifier search results
180183
def search_ident(self, version, ident, family):
181184
# DT bindings compatible strings are handled differently

elixir/web.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from .api import ApiIdentGetterResource
4444
from .query import get_query
4545
from .web_utils import ProjectConverter, IdentConverter, validate_version, validate_project, validate_ident, \
46-
get_elixir_version_string, get_elixir_repo_link, RequestContext, Config, DiffFormater
46+
get_elixir_version_string, get_elixir_repo_url, RequestContext, Config, DiffFormater
4747

4848
VERSION_CACHE_DURATION_SECONDS = 2 * 60 # 2 minutes
4949
ADD_ISSUE_LINK = "https://github.com/bootlin/elixir/issues/new"
@@ -884,7 +884,9 @@ def generate_diff_page(ctx: RequestContext, q: Query,
884884
breadcrumb_links.append((p, f'{ diff_base_url }{ path_temp }'))
885885

886886
type = q.get_file_type(version, path)
887-
type_other = q.get_file_type(version, path)
887+
type_other = q.get_file_type(version_other, path)
888+
blob_id = q.get_blob_id(version, path)
889+
blob_id_other = q.get_blob_id(version_other, path)
888890

889891
if type == 'tree' or type_other == 'tree':
890892
back_path = os.path.dirname(path[:-1])
@@ -906,7 +908,7 @@ def generate_warning(type, version):
906908
}
907909
template = ctx.jinja_env.get_template('tree.html')
908910
elif type == 'blob' or type_other == 'blob':
909-
if type == type_other == 'blob':
911+
if type == type_other == 'blob' and blob_id != blob_id_other:
910912
code, code_other = generate_diff(q, project, version, version_other, path)
911913
template_ctx = {
912914
'code': code,
@@ -915,10 +917,15 @@ def generate_warning(type, version):
915917
}
916918
template = ctx.jinja_env.get_template('diff.html')
917919
else:
918-
missing_version = version_other if type == 'blob' else version
920+
if blob_id == blob_id_other:
921+
warning = f'Files are the same in {version} and {version_other}.'
922+
else:
923+
missing_version = version_other if type == 'blob' else version
924+
warning = f'File does not exist or is not a file {missing_version}.'
925+
919926
template_ctx = {
920927
'code': generate_source(q, project, version if type == 'blob' else version_other, path),
921-
'warning': f'File does not exist in {missing_version}.'
928+
'warning': warning
922929
}
923930
template = ctx.jinja_env.get_template('source.html')
924931
else:

script.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ get_blob()
7979
git cat-file blob $opt1
8080
}
8181

82+
get_blob_id()
83+
{
84+
v=`echo $opt1 | version_rev`
85+
git ls-tree --format='%(objectname)' "$v" "`denormalize $opt2`" 2>/dev/null
86+
}
87+
8288
get_file()
8389
{
8490
v=`echo $opt1 | version_rev`
@@ -272,6 +278,10 @@ case $cmd in
272278
get_blob
273279
;;
274280

281+
get-blob-id)
282+
get_blob_id
283+
;;
284+
275285
get-file)
276286
get_file
277287
;;

0 commit comments

Comments
 (0)