@@ -21,6 +21,7 @@ function initCurrentState() {
2121 'shelf' : null ,
2222 'compatNum' : null ,
2323 'campaignCode' : [ ] ,
24+ 'catLabelPrefix' : '' ,
2425 'bell' : { 'origText' : null , 'origUrl' : null , 'pos' : null } ,
2526 'cat' : { 'origText' : null , 'origUrl' : null , 'pos' : null } ,
2627 'cfg' : { 'origText' : null , 'origUrl' : null , 'pos' : null } ,
@@ -42,6 +43,37 @@ function basename(path) {
4243 return path . split ( '/' ) . pop ( )
4344}
4445
46+ // Longest common directory prefix among a list of URLs/paths.
47+ // Example:
48+ // ["catalogue/aarch64/cats/aarch64.cat",
49+ // "catalogue/aarch64/cats/ArmARM-L.b/aarch64.cat"]
50+ // -> "catalogue/aarch64/cats/"
51+ function commonDirPrefix ( urls ) {
52+ if ( ! urls || urls . length === 0 ) return '' ;
53+ var prefix = urls [ 0 ] ;
54+ for ( var i = 1 ; i < urls . length ; i ++ ) {
55+ var u = urls [ i ] ;
56+ var j = 0 ;
57+ while ( j < prefix . length && j < u . length && prefix [ j ] === u [ j ] ) j ++ ;
58+ prefix = prefix . substring ( 0 , j ) ;
59+ if ( prefix === '' ) break ;
60+ }
61+ // Only keep whole-directory prefix
62+ var slash = prefix . lastIndexOf ( '/' ) ;
63+ return slash >= 0 ? prefix . substring ( 0 , slash + 1 ) : '' ;
64+ }
65+
66+ // Label cats by stripping the common prefix (computed per-record).
67+ // Falls back to basename if the prefix isn't known or doesn't match.
68+ function catLabel ( url ) {
69+ var prefix = currentState [ 'catLabelPrefix' ] || '' ;
70+ if ( url === null ) return '' ;
71+ if ( prefix && url . indexOf ( prefix ) === 0 ) {
72+ return url . substring ( prefix . length ) ;
73+ }
74+ return basename ( url ) ;
75+ }
76+
4577function shortname ( path ) {
4678 if ( path === null ) {
4779 return null
@@ -258,8 +290,9 @@ function populateEditorPanelHeader(id, elems) {
258290}
259291
260292function prepareEditorFile ( editorName , key , val , callback ) {
261- var baseVal = basename ( val ) ;
262- var itemId = 'file-' + baseVal . replace ( / \+ / g, '.' ) ;
293+ var baseVal = ( editorName === 'cat' ) ? catLabel ( val ) : basename ( val ) ;
294+ // baseVal may contain '/', so sanitize for HTML id usage.
295+ var itemId = 'file-' + baseVal . replace ( / \+ / g, '.' ) . replace ( / \/ / g, '__' ) ;
263296
264297 return $ ( '<li/>' )
265298 . append ( $ ( '<a/>' , {
@@ -333,7 +366,11 @@ function doDownloadAndSetEditorValue(url, name, pos) {
333366 currentState [ name ] [ 'pos' ] = pos ;
334367 updateLinkToExample ( ) ;
335368
336- $ ( selectMenuIdOfEditorName ( name ) ) . html ( basename ( url ) ) ;
369+ if ( name === 'cat' ) {
370+ $ ( selectMenuIdOfEditorName ( name ) ) . html ( catLabel ( url ) ) ;
371+ } else {
372+ $ ( selectMenuIdOfEditorName ( name ) ) . html ( basename ( url ) ) ;
373+ }
337374
338375 editors [ name ] . setValue ( data , - 1 ) ;
339376 if ( name === 'litmus' ) {
@@ -815,6 +852,10 @@ function readRecord(record, displayName, compatNum, bellKey, catKey, cfgKey, lit
815852 currentState [ 'displayName' ] = displayName ;
816853 currentState [ 'shelf' ] = resolveUrlsInShelf ( result , record ) ;
817854
855+ // Precompute the common prefix used to label cats uniquely.
856+ // resolveUrlsInShelf has expanded entries to full URLs like "catalogue/<record>/<...>".
857+ currentState [ 'catLabelPrefix' ] = commonDirPrefix ( currentState [ 'shelf' ] [ 'cats' ] || [ ] ) ;
858+
818859 updateAllEditors ( compatNum , bellKey , catKey , cfgKey , litmusKey , false ) ;
819860
820861 if ( currentState [ 'shelf' ] [ 'compatibilities' ] === null ) {
@@ -960,11 +1001,16 @@ function jerdIt() {
9601001 var catStr = editors [ 'cat' ] . getValue ( ) ;
9611002 var cfgStr = editors [ 'cfg' ] . getValue ( ) ;
9621003 var litmusStr = editors [ 'litmus' ] . getValue ( ) ;
1004+ var catSelectedLabel = '' ;
1005+ if ( currentState [ 'cat' ] && currentState [ 'cat' ] [ 'origUrl' ] !== null ) {
1006+ catSelectedLabel = catLabel ( currentState [ 'cat' ] [ 'origUrl' ] ) ;
1007+ }
9631008 runHerd (
9641009 bellStr ,
9651010 catStr ,
9661011 litmusStr ,
9671012 cfgStr ,
1013+ catSelectedLabel ,
9681014 ) ;
9691015 displayDotOutputs ( ) ;
9701016}
@@ -980,12 +1026,17 @@ function jerdAll() {
9801026 var cfgStr = editors [ 'cfg' ] . getValue ( ) ;
9811027 var catStr = editors [ 'cat' ] . getValue ( ) ;
9821028 var litmusStr = data ;
1029+ var catSelectedLabel = '' ;
1030+ if ( currentState [ 'cat' ] && currentState [ 'cat' ] [ 'origUrl' ] !== null ) {
1031+ catSelectedLabel = catLabel ( currentState [ 'cat' ] [ 'origUrl' ] ) ;
1032+ }
9831033
9841034 runHerd (
9851035 bellStr ,
9861036 catStr ,
9871037 litmusStr ,
9881038 cfgStr ,
1039+ catSelectedLabel ,
9891040 ) ;
9901041
9911042 var herdOutput = editors [ 'herdoutput' ] . getValue ( ) ;
0 commit comments