mirror.dongdigua.github.io/monthly-tag.exs
dongdigua a197bcb9c7 monthly tag script, clean collection
mv
- shakaianee -> `B'
- xxt, mrxn  -> `other'
- iceguye    -> `yt'
add:
- null program
- Project Nayuki
- JARGON FILE
- asmtutor.com & int80h.org
- zhihu: uboomtu
rm:
- fediverse wiki
- bzhang
- 小耸
- scincart
- some sub-article
2022-12-20 22:19:59 +08:00

61 lines
1.3 KiB
Elixir
Executable File

#! /usr/bin/elixir
# this is a simple script to monthly tagging git
# for I always rewrite the history and tags will be missing
# use elixir is, fun and elegant
defmodule GitMonthlyTag do
def main do
get_log()
|> parse_date()
|> IO.inspect()
|> sort_by_m()
|> Enum.map(&gen_tag_cmd(&1))
#|> Enum.each(&IO.puts(&1))
|> Enum.each(&System.shell(&1) |> IO.inspect())
end
def get_log do
{log, 0} =
System.cmd("git", ["log", "--reverse", "--pretty='%as %h'"])
log
|> String.trim()
|> String.replace(~r/['-]/, "")
|> String.split("\n")
|> Enum.map(&String.split(&1, " "))
|> Enum.map(&List.to_tuple(&1))
end
def parse_date(data) do
data
|> Enum.map(fn {date, hash} ->
{String.to_integer(date), hash} end)
end
def sort_by_m(data) do
psort(data, 19700101, [])
end
defp psort([], _, acc), do: acc
defp psort([{hd, hash} | tl], prev, acc) do
cond do
hash==prev ->
psort(tl(tl), hd, acc)
Enum.any?(prev..hd, fn x -> rem(x, 100) == 0 end) ->
psort(tl, hd, [{hd, hash} | acc])
true ->
psort(tl, hd, acc)
end
end
def gen_tag_cmd({date_n, hash}) do
ym = div(date_n, 100)
y = rem(div(ym, 100), 100)
m = rem(ym, 100)
"git tag #{y}.#{m} #{hash}"
end
end
GitMonthlyTag.main()