···11+22+- `Fpath.relativize` improve docs and change some correct but
33+ surpising results. Thanks to Martin Jambon for the report (#20).
44+15v0.7.3 2020-09-08 Zagreb
26------------------------
37
+5-1
vendor/opam/fpath/src/fpath.ml
···484484(* Roots and relativization *)
485485486486let _relativize ~root p =
487487+ if String.equal root p
488488+ then Some (segs_to_path (if is_dir_path p then ["."; ""] else ["."])) else
487489 let root = (* root is always interpreted as a directory *)
488490 let root = normalize root in
489491 if root.[String.length root - 1] = dir_sep_char then root else
···544546545547let is_rooted ~root p = match relativize ~root p with
546548| None -> false
547547-| Some r -> not (String.equal dotdot r || String.is_prefix ~affix:dotdot_dir r)
549549+| Some r ->
550550+ not (String.equal dotdot r || String.is_prefix ~affix:dotdot_dir r ||
551551+ (String.equal root p && not (is_dir_path p)))
548552549553(* Predicates and comparison *)
550554
+15-6
vendor/opam/fpath/src/fpath.mli
···263263(** {1:rootrel Roots and relativization} *)
264264265265val relativize : root:t -> t -> t option
266266-(** [relativize ~root p] is:
266266+(** [relativize ~root p] tries to express path [p] relative to the directory
267267+ [root]:
267268 {ul
268268- {- [Some q] if there exists a {{!is_relative}relative} path [q] such
269269+ {- [Some q] if there exists a {{!is_rel}relative} path [q] such
269270 that [root // q] and [p] represent the same paths,
270271 {{!is_dir_path}directoryness} included. They may however differ
271272 syntactically when converted to a string. Note that [q] is
272273 {{!normalize}normalized}.}
273273- {- [None] otherwise.}}
274274-274274+ {- [None] otherwise. This notably happens if [p] is absolute
275275+ and [root] relative or if [root] is relative and [p] is absolute.
276276+ In both cases it's not possible to know how to get from [p] from
277277+ [root].}}
275278 {{!ex_relativize}Examples}. *)
276279277280val is_rooted : root:t -> t -> bool
···855858856859 {2:ex_relativize {!relativize}}
857860 {ul
861861+ {- [relativize ~root:(v "/a/b") (v "/a/b")] is [Some (v ".")]}
862862+ {- [relativize ~root:(v "/a/b") (v "/a/b/")] is [Some (v "./")]}
863863+ {- [relativize ~root:(v "/a/b/") (v "/a/b/")] is [Some (v "./")]}
864864+ {- [relativize ~root:(v "/a/b/") (v "/a/b")] is [Some (v "../b")]}
865865+ {- [relativize ~root:(v "a/b") (v "a/b")] is [Some (v ".")]}
866866+ {- [relativize ~root:(v "a/b/") (v "a/b/")] is [Some (v "./")]}
867867+ {- [relativize ~root:(v "a/b") (v "a/b/")] is [Some (v "./")]}
868868+ {- [relativize ~root:(v "a/b/") (v "a/b")] is [Some (v "../b")]}
858869 {- [relativize ~root:(v "/a/b") (v "c")] is [None]}
859870 {- [relativize ~root:(v "/a/b") (v "/c")] is [Some (v "../../c")]}
860871 {- [relativize ~root:(v "/a/b") (v "/c/")] is [Some (v "../../c/")]}
···862873 {- [relativize ~root:(v "/a/b") (v "/c/")] is [Some (v "../../c/")]}
863874 {- [relativize ~root:(v "/a/b") (v "/a/b/c")] is [Some (v "c")]}
864875 {- [relativize ~root:(v "/a/b") (v "/a/b/c/")] is [Some (v "c/")]}
865865- {- [relativize ~root:(v "/a/b") (v "/a/b")] is [Some (v "../b")]}
866866- {- [relativize ~root:(v "/a/b") (v "/a/b/")] is [Some (v ".")]}
867876 {- [relativize ~root:(v "a/b") (v "/c")] is [None].}
868877 {- [relativize ~root:(v "a/b") (v "c")] is [Some (v "../../c")]}
869878 {- [relativize ~root:(v "a/b") (v "c/")] is [Some (v "../../c/")]}
+11
vendor/opam/fpath/test/test_fpath.ml
···693693 | None -> eq_opt None result ~__POS__
694694 | Some rel as r ->
695695 eq_opt r result ~__POS__;
696696+ let p = if Fpath.is_current_dir rel then Fpath.to_dir_path p else p in
696697 eq (Fpath.normalize (Fpath.append root rel)) (Fpath.normalize p)
697698 ~__POS__;
698699 in
700700+ relativize (v "/a/b") (v "/a/b") (Some (v ".")) ~__POS__;
701701+ relativize (v "/a/b") (v "/a/b/") (Some (v "./")) ~__POS__;
702702+ relativize (v "/a/b/") (v "/a/b/") (Some (v "./")) ~__POS__;
703703+ relativize (v "/a/b/") (v "/a/b") (Some (v "../b")) ~__POS__;
704704+ relativize (v "a/b") (v "a/b") (Some (v ".")) ~__POS__;
705705+ relativize (v "a/b") (v "a/b/") (Some (v "./")) ~__POS__;
706706+ relativize (v "a/b/") (v "a/b/") (Some (v "./")) ~__POS__;
707707+ relativize (v "a/b/") (v "a/b") (Some (v "../b")) ~__POS__;
708708+ relativize (v "a") (v "a") (Some (v ".")) ~__POS__;
709709+ relativize (v "a/") (v "a/") (Some (v "./")) ~__POS__;
699710 relativize (v "/a/") (v "/a") (Some (v "../a")) ~__POS__;
700711 relativize (v "/a/") (v "/a/") (Some (v "./")) ~__POS__;
701712 relativize (v "/a/") (v "/") (Some (v "../")) ~__POS__;