Commits

Andreas Stenius  committed 2eac9f0

Repo log works for mercurial repositories.

  • Participants
  • Parent commits c0945f1

Comments (0)

Files changed (5)

File actions/action_zmr_clone_repo.erl

 
 
 clone_repo(TargetId, RepoId, Context) ->
-    Context1 = update_progress(TargetId, [{message, "Cloning repository..."}], Context),
     Source = mod_zmr:repo_source(RepoId, Context),
     Target = mod_zmr:repo_path(RepoId, Context),
     Cmd = mod_zmr:get_cmd(RepoId, Context, 
 			   {"\\$source", Source}, 
 			   {"\\$target", Target}
 			  ]),
+    Context1 = update_progress(TargetId, [{message, "Cloning repository..."}], Context),
     Result = os:cmd(Cmd),
     ?PRINT(Result),
     Message = lists:flatten(["Clone Repository Done. <br /><pre>", Result, "</pre>"]),
 		 clone -> zmr_arg_clone;
 		 log -> zmr_arg_log
 	     end,
-    ToolId = m_edge:object(RepoId, zmr_scm, 1, Context),
-    Op = m_rsc:p(ToolId, OpProp, Context),
+    ToolId = m_edge:object(RepoId, zmr_repo_scm, 1, Context),
+    OpVal = z_convert:to_list(m_rsc:p(ToolId, OpProp, Context)),
     Args = lists:foldl(fun({From, To}, Arg) -> re:replace(Arg, From, To, [{return, list}]) end,
-		       Op,
+		       OpVal,
 		       Vars),
     Exe = z_convert:to_list(m_rsc:p(ToolId, zmr_command, Context)),
     Cmd = lists:flatten([Exe, " ", Args]),
-    ?PRINT(Cmd),
+    %?PRINT(Cmd),
     Cmd.
 
     

File models/m_zmr.erl

 
 -include_lib("zotonic.hrl").
 
+
 m_find_value(repo, #m{value=undefined} = M, _Context) ->
     M#m{value=repo};
 m_find_value(Id, #m{value=repo} = M, Context) ->
 	    end
     end;
 
-m_find_value(log, #m{value={repo, Id}}=M, _Context) ->
-    M#m{value={repo_log, ["example data", "should retreive this", "from the source repo", "in a suitable format"]}};
+m_find_value(log, #m{value={repo, Id}}=M, Context) ->
+    M#m{value={repo_log, get_repo_log(Id, Context)}};
 
 m_find_value(exist, #m{value={repo, Id}}, Context) ->
-    filelib:is_dir(mod_zmr:repo_path(Id, Context)).
+    filelib:is_dir(mod_zmr:repo_path(Id, Context));
 
+m_find_value(Key, #m{value={repo_log_entry, Entry}}, _Context) ->
+    %?PRINT(Key),
+    %?PRINT(Entry),
+    proplists:get_value(Key, Entry).
 
 
-m_to_list(#m{value={repo_log, Log}}, _Context) ->
-    Log;
+m_to_list(#m{value={repo_log, Log}}=M, _Context) ->
+    [M#m{value={repo_log_entry, Entry}} || Entry <- Log];
 
 m_to_list(_, _) ->
     undefined.
     Id.
 
 
+get_repo_log(Id, Context) -> 
+    Repo = mod_zmr:repo_path(Id, Context),
+    Cmd = lists:flatten(["cd ", Repo, " && ", mod_zmr:get_cmd(Id, Context, [log])]),
+    Output = os:cmd(Cmd),
+    %?PRINT(Output),
+    {match, Match} = re:run(Output, "(?m)^(\\w+):\\s*(.*)$|^$", [global, {capture, all_but_first, list}]),
+    match_to_proplist(Match).
 
+%%
+% Matches are reversed after this conversion. Use lists:reverse to restore, if needed
 
+match_to_proplist([]) -> [];
+match_to_proplist(Match) -> match_to_proplist(Match, [[]]).
+
+%keeps props in order, but less efficient
+%match_to_proplist([[Key, Value]|MatchList], [H|Acc]) -> match_to_proplist(MatchList, [H++[{Key, Value}]|Acc]);
+% props in reverse order
+match_to_proplist([[Key, Value]|MatchList], [H|Acc]) -> 
+    match_to_proplist(MatchList, 
+		      [
+		       [{z_convert:to_atom(string:to_lower(Key)), Value}|H]
+		       |Acc
+		      ]
+		     );
+
+match_to_proplist([[]], Acc) -> Acc;
+
+% could call lists:reverse here to restore prop order, if needed
+match_to_proplist([[]|MatchList], Acc) -> match_to_proplist(MatchList, [[]|Acc]);
+
+match_to_proplist([], Acc) -> Acc.
+    
+

File templates/_zmr_log_entry.tpl

-Log: <a id={{#entry}} href="javascript:void(0)">{{entry}}</a><br />
+{# until we got some proper css styles... it's a mess #}
+<hr />
+
 {% wire id=#entry
 	type="click" 
-	action={set_value target=target value=entry} 
+	action={set_value target=target value=entry.changeset} 
 	action={dialog_close} 
-%}
+%}
+<div id={{#entry}}>
+{% autoescape on %}
+	<b>Changeset:</b> {{entry.changeset}}{% if entry.tag %} ({{entry.tag}}){% endif %}<br />
+	<b>Date:</b> {{entry.date}}<br />
+	<b>User:</b> {{entry.user}}<br />
+	<b>Summary:</b> {{entry.summary}}<br />
+{% endautoescape %}
+</div>

File templates/_zmr_select_changeset.tpl

+<b>Click on a log entry to select it.</b>
+
 {% for entry in m.zmr.repo[repo].log %}
 	{% include "_zmr_log_entry.tpl" entry=entry target=target %}
 {% empty %}