@@ -444,6 +444,8 @@ def get_projects(basedir: str) -> list[ProjectEntry]:
444
444
# Used to render version list in the sidebar
445
445
VersionEntry = namedtuple ('VersionEntry' , 'version, url, diff_url' )
446
446
447
+ VersionPath = namedtuple ('VersionPath' , 'major, minor, path' )
448
+
447
449
# Takes result of Query.get_versions() and prepares it for the sidebar template.
448
450
# Returns an OrderedDict with version information and optionally a triple with
449
451
# (major, minor, version) of current_version. The triple is useful, because sometimes
@@ -456,10 +458,10 @@ def get_projects(basedir: str) -> list[ProjectEntry]:
456
458
def get_versions (versions : OrderedDict [str , OrderedDict [str , str ]],
457
459
get_url : Callable [[str ], str ],
458
460
get_diff_url : Optional [Callable [[str ], str ]],
459
- current_version : str ) -> Tuple [dict [str , dict [str , list [VersionEntry ]]], Tuple [ str | None , str | None , str | None ] ]:
461
+ current_version : str ) -> Tuple [dict [str , dict [str , list [VersionEntry ]]], VersionPath ]:
460
462
461
463
result = OrderedDict ()
462
- current_version_path = (None , None , None )
464
+ current_version_path = VersionPath (None , None , None )
463
465
for major , minor_verions in versions .items ():
464
466
for minor , patch_versions in minor_verions .items ():
465
467
for v in patch_versions :
@@ -471,10 +473,20 @@ def get_versions(versions: OrderedDict[str, OrderedDict[str, str]],
471
473
VersionEntry (v , get_url (v ), get_diff_url (v ) if get_diff_url is not None else None )
472
474
)
473
475
if v == current_version :
474
- current_version_path = (major , minor , v )
476
+ current_version_path = VersionPath (major , minor , v )
475
477
476
478
return result , current_version_path
477
479
480
+ def find_version_path (versions : OrderedDict [str , OrderedDict [str , str ]],
481
+ version : str ) -> VersionPath :
482
+ for major , minor_verions in versions .items ():
483
+ for minor , patch_versions in minor_verions .items ():
484
+ for v in patch_versions :
485
+ if v == version :
486
+ return VersionPath (major , minor , v )
487
+
488
+ return VersionPath (None , None , None )
489
+
478
490
def get_versions_cached (q , ctx , project ):
479
491
with ctx .versions_cache_lock :
480
492
if project not in ctx .versions_cache :
@@ -501,6 +513,7 @@ def get_layout_template_context(q: Query, ctx: RequestContext, get_url_with_new_
501
513
'projects' : get_projects (ctx .config .project_dir ),
502
514
'versions' : versions ,
503
515
'current_version_path' : current_version_path ,
516
+ 'other_version_path' : (None , None , None ),
504
517
'topbar_families' : TOPBAR_FAMILIES ,
505
518
'elixir_version_string' : ctx .config .version_string ,
506
519
'elixir_repo_url' : ctx .config .repo_url ,
@@ -920,7 +933,8 @@ def generate_warning(type, version):
920
933
warning = f'Files are the same in { version } and { version_other } .'
921
934
else :
922
935
missing_version = version_other if type == 'blob' else version
923
- warning = f'File does not exist, or is not a file in { missing_version } . ({ version } displayed)'
936
+ shown_version = version if type == 'blob' else version_other
937
+ warning = f'File does not exist, or is not a file in { missing_version } . ({ shown_version } displayed)'
924
938
925
939
template_ctx = {
926
940
'code' : generate_source (q , project , version if type == 'blob' else version_other , path ),
@@ -952,6 +966,7 @@ def generate_warning(type, version):
952
966
** get_layout_template_context (q , ctx , get_url_with_new_version , get_diff_url , project , version ),
953
967
** template_ctx ,
954
968
969
+ 'other_version_path' : find_version_path (get_versions_cached (q , ctx , project ), version_other ),
955
970
'diff_mode_available' : True ,
956
971
'diff_checked' : True ,
957
972
'diff_exit_url' : stringify_source_path (project , version , path ),
0 commit comments