Permalink
Browse files

updated subversion server with blakes changes

  • Loading branch information...
1 parent 06f1e1a commit 809f4345b7f6ab584d2050e55299795bafed706f @schacon committed Aug 22, 2008
Showing with 68 additions and 0 deletions.
  1. +1 −0 README
  2. +67 −0 src/subversion_import.erl
View
1 README
@@ -40,4 +40,5 @@ ToDo
Authors
======================
+* Blake Mizerany <blake.mizerany@gmail.com>
* Scott Chacon <schacon@gmail.com>
View
@@ -39,3 +39,70 @@ handle_info({nodedown, Node, Reason}, State) ->
terminate(_Reason, _State) -> ok.
code_change(_OldVsn, State, _Extra) -> {ok, State}.
+
+%%--------------------------------------------------------------------
+%%% Internal functions
+%%--------------------------------------------------------------------
+
+get_revisions(Url) ->
+ Info = cmd("svn info " ++ Url, "."),
+ case regexp:match(Info, "Revision: [0-9]+") of
+ {match, Start, Length} ->
+ case regexp:match(R = string:substr(Info, Start, Length), "[0-9]+") of
+ {match, Start1, Length1} ->
+ {Int, _} = string:to_integer(string:substr(R, Start1, Length1)),
+ {ok, Int};
+ _ ->
+ {error, no_info}
+ end;
+ _ ->
+ {error, no_info}
+ end.
+
+import_repo(Url) ->
+ Ref = make_ref(),
+ RefL = erlang:ref_to_list(Ref),
+ io:format("~p~n", [RefL]),
+ io:format("~p~n", [Url]),
+ case get_revisions(Url) of
+ {ok, Revisions} ->
+ go(Url, RefL, Revisions);
+ _ ->
+ error_logger:error_msg("Unable to get info for ~s", [Url])
+ end.
+
+go(Url, Ref, Revisions) ->
+ cmd("mkdir '" ++ Ref ++ "'", "."),
+ cmd("git init", Ref),
+ cmd("echo '.svn' > .gitignore", Ref),
+ cmd("git add .; git commit -m \"init with .gitignore\"", Ref),
+ checkout(Url, Ref, Revisions).
+
+checkout(Url, Ref, Revisions) ->
+ checkout(Url, Ref, 1, Revisions).
+
+checkout(Url, Ref, N, Revisions) ->
+ Out = cmd("svn co ~s -r ~b .", [Url, N], Ref),
+ io:format("~p~n", [Out]),
+ case regexp:match(Out, "svn: Unable") of
+ {match, _} ->
+ io:format("Unable to start at r~b", [N]),
+ checkout(Url, Ref, N+1, Revisions);
+ _ ->
+ update(Ref, N+1, Revisions)
+ end.
+
+update(_Ref, N, Revisions) when N > Revisions ->
+ ok;
+update(Ref, N, Revisions) ->
+ io:format("~~ updating ~b of ~b~n", [N, Revisions]),
+ cmd("svn update -r~b", [N], Ref),
+ cmd("git add .; git commit -m 'r~b'", [N], Ref),
+ update(Ref, N+1, Revisions).
+
+
+cmd(Cmd, Data, Dir) ->
+ cmd(io_lib:format(Cmd, Data), Dir).
+
+cmd(Cmd, Dir) ->
+ os:cmd("cd '" ++ Dir ++ "'; " ++ Cmd).

0 comments on commit 809f434

Please sign in to comment.