Skip to content

Commit

Permalink
More parsing url fixes
Browse files Browse the repository at this point in the history
fixed parsing [user@]host:path.git as git
  • Loading branch information
AltGr committed Oct 27, 2015
1 parent a0a2e15 commit 97a6c96
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/client/opamArg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ let repository_name =
parse, print

let url =
let parse str = `Ok (OpamUrl.of_string str) in
let parse str = `Ok (OpamUrl.parse str) in
let print ppf url = pr_str ppf (OpamUrl.to_string url) in
parse, print

Expand Down
24 changes: 14 additions & 10 deletions src/core/opamUrl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ let split_url =
let re =
let (@@) f x = f x in
Re.(compile @@ seq [
bos;
opt @@ seq [
opt @@ seq [ group @@ rep @@ diff any (set "+:");
alt [ char '+'; str "://"] ];
Expand Down Expand Up @@ -108,23 +109,26 @@ let looks_like_ssh_path =
Some (Re.get sub 1 ^ try "/" ^ Re.get sub 2 with Not_found -> "")
with Not_found -> None

let parse ?backend s =
let parse ?backend ?(handle_suffix=true) s =
let vc, transport, path, suffix, hash = split_url s in
let backend =
match backend with
| Some b -> b
| None ->
match vc with
| Some vc -> vc_of_string vc
| None -> match transport with
| None ->
let of_suffix ~default =
if not handle_suffix then default else
match suffix with
| None -> default
| Some sf -> try vc_of_string sf with Failure _ -> default
in
match transport with
| None -> of_suffix ~default:`rsync
| Some tr ->
(try vc_of_string tr with Failure _ ->
match suffix with
| Some sf ->
(try vc_of_string sf with Failure _ ->
backend_of_string tr)
| None -> backend_of_string tr)
| None -> `rsync
try vc_of_string tr with Failure _ ->
of_suffix ~default:(backend_of_string tr)
in
let transport, path =
match backend, transport, looks_like_ssh_path path with
Expand All @@ -144,7 +148,7 @@ let parse ?backend s =
backend;
}

let of_string url = parse url
let of_string url = parse ~handle_suffix:false url

let to_string url =
let hash = match url.hash with Some h -> "#" ^ h | None -> "" in
Expand Down
6 changes: 4 additions & 2 deletions src/core/opamUrl.mli
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ type t = {
url *)
}

(** Same as [of_string], but allows enforcing the expected backend *)
val parse: ?backend:backend -> string -> t
(** Same as [of_string], but allows enforcing the expected backend, and may
otherwise guess version control from the suffix by default (for e.g.
https://foo/bar.git) (this should be disabled when parsing from files) *)
val parse: ?backend:backend -> ?handle_suffix:bool -> string -> t

include OpamStd.ABSTRACT with type t := t

Expand Down
2 changes: 1 addition & 1 deletion src/format/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ module Reinstall = LineFile(struct
let pp_pin =
Pp.pp
~name:"?pin-kind pin-target"
(fun ~pos ->function
(fun ~pos -> function
| [x] -> pin_option_of_string x
| [k;x] -> pin_option_of_string ~kind:(pin_kind_of_string k) x
| _ -> OpamFormat.bad_format ~pos "Invalid number of fields")
Expand Down
2 changes: 1 addition & 1 deletion src/format/opamFormat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ module Pp = struct
let url_with_backend backend =
string -|
pp ~name:"url"
(fun ~pos:_ -> OpamUrl.parse ~backend)
(fun ~pos:_ -> OpamUrl.parse ~backend ~handle_suffix:false)
(fun url -> OpamUrl.to_string url)

(* a hack to allow "system" compiler as ident rather than string. For
Expand Down
2 changes: 1 addition & 1 deletion src/format/opamTypesBase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ let pin_option_of_string ?kind ?(guess=false) s =
if guess then OpamUrl.guess_version_control s
else None
in
Source (OpamUrl.parse ?backend s)
Source (OpamUrl.parse ?backend ~handle_suffix:guess s)

let string_of_pin_kind = function
| `version -> "version"
Expand Down

0 comments on commit 97a6c96

Please sign in to comment.