Skip to content

Commit 1dd87d7

Browse files
committed
patch => diff
1 parent b27df7e commit 1dd87d7

File tree

11 files changed

+164
-185
lines changed

11 files changed

+164
-185
lines changed

lib/diff/storage/gcs.ex

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ defmodule Diff.Storage.GCS do
55

66
@gs_xml_url "https://storage.googleapis.com"
77

8-
def get_patch(package, from_version, to_version, patch_id) do
8+
def get_diff(package, from_version, to_version, diff_id) do
99
with {:ok, hash} <- combined_checksum(package, from_version, to_version),
10-
url = url(patch_key(package, from_version, to_version, hash, patch_id)),
10+
url = url(diff_key(package, from_version, to_version, hash, diff_id)),
1111
{:ok, 200, _headers, body} <-
1212
Diff.HTTP.retry("gs", fn -> Diff.HTTP.get(url, headers()) end) do
1313
{:ok, body}
@@ -16,37 +16,37 @@ defmodule Diff.Storage.GCS do
1616
{:error, :not_found}
1717

1818
{:ok, status, _headers, _body} ->
19-
Logger.error("Failed to get patch from storage. Status #{status}")
19+
Logger.error("Failed to get diff from storage. Status #{status}")
2020
{:error, :not_found}
2121

2222
{:error, reason} ->
23-
Logger.error("Failed to get patch from storage. Reason #{inspect(reason)}")
23+
Logger.error("Failed to get diff from storage. Reason #{inspect(reason)}")
2424
{:error, :not_found}
2525
end
2626
end
2727

28-
def put_patch(package, from_version, to_version, patch_id, patch_data) do
28+
def put_diff(package, from_version, to_version, diff_id, diff_data) do
2929
with {:ok, hash} <- combined_checksum(package, from_version, to_version),
30-
url = url(patch_key(package, from_version, to_version, hash, patch_id)),
30+
url = url(diff_key(package, from_version, to_version, hash, diff_id)),
3131
{:ok, 200, _headers, _body} <-
32-
Diff.HTTP.retry("gs", fn -> Diff.HTTP.put(url, headers(), patch_data) end) do
32+
Diff.HTTP.retry("gs", fn -> Diff.HTTP.put(url, headers(), diff_data) end) do
3333
:ok
3434
else
3535
{:ok, status, _headers, _body} ->
36-
Logger.error("Failed to put patch to storage. Status #{status}")
36+
Logger.error("Failed to put diff to storage. Status #{status}")
3737
{:error, :storage_error}
3838

3939
error ->
40-
Logger.error("Failed to put patch to storage. Reason #{inspect(error)}")
40+
Logger.error("Failed to put diff to storage. Reason #{inspect(error)}")
4141
error
4242
end
4343
end
4444

45-
def list_patches(package, from_version, to_version) do
45+
def list_diffs(package, from_version, to_version) do
4646
case get_metadata(package, from_version, to_version) do
47-
{:ok, %{total_patches: total_patches}} ->
48-
patch_ids = 0..(total_patches - 1) |> Enum.map(&"patch-#{&1}")
49-
{:ok, patch_ids}
47+
{:ok, %{total_diffs: total_diffs}} ->
48+
diff_ids = 0..(total_diffs - 1) |> Enum.map(&"diff-#{&1}")
49+
{:ok, diff_ids}
5050

5151
{:error, :not_found} ->
5252
{:ok, []}
@@ -112,8 +112,8 @@ defmodule Diff.Storage.GCS do
112112
end
113113
end
114114

115-
defp patch_key(package, from_version, to_version, hash, patch_id) do
116-
"diffs/patches/#{package}-#{from_version}-#{to_version}-#{hash}-#{patch_id}.patch"
115+
defp diff_key(package, from_version, to_version, hash, diff_id) do
116+
"diffs/diffs/#{package}-#{from_version}-#{to_version}-#{hash}-#{diff_id}.json"
117117
end
118118

119119
defp metadata_key(package, from_version, to_version, hash) do

lib/diff/storage/local.ex

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ defmodule Diff.Storage.Local do
33

44
@behaviour Diff.Storage
55

6-
def get_patch(package, from_version, to_version, patch_id) do
6+
def get_diff(package, from_version, to_version, diff_id) do
77
case combined_checksum(package, from_version, to_version) do
88
{:ok, hash} ->
9-
filename = patch_key(package, from_version, to_version, hash, patch_id)
10-
path = Path.join([dir(), package, "patches", filename])
9+
filename = diff_key(package, from_version, to_version, hash, diff_id)
10+
path = Path.join([dir(), package, "diffs", filename])
1111

1212
if File.regular?(path) do
1313
{:ok, File.read!(path)}
@@ -20,40 +20,40 @@ defmodule Diff.Storage.Local do
2020
end
2121
end
2222

23-
def put_patch(package, from_version, to_version, patch_id, patch_data) do
23+
def put_diff(package, from_version, to_version, diff_id, diff_data) do
2424
with {:ok, hash} <- combined_checksum(package, from_version, to_version),
25-
filename = patch_key(package, from_version, to_version, hash, patch_id),
26-
path = Path.join([dir(), package, "patches", filename]),
25+
filename = diff_key(package, from_version, to_version, hash, diff_id),
26+
path = Path.join([dir(), package, "diffs", filename]),
2727
:ok <- File.mkdir_p(Path.dirname(path)) do
28-
File.write!(path, patch_data)
28+
File.write!(path, diff_data)
2929
:ok
3030
else
3131
{:error, reason} ->
32-
Logger.error("Failed to store patch. Reason: #{inspect(reason)}.")
32+
Logger.error("Failed to store diff. Reason: #{inspect(reason)}.")
3333
{:error, reason}
3434
end
3535
end
3636

37-
def list_patches(package, from_version, to_version) do
37+
def list_diffs(package, from_version, to_version) do
3838
case combined_checksum(package, from_version, to_version) do
3939
{:ok, hash} ->
40-
patches_dir = Path.join([dir(), package, "patches"])
40+
diffs_dir = Path.join([dir(), package, "diffs"])
4141
prefix = "#{package}-#{from_version}-#{to_version}-#{hash}-"
4242

43-
if File.dir?(patches_dir) do
44-
patch_ids =
45-
patches_dir
43+
if File.dir?(diffs_dir) do
44+
diff_ids =
45+
diffs_dir
4646
|> File.ls!()
4747
|> Enum.filter(&String.starts_with?(&1, prefix))
4848
|> Enum.map(fn filename ->
4949
filename
5050
|> String.replace_prefix(prefix, "")
51-
|> String.replace_suffix(".patch", "")
51+
|> String.replace_suffix(".diff", "")
5252
end)
53-
|> Enum.sort_by(fn patch_id ->
54-
# Extract numeric part for proper sorting (e.g., "patch-10" -> 10)
55-
case String.split(patch_id, "-") do
56-
["patch", num_str] ->
53+
|> Enum.sort_by(fn diff_id ->
54+
# Extract numeric part for proper sorting (e.g., "diff-10" -> 10)
55+
case String.split(diff_id, "-") do
56+
["diff", num_str] ->
5757
case Integer.parse(num_str) do
5858
{num, _} -> num
5959
:error -> 0
@@ -64,7 +64,7 @@ defmodule Diff.Storage.Local do
6464
end
6565
end)
6666

67-
{:ok, patch_ids}
67+
{:ok, diff_ids}
6868
else
6969
{:ok, []}
7070
end
@@ -121,8 +121,8 @@ defmodule Diff.Storage.Local do
121121
end
122122
end
123123

124-
defp patch_key(package, from_version, to_version, hash, patch_id) do
125-
"#{package}-#{from_version}-#{to_version}-#{hash}-#{patch_id}.patch"
124+
defp diff_key(package, from_version, to_version, hash, diff_id) do
125+
"#{package}-#{from_version}-#{to_version}-#{hash}-#{diff_id}.diff"
126126
end
127127

128128
defp metadata_key(package, from_version, to_version, hash) do

lib/diff/storage/storage.ex

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,21 @@ defmodule Diff.Storage do
22
@type package :: String.t()
33
@type from_version :: String.t()
44
@type to_version :: String.t()
5-
@type patch_id :: String.t()
6-
@type patch_html :: String.t()
5+
@type diff_id :: String.t()
6+
@type diff_html :: String.t()
77
@type diff_metadata :: %{
8-
total_patches: non_neg_integer(),
8+
total_diffs: non_neg_integer(),
99
total_additions: non_neg_integer(),
1010
total_deletions: non_neg_integer(),
1111
files_changed: non_neg_integer()
1212
}
1313

14-
# New patch-level storage callbacks
15-
@callback get_patch(package, from_version, to_version, patch_id) ::
16-
{:ok, patch_html} | {:error, term}
17-
@callback put_patch(package, from_version, to_version, patch_id, patch_html) ::
14+
# New diff-level storage callbacks
15+
@callback get_diff(package, from_version, to_version, diff_id) ::
16+
{:ok, diff_html} | {:error, term}
17+
@callback put_diff(package, from_version, to_version, diff_id, diff_html) ::
1818
:ok | {:error, term}
19-
@callback list_patches(package, from_version, to_version) :: {:ok, [patch_id]} | {:error, term}
19+
@callback list_diffs(package, from_version, to_version) :: {:ok, [diff_id]} | {:error, term}
2020

2121
# Metadata storage callbacks
2222
@callback get_metadata(package, from_version, to_version) ::
@@ -25,16 +25,16 @@ defmodule Diff.Storage do
2525

2626
defp impl(), do: Application.get_env(:diff, :storage_impl)
2727

28-
def get_patch(package, from_version, to_version, patch_id) do
29-
impl().get_patch(package, from_version, to_version, patch_id)
28+
def get_diff(package, from_version, to_version, diff_id) do
29+
impl().get_diff(package, from_version, to_version, diff_id)
3030
end
3131

32-
def put_patch(package, from_version, to_version, patch_id, patch_html) do
33-
impl().put_patch(package, from_version, to_version, patch_id, patch_html)
32+
def put_diff(package, from_version, to_version, diff_id, diff_html) do
33+
impl().put_diff(package, from_version, to_version, diff_id, diff_html)
3434
end
3535

36-
def list_patches(package, from_version, to_version) do
37-
impl().list_patches(package, from_version, to_version)
36+
def list_diffs(package, from_version, to_version) do
37+
impl().list_diffs(package, from_version, to_version)
3838
end
3939

4040
def get_metadata(package, from_version, to_version) do

0 commit comments

Comments
 (0)