versioned_graph/commit

misc cleanup

authorJacco van Ossenbruggen
Tue Jul 24 17:42:33 2012 +0200
committerJacco van Ossenbruggen
Tue Jul 24 17:42:33 2012 +0200
commit98eeb0d27a04ddf707ee7b9545851c33d28fbbd5
tree22ed5b6d13050f946851f4e3c77017dfeea9ef34
parent1a3d844248c8b94d02af5785fe7676d6237bc614
Diff style: patch stat
diff --git a/lib/graph_version.pl b/lib/graph_version.pl
index 3f6a187..25aca01 100644
--- a/lib/graph_version.pl
+++ b/lib/graph_version.pl
@@ -43,6 +43,27 @@
 :- listen(settings(changed(graph_version:_Setting, _Old, _New)),
 	  gv_init).
 
+%%	gv_hash_uri(+Hash, -URI) is det.
+%
+%	URI is a uri constructed by concatenating the
+%	Hash with some additional prefix to make it a
+%	legal URI.
+%
+%	This provides a basic one to one mapping between
+%       git's SHA1 hash ids and the URIs used in RDF.
+
+gv_hash_uri(Hash, URI) :-
+	nonvar(Hash), Hash \= null,
+	!,
+	atom_concat(x, Hash, Local),
+	rdf_global_id(hash:Local, URI).
+
+gv_hash_uri(Hash, URI) :-
+	nonvar(URI),!,
+	rdf_global_id(hash:Local, URI),
+	atom_concat(x, Hash, Local).
+
+
 %%	git_init is det.
 %
 %       Initialise the RDF and/or GIT version repositories.
@@ -177,7 +198,9 @@ gv_branch_head(Branch, Commit) :-
 
 gv_branch_head(Branch, Commit) :-
 	\+ setting(gv_refs_store, rdf_only),
-	gv_branch_head_git(Branch, Commit).
+	rdf_global_id(localgit:Ref, Branch),
+	gv_branch_head_git(Ref, Hash),
+	gv_hash_uri(Hash, Commit).
 
 %%	gv_head(+Commit) is det.
 %
@@ -207,7 +230,9 @@ gv_move_head_(NewHead) :-
 	;   true
 	),
 	(   (StoreMode == git_only ; StoreMode == both)
-	->  gv_move_head_git(Branch, NewHead)
+	->  gv_hash_uri(Hash, NewHead),
+	    rdf_global_id(localgit:Local, Branch),
+	    gv_move_head_git(Local, Hash)
 	;   true
 	).
 
diff --git a/lib/gv_git_io.pl b/lib/gv_git_io.pl
index 6aba105..fa62931 100644
--- a/lib/gv_git_io.pl
+++ b/lib/gv_git_io.pl
@@ -1,6 +1,5 @@
 :- module(gv_git_io,
 	 [
-	  gv_hash_uri/2,
 	  gv_init_git/0,
 	  gv_current_branch_git/1,
 	  gv_commit_property_git/2,
@@ -11,27 +10,6 @@
 :- use_module(library(git)).
 :- use_module(parse_git_objects).
 
-:- use_module(library(semweb/rdf_db)).  % this should not be necessary ...
-
-%%	gv_hash_uri(+Hash, -URI) is det.
-%
-%	URI is a uri constructed by concatenating the
-%	Hash with some additional prefix to make it a
-%	legal URI.
-%
-%	This provides a basic one to one mapping between git's SHA1 hash
-%	ids and the URIs used in RDF.
-
-gv_hash_uri(Hash, URI) :-
-	nonvar(Hash), Hash \= null,
-	!,
-	atom_concat(x, Hash, Local),
-	rdf_global_id(hash:Local, URI).
-
-gv_hash_uri(Hash, URI) :-
-	nonvar(URI),!,
-	rdf_global_id(hash:Local, URI),
-	atom_concat(x, Hash, Local).
 
 gv_init_git :-
 	setting(graph_version:gv_git_dir, Dir),
@@ -49,7 +27,7 @@ gv_init_git :-
 
 gv_current_branch_git(Ref) :-
 	setting(graph_version:gv_git_dir, Dir),
-	git(['symbolic-ref', 'HEAD'],[directory(Dir), output(OutCodes)]),!,
+	catch(git(['symbolic-ref', 'HEAD'],[directory(Dir), output(OutCodes)]), _, fail),!,
 	atom_codes(RefNL, OutCodes),
 	sub_atom(RefNL, 0, _, 1, Ref).
 
@@ -69,18 +47,14 @@ gv_commit_property_git(CommitHash, Prop) :-
 	    option(Prop, C)
 	).
 
-gv_branch_head_git(Branch, Commit) :-
+gv_branch_head_git(Ref, Hash) :-
 	setting(graph_version:gv_git_dir, Dir),
-	rdf_global_id(localgit:Ref, Branch),
 	catch(git(['show-ref', '--hash', Ref],
 		  [output(Codes), directory(Dir)]), _, fail),
 	atom_codes(Atom, Codes),  % hash with newline
-	sub_atom(Atom, 0, 40 ,1, Hash),
-	gv_hash_uri(Hash, Commit).
+	sub_atom(Atom, 0, 40 ,1, Hash).
 
-gv_move_head_git(Branch, NewHead) :-
+gv_move_head_git(Ref, Hash) :-
 	setting(graph_version:gv_git_dir, Dir),
-	gv_hash_uri(Hash, NewHead),
-	rdf_global_id(localgit:Local, Branch),
-	git(['update-ref', Local, Hash],[directory(Dir)]).
+	catch(git(['update-ref', Ref, Hash],[directory(Dir)]), _, fail).
 
diff --git a/lib/parse_git_objects.pl b/lib/parse_git_objects.pl
index a169edd..e499178 100644
--- a/lib/parse_git_objects.pl
+++ b/lib/parse_git_objects.pl
@@ -42,7 +42,7 @@ author(Name,Email,Date) -->
 	name(NameC),
 	[32, 60], author_email(EmailC), [62, 32],
 	author_date(DateC,_ZoneC),
-	[10],
+	[10],!,
 	{
 	 atom_codes(Name, NameC),
 	 atom_codes(Email, EmailC),
@@ -133,7 +133,7 @@ xdigit(E) -->
 
 
 tree([H|T]) -->
-	blobline(H),
+	blobline(H),!,
 	tree(T).
 tree([]) --> [].