Merge pull request #83 from joedevivo/master
Made version prefix configurable in ec_git_vsn
This commit is contained in:
commit
e56c73c940
2 changed files with 14 additions and 11 deletions
|
@ -83,7 +83,7 @@ the `lists` module in stdlib.
|
||||||
|
|
||||||
### [ec_talk](https://github.com/erlware/erlware_commons/blob/master/src/ec_talk.erl)
|
### [ec_talk](https://github.com/erlware/erlware_commons/blob/master/src/ec_talk.erl)
|
||||||
|
|
||||||
A set of simple utility functions to falicitate command line
|
A set of simple utility functions to facilitate command line
|
||||||
communication with a user.
|
communication with a user.
|
||||||
|
|
||||||
Signatures
|
Signatures
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%% This should be opaque, but that kills dialyzer so for now we export it
|
%% This should be opaque, but that kills dialyzer so for now we export it
|
||||||
%% however you should not rely on the internal representation here
|
%% however you should not rely on the internal representation here
|
||||||
-type t() :: {}.
|
-type t() :: {string()}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% API
|
%%% API
|
||||||
|
@ -32,23 +32,23 @@
|
||||||
|
|
||||||
-spec new() -> t().
|
-spec new() -> t().
|
||||||
new() ->
|
new() ->
|
||||||
{}.
|
{"v"}.
|
||||||
|
|
||||||
-spec vsn(t()) -> {ok, string()} | {error, Reason::any()}.
|
-spec vsn(t()) -> {ok, string()} | {error, Reason::any()}.
|
||||||
vsn(_Data) ->
|
vsn(Data) ->
|
||||||
{Vsn, RawRef, RawCount} = collect_default_refcount(),
|
{Vsn, RawRef, RawCount} = collect_default_refcount(Data),
|
||||||
{ok, build_vsn_string(Vsn, RawRef, RawCount)}.
|
{ok, build_vsn_string(Vsn, RawRef, RawCount)}.
|
||||||
|
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
%%% Internal Functions
|
%%% Internal Functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
collect_default_refcount() ->
|
collect_default_refcount(Data) ->
|
||||||
%% Get the tag timestamp and minimal ref from the system. The
|
%% Get the tag timestamp and minimal ref from the system. The
|
||||||
%% timestamp is really important from an ordering perspective.
|
%% timestamp is really important from an ordering perspective.
|
||||||
RawRef = os:cmd("git log -n 1 --pretty=format:'%h\n' "),
|
RawRef = os:cmd("git log -n 1 --pretty=format:'%h\n' "),
|
||||||
|
|
||||||
{Tag, TagVsn} = parse_tags(),
|
{Tag, TagVsn} = parse_tags(Data),
|
||||||
RawCount =
|
RawCount =
|
||||||
case Tag of
|
case Tag of
|
||||||
undefined ->
|
undefined ->
|
||||||
|
@ -84,11 +84,14 @@ get_patch_count(RawRef) ->
|
||||||
[Ref]),
|
[Ref]),
|
||||||
os:cmd(Cmd).
|
os:cmd(Cmd).
|
||||||
|
|
||||||
parse_tags() ->
|
-spec parse_tags(t()) -> {string()|undefined, ec_semver:version_string()}.
|
||||||
first_valid_tag(os:cmd("git log --oneline --decorate | fgrep \"tag: \" -1000")).
|
parse_tags({Prefix}) ->
|
||||||
|
first_valid_tag(os:cmd("git log --oneline --decorate | fgrep \"tag: \" -1000"), Prefix).
|
||||||
|
|
||||||
first_valid_tag(Line) ->
|
-spec first_valid_tag(string(), string()) -> {string()|undefined, ec_semver:version_string()}.
|
||||||
case re:run(Line, "(\\(|\\s)tag:\\s(v([^,\\)]+))", [{capture, [2, 3], list}]) of
|
first_valid_tag(Line, Prefix) ->
|
||||||
|
RE = lists:flatten(io_lib:format("(\\(|\\s)tag:\\s(~s([^,\\)]+))", [Prefix])),
|
||||||
|
case re:run(Line, RE, [{capture, [2, 3], list}]) of
|
||||||
{match,[Tag, Vsn]} ->
|
{match,[Tag, Vsn]} ->
|
||||||
{Tag, Vsn};
|
{Tag, Vsn};
|
||||||
nomatch ->
|
nomatch ->
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue