From 5d3a5a100a597597f8d6071f314af098cf00022e Mon Sep 17 00:00:00 2001 From: Jesper Eskilson Date: Mon, 4 Jan 2021 09:55:26 +0100 Subject: [PATCH 1/2] Use "git rev-list --count" to count refs By using the --count option to "git rev-list", we avoid having to actually produce the list of commits, splitting it, and counting the lines. --- src/rebar_git_resource.erl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index d95fd597..008a0129 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -306,11 +306,11 @@ collect_default_refcount(Dir) -> case Tag of undefined -> AbortMsg2 = "Getting rev-list of git dependency failed in " ++ Dir, - {ok, PatchLines} = rebar_utils:sh("git rev-list HEAD", + {ok, PatchLines} = rebar_utils:sh("git rev-list --count HEAD", [{use_stdout, false}, {cd, Dir}, {debug_abort_on_error, AbortMsg2}]), - rebar_utils:line_count(PatchLines); + {ok, list_to_integer(string:trim(PatchLines))}; _ -> get_patch_count(Dir, Tag) end, @@ -333,13 +333,13 @@ build_vsn_string(Vsn, RawRef, Count) -> get_patch_count(Dir, RawRef) -> AbortMsg = "Getting rev-list of git dep failed in " ++ Dir, Ref = re:replace(RawRef, "\\s", "", [global, unicode]), - Cmd = io_lib:format("git rev-list ~ts..HEAD", + Cmd = io_lib:format("git rev-list --count ~ts..HEAD", [rebar_utils:escape_chars(Ref)]), {ok, PatchLines} = rebar_utils:sh(Cmd, [{use_stdout, false}, {cd, Dir}, {debug_abort_on_error, AbortMsg}]), - rebar_utils:line_count(PatchLines). + {ok, list_to_integer(string:trim(PatchLines))}. parse_tags(Dir) -> From 38aec3fb9d2b3c9b054d98411b34f3fc972fa7f3 Mon Sep 17 00:00:00 2001 From: Jesper Eskilson Date: Thu, 7 Jan 2021 08:31:21 +0100 Subject: [PATCH 2/2] Use rebar_string:trim/1 for OTP 19 compatibility --- src/rebar_git_resource.erl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index 008a0129..52c6c85f 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -310,7 +310,7 @@ collect_default_refcount(Dir) -> [{use_stdout, false}, {cd, Dir}, {debug_abort_on_error, AbortMsg2}]), - {ok, list_to_integer(string:trim(PatchLines))}; + {ok, list_to_integer(rebar_string:trim(PatchLines))}; _ -> get_patch_count(Dir, Tag) end, @@ -339,7 +339,7 @@ get_patch_count(Dir, RawRef) -> [{use_stdout, false}, {cd, Dir}, {debug_abort_on_error, AbortMsg}]), - {ok, list_to_integer(string:trim(PatchLines))}. + {ok, list_to_integer(rebar_string:trim(PatchLines))}. parse_tags(Dir) ->