<commit_before>-module(rebar_prv_deps_tree).

-behaviour(provider).

-export([init/1,
         do/1,
         format_error/1]).

-include("rebar.hrl").

-define(PROVIDER, tree).
-define(DEPS, [lock]).

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
    State1 = rebar_state:add_provider(
               State,
               providers:create([{name, ?PROVIDER},
                                 {module, ?MODULE},
                                 {bare, true},
                                 {deps, ?DEPS},
                                 {example, "rebar3 tree"},
                                 {short_desc, "Print dependency tree."},
                                 {desc, ""},
                                 {opts, [{verbose, $v, "verbose", undefined, "Print repo and branch/tag/ref for git and hg deps"}]}])),
    {ok, State1}.

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
    {Args, _} = rebar_state:command_parsed_args(State),
    Verbose = proplists:get_value(verbose, Args, false),
    print_deps_tree(rebar_state:all_deps(State), Verbose, State),
    {ok, State}.

-spec format_error(any()) -> iolist().
format_error(Reason) ->
    io_lib:format("~p", [Reason]).

%% Internal functions

print_deps_tree(SrcDeps, Verbose, State) ->
    D = lists:foldl(fun(App, Dict) ->
                            Name = rebar_app_info:name(App),
                            Vsn = rebar_app_info:original_vsn(App),
                            Source  = rebar_app_info:source(App),
                            Parent = rebar_app_info:parent(App),
                            dict:append_list(Parent, [{Name, Vsn, Source}], Dict)
                    end, dict:new(), SrcDeps),
    ProjectAppNames = [{rebar_app_info:name(App)
                       ,rebar_app_info:original_vsn(App)
                       ,project} || App <- rebar_state:project_apps(State)],
    case dict:find(root, D) of
        {ok, Children} ->
            print_children("", lists:keysort(1, Children++ProjectAppNames), D, Verbose);
        error ->
            print_children("", lists:keysort(1, ProjectAppNames), D, Verbose)
    end.

print_children(_, [], _, _) ->
    ok;
print_children(Prefix, [{Name, Vsn, Source} | Rest], Dict, Verbose) ->
    Prefix1 = case Rest of
        [] ->
            io:format("~s`- ", [Prefix]),
            [Prefix, "   "];
        _ ->
            io:format("~s|- ", [Prefix]),
            [Prefix, "|  "]
    end,
    io:format("~s-~s (~s)~n", [Name, Vsn, type(Source, Verbose)]),
    case dict:find(Name, Dict) of
        {ok, Children} ->
            print_children(Prefix1, lists:keysort(1, Children), Dict, Verbose),
            print_children(Prefix, Rest, Dict, Verbose);
        error ->
            print_children(Prefix, Rest, Dict, Verbose)
    end.

type(project, _) ->
    "project app";
type(Source, Verbose) when is_tuple(Source) ->
    case {element(1, Source), Verbose} of
        {pkg, _} ->
            "hex package";
        {Other, false} ->
            io_lib:format("~s repo", [Other]);
        {_, true} ->
            io_lib:format("~s", [element(2, Source)])
    end.<commit_msg>utf8 tree<commit_after>-module(rebar_prv_deps_tree).

-behaviour(provider).

-export([init/1,
         do/1,
         format_error/1]).

-include("rebar.hrl").

-define(PROVIDER, tree).
-define(DEPS, [lock]).

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
    State1 = rebar_state:add_provider(
               State,
               providers:create([{name, ?PROVIDER},
                                 {module, ?MODULE},
                                 {bare, true},
                                 {deps, ?DEPS},
                                 {example, "rebar3 tree"},
                                 {short_desc, "Print dependency tree."},
                                 {desc, ""},
                                 {opts, [{verbose, $v, "verbose", undefined, "Print repo and branch/tag/ref for git and hg deps"}]}])),
    {ok, State1}.

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
    {Args, _} = rebar_state:command_parsed_args(State),
    Verbose = proplists:get_value(verbose, Args, false),
    print_deps_tree(rebar_state:all_deps(State), Verbose, State),
    {ok, State}.

-spec format_error(any()) -> iolist().
format_error(Reason) ->
    io_lib:format("~p", [Reason]).

%% Internal functions

print_deps_tree(SrcDeps, Verbose, State) ->
    D = lists:foldl(fun(App, Dict) ->
                            Name = rebar_app_info:name(App),
                            Vsn = rebar_app_info:original_vsn(App),
                            Source  = rebar_app_info:source(App),
                            Parent = rebar_app_info:parent(App),
                            dict:append_list(Parent, [{Name, Vsn, Source}], Dict)
                    end, dict:new(), SrcDeps),
    ProjectAppNames = [{rebar_app_info:name(App)
                       ,rebar_app_info:original_vsn(App)
                       ,project} || App <- rebar_state:project_apps(State)],
    io:setopts([{encoding, unicode}]),
    case dict:find(root, D) of
        {ok, Children} ->
            print_children("", lists:keysort(1, Children++ProjectAppNames), D, Verbose);
        error ->
            print_children("", lists:keysort(1, ProjectAppNames), D, Verbose)
    end.

print_children(_, [], _, _) ->
    ok;
print_children(Prefix, [{Name, Vsn, Source} | Rest], Dict, Verbose) ->
    Prefix1 = case Rest of
                  [] ->
                      io:format("~s└─ ", [Prefix]),
                      [Prefix, "   "];
                  _ ->
                      io:format("~s├─ ", [Prefix]),
                      [Prefix, "│  "]
              end,
    io:format("~s─~s (~s)~n", [Name, Vsn, type(Source, Verbose)]),
    case dict:find(Name, Dict) of
        {ok, Children} ->
            print_children(Prefix1, lists:keysort(1, Children), Dict, Verbose),
            print_children(Prefix, Rest, Dict, Verbose);
        error ->
            print_children(Prefix, Rest, Dict, Verbose)
    end.

type(project, _) ->
    "project app";
type(Source, Verbose) when is_tuple(Source) ->
    case {element(1, Source), Verbose} of
        {pkg, _} ->
            "hex package";
        {Other, false} ->
            io_lib:format("~s repo", [Other]);
        {_, true} ->
            io_lib:format("~s", [element(2, Source)])
    end.
{'fraction_non_alphanumeric': 0.15719374322440763, 'fraction_numerical': 0.004181508440452222, 'mean_word_length': 1.8461877479065667, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7029964', 'n_tokens_mistral': 2092, 'n_tokens_neox': 2070, 'n_words': 391}