Skip to content

Commit

Permalink
Display information about upstream on 'opam info foo -v'
Browse files Browse the repository at this point in the history
  • Loading branch information
samoht committed Mar 27, 2013
1 parent a19cff1 commit d064671
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
46 changes: 43 additions & 3 deletions src/client/opamClient.ml
Expand Up @@ -414,14 +414,53 @@ module API = struct
let opam = OpamState.opam t nv in let opam = OpamState.opam t nv in


(* where does it come from (eg. which repository) *) (* where does it come from (eg. which repository) *)
let repo =
try Some (OpamState.with_repository t nv (fun p r -> (p,r)))
with _ -> None in

let repository = let repository =
if is_locally_pinned t.pinned then if is_locally_pinned t.pinned then
["repository", "(pinned)"] ["repository", "(pinned)"]
else if OpamRepositoryName.Map.cardinal t.repositories <= 1 then else if OpamRepositoryName.Map.cardinal t.repositories <= 1 then
[] []
else else match repo with
let repo = OpamState.with_repository t nv (fun _ r -> r.repo_name) in | None -> []
["repository", OpamRepositoryName.to_string repo] in | Some (_,r) -> [ "repository", OpamRepositoryName.to_string r.repo_name ] in

let url = match repo with
| None -> []
| Some (p,r) ->
if not !OpamGlobals.verbose then []
else if is_locally_pinned t.pinned then
match OpamState.pinned_path t name with
| Some p -> [ "pinned-path", OpamFilename.Dir.to_string p ]
| None -> OpamGlobals.error_and_exit "invalid pinned package"
else
let mirror =
let m = OpamPath.Repository.archive r.repo_address nv in
[ "mirror-url", OpamFilename.to_string m ] in
let file =
let prefix = OpamRepository.read_prefix p in
let prefix = OpamRepository.find_prefix prefix nv in
OpamPath.Repository.url p prefix nv in
let url =
if not (OpamFilename.exists file) then
[ "upstream-url", "<none>" ]
else (
let url = OpamFile.URL.read file in
let archive = OpamFile.URL.url url in
let kind =
match OpamFile.URL.kind url with
| None -> "http"
| Some k -> string_of_repository_kind k in
let checksum = OpamFile.URL.checksum url in
[ "upstream-url" , Printf.sprintf "%s" archive;
"upstream-kind" , kind ]
@ match checksum with
| None -> []
| Some c -> [ "upstream-checksum", c ]
) in
mirror @ url in


(* All the version of the package *) (* All the version of the package *)
let versions = OpamPackage.versions_of_name t.packages name in let versions = OpamPackage.versions_of_name t.packages name in
Expand Down Expand Up @@ -506,6 +545,7 @@ module API = struct
[ "package", OpamPackage.Name.to_string name ] [ "package", OpamPackage.Name.to_string name ]
@ [ "version", OpamPackage.Version.to_string current_version ] @ [ "version", OpamPackage.Version.to_string current_version ]
@ repository @ repository
@ url
@ homepage @ homepage
@ authors @ authors
@ license @ license
Expand Down
2 changes: 1 addition & 1 deletion src/core/opamFile.ml
Expand Up @@ -184,7 +184,7 @@ module URL = struct
let checksum = OpamFormat.assoc_option s.file_contents s_checksum OpamFormat.parse_string in let checksum = OpamFormat.assoc_option s.file_contents s_checksum OpamFormat.parse_string in
let url, kind = match archive, git, darcs with let url, kind = match archive, git, darcs with
| None , None , None -> OpamGlobals.error_and_exit "Missing URL" | None , None , None -> OpamGlobals.error_and_exit "Missing URL"
| Some x, None , None -> x, None | Some x, None , None -> x, Some `http
| None , Some x, None -> x, Some `git | None , Some x, None -> x, Some `git
| None , None , Some x -> x, Some `darcs | None , None , Some x -> x, Some `darcs
| _ -> OpamGlobals.error_and_exit "Too many URLS" in | _ -> OpamGlobals.error_and_exit "Too many URLS" in
Expand Down

0 comments on commit d064671

Please sign in to comment.