-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeta_forks.escript
executable file
·76 lines (67 loc) · 2.32 KB
/
meta_forks.escript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env escript
%%! -Wall -pz _build/default/lib/erldocs_other/ebin/ -pz _build/default/lib/erldocs/ebin/ -pz _build/default/lib/erlydtl/ebin/ -sname meta_forks
%% Copyright © 2015 Pierre Fenoll ‹[email protected]›
%% See LICENSE for licensing information.
%% -*- coding: utf-8 -*-
%% forks: try to find a repo's forks
-include("include/erldocs_other.hrl").
-mode(compile).
%% API
main ([Dir]) ->
F = fun (Meta, Count) ->
UUID = eo_meta:target_path(Meta),
Cos = [Rev#rev.commit || Rev <- eo_meta:revisions(Meta)],
lists:foreach(fun (Co) ->
append(Co, UUID)
end, Cos),
Count + 1
end,
CountRepos = eo_meta:fold(Dir, F, 0),
io:format(standard_error, "# repos: ~p\n", [CountRepos]),
G = fun ({Co, Ids}) ->
erase(Co),
A = fun (Id) ->
append(Id, gb_sets:delete_any(Id, Ids))
end,
lists:foreach(A, gb_sets:to_list(Ids))
end,
lists:foreach(G, get()),
H = fun ({Id, Similar0}, Count) ->
erase(Id),
Similar = gb_sets:to_list(Similar0),
io:format(standard_error, "~s\t~p\n\t~p\n", [Id, gb_sets:size(Similar0), Similar]),
case Similar of
[] -> Count;
_ -> Count + 1
end
end,
CountForks = lists:foldl(H, 0, get()),
%% #projects sharing >0 commits
io:format("~p\n", [CountForks]);
main (_) ->
usage().
%% Internals
append(Key, Value) ->
case get(Key) of
undefined ->
case Value of
[_Char|_] when is_integer(_Char) ->
put(Key, gb_sets:from_list([Value]));
_ ->
put(Key, Value)
end;
S ->
case Value of
[_Char|_] when is_integer(_Char) ->
put(Key, gb_sets:add(Value, S));
_ ->
put(Key, gb_sets:union(Value, S))
end
end.
usage () ->
ok = io:setopts([{encoding, unicode}]),
Arg0 = escript:script_name(),
io:format("Usage: ~s ‹other.erldocs.com's dir›\n",
[filename:basename(Arg0)]),
halt(1).
%% End of Module.