<commit_before>-module(rebar_prv_lock).

-behaviour(provider).

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

-include("rebar.hrl").

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

%% ===================================================================
%% Public API
%% ===================================================================

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
    State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
                                                               {module, ?MODULE},
                                                               {bare, false},
                                                               {deps, ?DEPS},
                                                               {example, ""},
                                                               {short_desc, "Locks dependencies."},
                                                               {desc, "Locks dependencies"},
                                                               {opts, []}])),
    {ok, State1}.

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
    OldLocks = rebar_state:get(State, {locks, default}, []),
    Locks = lists:keysort(1, build_locks(State)),
    Dir = rebar_state:dir(State),
    file:write_file(filename:join(Dir, ?LOCK_FILE),
                    io_lib:format("~p.~n", [Locks])),
    State1 = rebar_state:set(State, {locks, default}, Locks),

    OldLockNames = [element(1,L) || L <- OldLocks],
    NewLockNames = [element(1,L) || L <- Locks],
    rebar_utils:info_useless(OldLockNames, NewLockNames),

    {ok, State1}.

-spec format_error(any()) -> iolist().
format_error(Reason) -><commit_msg>only lock when running in the default profile<commit_after>-module(rebar_prv_lock).

-behaviour(provider).

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

-include("rebar.hrl").

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

%% ===================================================================
%% Public API
%% ===================================================================

-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
    State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
                                                               {module, ?MODULE},
                                                               {bare, false},
                                                               {deps, ?DEPS},
                                                               {example, ""},
                                                               {short_desc, "Locks dependencies."},
                                                               {desc, "Locks dependencies"},
                                                               {opts, []}])),
    {ok, State1}.

-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
    %% Only lock default profile run
    case rebar_state:current_profiles(State) of
        [default] ->
            OldLocks = rebar_state:get(State, {locks, default}, []),
            Locks = lists:keysort(1, build_locks(State)),
            Dir = rebar_state:dir(State),
            file:write_file(filename:join(Dir, ?LOCK_FILE),
                            io_lib:format("~p.~n", [Locks])),
            State1 = rebar_state:set(State, {locks, default}, Locks),

            OldLockNames = [element(1,L) || L <- OldLocks],
            NewLockNames = [element(1,L) || L <- Locks],
            rebar_utils:info_useless(OldLockNames, NewLockNames),

            {ok, State1};
        _ ->
            {ok, State}
    end.

-spec format_error(any()) -> iolist().
format_error(Reason) ->
{'fraction_non_alphanumeric': 0.20572779821334736, 'fraction_numerical': 0.005254860746190226, 'mean_word_length': 1.5619111709286675, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6502625', 'n_tokens_mistral': 1012, 'n_tokens_neox': 977, 'n_words': 175}