swish/commit

New upstream version

authorJan Wielemaker
Wed Mar 18 16:36:32 2015 +0100
committerJan Wielemaker
Wed Mar 18 16:36:32 2015 +0100
commit8fd550eb10460488036fa2d2ac404accd1185d8b
treeb25117e5b4613af2a7cc52f4e9a8816a53715d4b
parentee846a3244316787694745df3a95a28d9b48398f
Diff style: patch stat
diff --git a/lib/swish/include.pl b/lib/swish/include.pl
index fab6275..c6a0d8c 100644
--- a/lib/swish/include.pl
+++ b/lib/swish/include.pl
@@ -45,17 +45,27 @@ shared gitty store. It realises this using the following steps:
   - Declare this specific version of include safe.
   - Adjust the colourization to indicate the shared file as existing.
   - Hook the Prolog cross-referencer to process the included file.
+
+We allow for hierarchical and circular includes.
 */
 
 
-swish:term_expansion(:- include(File),
-		     :- include(stream(Id, Stream, [close(true)]))) :-
-	setting(web_storage:directory, Store),
-	atomic(File),
-	add_extension(File, FileExt),
-	catch(gitty_data(Store, FileExt, Data, _Meta), _, fail),
-	atom_concat('swish://', FileExt, Id),
-	open_string(Data, Stream).
+swish:term_expansion(:- include(FileIn), Expansion) :-
+	atomic(FileIn),
+	atom_string(File, FileIn),
+	(   prolog_load_context(module, Module),
+	    clause(Module:'swish included'(File), true)
+	->  Expansion = []
+	;   Expansion = [ (:- discontiguous('swish included'/1)),
+		          'swish included'(File),
+		          (:- include(stream(Id, Stream, [close(true)])))
+			],
+	    setting(web_storage:directory, Store),
+	    add_extension(File, FileExt),
+	    catch(gitty_data(Store, FileExt, Data, _Meta), _, fail),
+	    atom_concat('swish://', FileExt, Id),
+	    open_string(Data, Stream)
+	).
 
 add_extension(File, FileExt) :-
 	file_name_extension(_, Ext, File),