Skip to content

Commit 4724861

Browse files
committed
Script for updating priv/funcs.txt
Generated from previous snippets: 6eda003 and 0b6d98b The FuncsDiffAnalyzer is perhaps not needed beyond this PR, where sorting is enforced, but it's nice to have. Signed-off-by: Peter M <[email protected]>
1 parent 19d9cd8 commit 4724861

File tree

5 files changed

+717
-235
lines changed

5 files changed

+717
-235
lines changed

analyze_funcs_diff.exs

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env elixir
2+
3+
defmodule FuncsDiffAnalyzer do
4+
@moduledoc """
5+
Analyzes git diff output for priv/funcs.txt to identify actual content changes.
6+
7+
This script distinguishes between functions that are genuinely added/removed
8+
versus functions that are simply reordered due to sorting changes.
9+
It provides a mathematical consistency check between git diff statistics
10+
and actual content changes.
11+
"""
12+
13+
@funcs_txt_path "priv/funcs.txt"
14+
def run do
15+
case System.cmd("git", ["diff", @funcs_txt_path], stderr_to_stdout: true) do
16+
{output, 0} when output != "" -> output |> parse_and_analyze() |> display_results()
17+
{_, 0} -> IO.puts("\nNo changes detected")
18+
{error, _} -> IO.puts("Error: #{error}")
19+
end
20+
end
21+
22+
defp parse_and_analyze(diff_output) do
23+
{added, removed} =
24+
diff_output
25+
|> String.split("\n")
26+
|> Enum.reduce({[], []}, fn
27+
"+" <> line, {adds, removes} ->
28+
if String.starts_with?(line, "++"), do: {adds, removes}, else: {[line | adds], removes}
29+
30+
"-" <> line, {adds, removes} ->
31+
if String.starts_with?(line, "--"), do: {adds, removes}, else: {adds, [line | removes]}
32+
33+
_, acc ->
34+
acc
35+
end)
36+
37+
added_set = MapSet.new(added)
38+
removed_set = MapSet.new(removed)
39+
reordered = MapSet.intersection(added_set, removed_set)
40+
41+
{MapSet.difference(added_set, reordered) |> Enum.sort(),
42+
MapSet.difference(removed_set, reordered) |> Enum.sort(), length(added), length(removed)}
43+
end
44+
45+
defp display_results({actual_added, actual_removed, total_added, total_removed}) do
46+
git_net = total_added - total_removed
47+
content_net = length(actual_added) - length(actual_removed)
48+
49+
IO.puts("\nGit diff: +#{total_added} -#{total_removed} = #{git_net} net lines")
50+
51+
IO.puts(
52+
"Content: +#{length(actual_added)} -#{length(actual_removed)} = #{content_net} net functions"
53+
)
54+
55+
IO.puts(
56+
"Math check: #{if git_net == content_net, do: "✅ CONSISTENT", else: "❌ INCONSISTENT"}"
57+
)
58+
59+
case {actual_added, actual_removed} do
60+
{[], []} ->
61+
IO.puts("\n🔄 All changes are due to reordering")
62+
63+
{funcs, []} ->
64+
show_functions("📈 NEW", funcs)
65+
66+
{[], funcs} ->
67+
show_functions("📉 REMOVED", funcs)
68+
69+
{new_funcs, old_funcs} ->
70+
[show_functions("📈 NEW", new_funcs), show_functions("📉 REMOVED", old_funcs)]
71+
end
72+
end
73+
74+
defp show_functions(label, funcs) do
75+
IO.puts("\n#{label} FUNCTIONS (#{length(funcs)}):")
76+
77+
funcs
78+
|> Enum.each(&IO.puts(" #{if String.contains?(label, "NEW"), do: "+", else: "-"} #{&1}"))
79+
end
80+
end
81+
82+
# Run the analysis
83+
FuncsDiffAnalyzer.run()

0 commit comments

Comments
 (0)