Skip to content
This repository has been archived by the owner on Oct 8, 2020. It is now read-only.

Commit

Permalink
Introduce a common data type for less-than / equal / greater-than com…
Browse files Browse the repository at this point in the history
…parisons. (#128)
  • Loading branch information
scouten committed Aug 27, 2019
1 parent 00d219f commit e0d77ec
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/xgit/core/dir_cache.ex
Expand Up @@ -23,6 +23,8 @@ defmodule Xgit.Core.DirCache do
use Bitwise
use Xgit.Core.FileMode

alias Xgit.Util.Comparison

@typedoc ~S"""
Version number for an index file.
"""
Expand Down Expand Up @@ -200,7 +202,7 @@ defmodule Xgit.Core.DirCache do
* `:eq` if they are the same.
* `:gt` if `entry1` sorts after `entry2`.
"""
@spec compare(entry1 :: t | nil, entry2 :: t) :: :lt | :eq | :gt
@spec compare(entry1 :: t | nil, entry2 :: t) :: Comparison.result()
def compare(entry1, entry2)

def compare(nil, _entry2), do: :lt
Expand Down
10 changes: 10 additions & 0 deletions lib/xgit/util/comparison.ex
@@ -0,0 +1,10 @@
defmodule Xgit.Util.Comparison do
@moduledoc ~S"""
Common vocabulary for data types that can be compared and/or sorted.
"""

@typedoc """
Result of a comparison.
"""
@type result :: :lt | :eq | :gt
end
8 changes: 3 additions & 5 deletions lib/xgit/util/paths.ex
Expand Up @@ -50,11 +50,9 @@ defmodule Xgit.Util.Paths do
"""

use Bitwise

use Xgit.Core.FileMode

@typedoc "Comparison result."
@type comparison_result :: :lt | :eq | :gt
alias Xgit.Util.Comparison

@doc ~S"""
Remove trailing `/` if present.
Expand Down Expand Up @@ -87,7 +85,7 @@ defmodule Xgit.Util.Paths do
mode1 :: FileMode.t(),
path2 :: charlist,
mode2 :: FileMode.t()
) :: comparison_result
) :: Comparison.result()
def compare(path1, mode1, path2, mode2)
when is_list(path1) and is_file_mode(mode1) and is_list(path2) and is_file_mode(mode2) do
case core_compare(path1, mode1, path2, mode2) do
Expand Down Expand Up @@ -127,7 +125,7 @@ defmodule Xgit.Util.Paths do
one of the other return values.
"""
@spec compare_same_name(path1 :: charlist, path2 :: charlist, mode2 :: FileMode.t()) ::
comparison_result
Comparison.result()
def compare_same_name(path1, path2, mode2),
do: core_compare(path1, FileMode.tree(), path2, mode2)

Expand Down

0 comments on commit e0d77ec

Please sign in to comment.