Skip to content

Instantly share code, notes, and snippets.

Created December 9, 2014 00:20
Show Gist options
  • Save anonymous/c40629a04d5a2ef1c3be to your computer and use it in GitHub Desktop.
Save anonymous/c40629a04d5a2ef1c3be to your computer and use it in GitHub Desktop.
subtree scripts for CouchDB
#!/usr/bin/env escript
-mode(compile).
-export([main/1]).
main(_) ->
Mode = subtree_mode(),
Repos = read_repos(),
ok = filelib:ensure_dir(apps_path()),
[merge(Repo, Mode) || Repo <- Repos].
subtree_mode() ->
case filelib:is_dir(apps_path()) of
true -> pull;
false -> add
end.
read_repos() ->
{ok, [{repos, Repos}]} = file:consult(filename:join("support", "repos.config")),
Repos.
merge({Dir, Suffix, Ref}, add) ->
io:format("Adding ~s (~s)~n", [Dir, Ref]),
Path = app_path(Dir),
Remote = "https://git-wip-us.apache.org/repos/asf/couchdb-" ++ Suffix ++ ".git",
RemoteName = "subtree-" ++ Suffix,
cmd("git remote add -f " ++ RemoteName ++ " " ++ Remote),
cmd("git fetch " ++ RemoteName),
cmd(
"git subtree add" ++
" --prefix=" ++ Path ++
" " ++ RemoteName ++ " " ++ Ref);
merge({Dir, Suffix, Ref}, pull) ->
Path = app_path(Dir),
RemoteName = "subtree-" ++ Suffix,
cmd("git fetch " ++ RemoteName),
cmd(
"git subtree pull" ++
" --prefix " ++ Path ++
" " ++ RemoteName ++ " " ++ Ref).
apps_path() ->
{ok, CWD} = file:get_cwd(),
filename:join(CWD, "apps") ++ "/".
app_path(Dir) ->
filename:join("apps", atom_to_list(Dir)).
cmd(Command) ->
io:format(Command),
io:format("~n~s", [os:cmd(Command)]).
{repos, [
{b64url, "b64url", "master"},
{cassim, "cassim", "master"},
{chttpd, "chttpd", "master"},
{config, "config", "master"},
{couch, "couch", "master"},
{couch_dbupdates, "couch-dbupdates", "master"},
{couch_event, "couch-event", "master"},
{couch_index, "couch-index", "master"},
{couch_log, "couch-log", "master"},
{couch_mrview, "couch-mrview", "master"},
{couch_plugins, "couch-plugins", "master"},
{couch_replicator, "couch-replicator", "master"},
{couch_stats, "couch-stats", "master"},
{ddoc_cache, "ddoc-cache", "master"},
{docs, "documentation", "master"},
{ets_lru, "ets-lru", "master"},
{fabric, "fabric", "master"},
{fauxton, "fauxton", "master"},
{folsom, "folsom", "master"},
{global_changes, "global-changes", "master"},
{goldrush, "goldrush", "0.1.6"},
{ibrowse, "ibrowse", "master"},
{ioq, "ioq", "master"},
{jiffy, "jiffy", "master"},
{khash, "khash", "master"},
{mem3, "mem3", "master"},
{mochiweb, "mochiweb", "master"},
{oauth, "oauth", "master"},
{rexi, "rexi", "master"},
{snappy, "snappy", "master"}
]}.
#!/usr/bin/env escript
-mode(compile).
-export([main/1]).
main(_) ->
Repos = read_repos(),
[split(Repo) || Repo <- Repos].
read_repos() ->
{ok, [{repos, Repos}]} = file:consult(filename:join("support", "repos.config")),
Repos.
split({Dir, Suffix, Ref = "master"}) ->
io:format("Pusing ~p@~s~n", [Dir, Ref]),
Path = app_path(Dir),
Remote = "https://github.com/strmpnk/couchdb-" ++ Suffix,
RemoteName = "subtree-target-" ++ Suffix,
cmd("git remote add -f " ++ RemoteName ++ " " ++ Remote),
cmd(
"git subtree push" ++
" --prefix=" ++ Path ++
" " ++ RemoteName ++ " " ++ Ref);
split({Dir, _Suffix, Ref}) ->
io:format("Skipping ~p@~s~n", [Dir, Ref]).
app_path(Dir) ->
filename:join("apps", atom_to_list(Dir)).
cmd(Command) ->
io:format(Command),
io:format("~n~s", [os:cmd(Command)]).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment