Skip to content

Commit

Permalink
repo: fixed incorrect relative link computation
Browse files Browse the repository at this point in the history
when detecting redundancies in repo I needed to test if a path was a
prefix of another, with *directory* granularity. Problem was I tested
that at *character* granularity, causing foo/bar.fa and foo/bar.fa.gz
to be detected as redundant. However for the relevant meaning when
generating repo, only foo is considered redundant.
  • Loading branch information
pveber committed Nov 17, 2018
1 parent a808c24 commit 05d4719
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
9 changes: 9 additions & 0 deletions lib/bistro.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,15 @@ module Path = struct
| "/" :: t -> "/" ^ (to_string t)
| p -> List.reduce_exn p ~f:Filename.concat

let rec is_prefix ~prefix u =
match prefix, u with
| [], _ -> true
| _, [] -> false
| h_p :: t_p, h_u :: t_u ->
h_p = h_u && is_prefix ~prefix:t_p t_u

let is_strict_prefix ~prefix u =
prefix <> u && is_prefix ~prefix u
end


Expand Down
3 changes: 3 additions & 0 deletions lib/bistro.mli
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ module Path : sig
can be used to go from [dirA] to [dirB]. @raise
[Invalid_argument] if [dirA] is relative. *)
val make_relative : ?from:string -> string -> t

val is_prefix : prefix:t -> t -> bool
val is_strict_prefix : prefix:t -> t -> bool
end

type id = string
Expand Down
10 changes: 5 additions & 5 deletions lib/utils/repo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ let item path w = Repo_item (path, w)

let ( %> ) path w = item path w

let is_strict_prefix ~prefix u =
String.length prefix < String.length u
&& String.is_prefix ~prefix u

let find_bottom items item =
let module P = Bistro.Path in
let f min_item candidate =
if is_strict_prefix ~prefix:candidate.target_path min_item.target_path
if
P.is_strict_prefix
~prefix:(P.of_string candidate.target_path)
(P.of_string min_item.target_path)
then candidate
else min_item
in
Expand Down

0 comments on commit 05d4719

Please sign in to comment.