Skip to content

Commit

Permalink
Avoid opam source command, fetching with --depth 1
Browse files Browse the repository at this point in the history
- Fixes #5061
  • Loading branch information
moyodiallo committed Mar 20, 2024
1 parent 976455a commit deca4d4
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/client/opamCommands.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3696,6 +3696,7 @@ let source cli =
match
OpamProcess.Job.run
(OpamRepository.pull_tree
~full_fetch:true
~cache_dir:(OpamRepositoryPath.download_cache
OpamStateConfig.(!r.root_dir))
?subpath
Expand Down
2 changes: 1 addition & 1 deletion src/repository/opamDarcs.ml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module VCS = struct
(* Marks the current state, in the form of a reversing patch on top of the
fetched state *)

let fetch ?cache_dir:_ ?subpath:_ repo_root repo_url =
let fetch ?full_fetch:_ ?cache_dir:_ ?subpath:_ repo_root repo_url =
(* Just do a fresh pull into a temp directory, and replace _darcs/
There is no easy way to diff or make sure darcs forgets about local
patches otherwise. *)
Expand Down
9 changes: 7 additions & 2 deletions src/repository/opamGit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ open OpamProcess.Job.Op

module VCS : OpamVCS.VCS = struct


let name = `git

let exists repo_root =
Expand Down Expand Up @@ -62,7 +63,8 @@ module VCS : OpamVCS.VCS = struct
| Some h -> "refs/remotes/opam-ref-"^h
| None -> "refs/remotes/opam-ref"

let fetch ?cache_dir ?subpath repo_root repo_url =
let fetch ?(full_fetch = false) ?cache_dir ?subpath repo_root repo_url =
(* let fetch ?cache_dir ?subpath repo_root repo_url = *)
(match subpath with
| Some sp ->
git repo_root [ "config"; "--local"; "core.sparseCheckout"; "true" ]
Expand Down Expand Up @@ -95,7 +97,10 @@ module VCS : OpamVCS.VCS = struct
OpamFilename.write alternates
(OpamFilename.Dir.to_string (cache / "objects")))
global_cache;
git repo_root [ "fetch" ; "-q"; origin; "--update-shallow"; "--depth=1"; refspec ]
(if full_fetch then
git repo_root [ "fetch" ; "-q"; origin; "--update-shallow"; refspec ]
else
git repo_root [ "fetch" ; "-q"; origin; "--update-shallow"; "--depth=1"; refspec ])
@@> fun r ->
if OpamProcess.check_success_and_cleanup r then
let refspec =
Expand Down
4 changes: 2 additions & 2 deletions src/repository/opamHTTP.ml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module B = struct

let name = `http

let fetch_repo_update repo_name ?cache_dir:_ repo_root url =
let fetch_repo_update repo_name ?full_fetch:_ ?cache_dir:_ repo_root url =
log "pull-repo-update";
let quarantine =
OpamFilename.Dir.(of_string (to_string repo_root ^ ".new"))
Expand Down Expand Up @@ -68,7 +68,7 @@ module B = struct

let repo_update_complete _ _ = Done ()

let pull_url ?cache_dir:_ ?subpath:_ dirname checksum remote_url =
let pull_url ?full_fetch:_ ?cache_dir:_ ?subpath:_ dirname checksum remote_url =
log "pull-file into %a: %a"
(slog OpamFilename.Dir.to_string) dirname
(slog OpamUrl.to_string) remote_url;
Expand Down
2 changes: 1 addition & 1 deletion src/repository/opamHg.ml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ module VCS = struct
| None -> mark_prefix
| Some fragment -> mark_prefix ^ "-" ^ fragment

let fetch ?cache_dir:_ ?subpath:_ repo_root repo_url =
let fetch ?full_fetch:_ ?cache_dir:_ ?subpath:_ repo_root repo_url =
let src = OpamUrl.base_url repo_url in
let rev = OpamStd.Option.default "default" repo_url.OpamUrl.hash in
let mark = mark_from_url repo_url in
Expand Down
4 changes: 2 additions & 2 deletions src/repository/opamLocal.ml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ module B = struct
let pull_dir_quiet local_dirname url =
rsync_dirs url local_dirname

let fetch_repo_update repo_name ?cache_dir:_ repo_root url =
let fetch_repo_update repo_name ?full_fetch:_ ?cache_dir:_ repo_root url =
log "pull-repo-update";
let quarantine =
OpamFilename.Dir.(of_string (to_string repo_root ^ ".new"))
Expand Down Expand Up @@ -190,7 +190,7 @@ module B = struct

let repo_update_complete _ _ = Done ()

let pull_url ?cache_dir:_ ?subpath local_dirname _checksum remote_url =
let pull_url ?full_fetch:_ ?cache_dir:_ ?subpath local_dirname _checksum remote_url =
let local_dirname = OpamFilename.SubPath.(local_dirname /? subpath) in
OpamFilename.mkdir local_dirname;
let dir = OpamFilename.Dir.to_string local_dirname in
Expand Down
20 changes: 10 additions & 10 deletions src/repository/opamRepository.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ let validate_and_add_to_cache label url cache_dir file checksums =

(* [cache_dir] used to add to cache only *)
let pull_from_upstream
label ?(working_dir=false) ?subpath cache_dir destdir checksums url =
label ?full_fetch ?(working_dir=false) ?subpath cache_dir destdir checksums url =
let module B = (val url_backend url: OpamRepositoryBackend.S) in
let cksum = match checksums with [] -> None | c::_ -> Some c in
let text =
Expand Down Expand Up @@ -206,7 +206,7 @@ let pull_from_upstream
)
else url, B.pull_url
in
pull ?cache_dir ?subpath destdir cksum url
pull ?full_fetch ?cache_dir ?subpath destdir cksum url
)
@@| function
| (Result (Some file) | Up_to_date (Some file)) as ret ->
Expand All @@ -219,14 +219,14 @@ let pull_from_upstream
| (Result None | Up_to_date None) as ret -> ret
| Not_available _ as na -> na

let pull_from_mirrors label ?working_dir ?subpath cache_dir destdir checksums urls =
let pull_from_mirrors label ?full_fetch ?working_dir ?subpath cache_dir destdir checksums urls =
let rec aux = function
| [] -> invalid_arg "pull_from_mirrors: empty mirror list"
| [url] ->
pull_from_upstream label ?working_dir ?subpath cache_dir destdir checksums url
pull_from_upstream label ?full_fetch ?working_dir ?subpath cache_dir destdir checksums url
@@| fun r -> url, r
| url::mirrors ->
pull_from_upstream label ?working_dir ?subpath cache_dir destdir checksums url
pull_from_upstream label ?full_fetch ?working_dir ?subpath cache_dir destdir checksums url
@@+ function
| Not_available (_,s) ->
OpamConsole.warning "%s: download of %s failed (%s), trying mirror"
Expand All @@ -246,7 +246,7 @@ let pull_from_mirrors label ?working_dir ?subpath cache_dir destdir checksums ur

(* handle subpathes *)
let pull_tree_t
?cache_dir ?(cache_urls=[]) ?working_dir
?full_fetch ?cache_dir ?(cache_urls=[]) ?working_dir
dirnames checksums remote_urls =
let extract_archive =
let fallback success = function
Expand Down Expand Up @@ -342,13 +342,13 @@ let pull_tree_t
let pull label checksums remote_urls =
match dirnames with
| [ label, local_dirname, subpath ] ->
pull_from_mirrors label ?working_dir ?subpath cache_dir local_dirname
pull_from_mirrors label ?full_fetch ?working_dir ?subpath cache_dir local_dirname
checksums remote_urls
@@| fun (url, res) ->
(OpamUrl.to_string_w_subpath subpath url),
res
| _ ->
pull_from_mirrors label ?working_dir cache_dir tmpdir
pull_from_mirrors label ?full_fetch ?working_dir cache_dir tmpdir
checksums remote_urls
@@| fun (url, res) -> OpamUrl.to_string url, res
in
Expand All @@ -361,9 +361,9 @@ let pull_tree_t
| _, (Not_available _ as na) -> Done na


let pull_tree label ?cache_dir ?(cache_urls=[]) ?working_dir ?subpath
let pull_tree label ?full_fetch ?cache_dir ?(cache_urls=[]) ?working_dir ?subpath
local_dirname =
pull_tree_t ?cache_dir ~cache_urls ?working_dir
pull_tree_t ?full_fetch ?cache_dir ~cache_urls ?working_dir
[label, local_dirname, subpath]

let pull_shared_tree ?cache_dir ?(cache_urls=[]) dirnames checksums remote_urls =
Expand Down
2 changes: 1 addition & 1 deletion src/repository/opamRepository.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ val pull_shared_tree:

(* Same as [pull_shared_tree], but for a unique label/dirname. *)
val pull_tree:
string -> ?cache_dir:dirname -> ?cache_urls:url list -> ?working_dir:bool ->
string -> ?full_fetch:bool -> ?cache_dir:dirname -> ?cache_urls:url list -> ?working_dir:bool ->
?subpath:subpath -> dirname -> OpamHash.t list -> url list ->
string download OpamProcess.job

Expand Down
3 changes: 2 additions & 1 deletion src/repository/opamRepositoryBackend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ type update =
module type S = sig
val name: OpamUrl.backend
val pull_url:
?full_fetch:bool ->
?cache_dir:dirname -> ?subpath:subpath -> dirname -> OpamHash.t option -> url ->
filename option download OpamProcess.job
val fetch_repo_update:
repository_name -> ?cache_dir:dirname -> dirname -> url ->
repository_name -> ?full_fetch:bool -> ?cache_dir:dirname -> dirname -> url ->
update OpamProcess.job
val repo_update_complete: dirname -> url -> unit OpamProcess.job
val revision: dirname -> version option OpamProcess.job
Expand Down
3 changes: 2 additions & 1 deletion src/repository/opamRepositoryBackend.mli
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ module type S = sig
[checksum] can be used for retrieval but is NOT checked by this
function. *)
val pull_url:
?full_fetch:bool ->
?cache_dir:dirname -> ?subpath:subpath -> dirname -> OpamHash.t option ->
url -> filename option download OpamProcess.job

Expand All @@ -53,7 +54,7 @@ module type S = sig
verifications. The file or directory returned is always temporary and
should be cleaned up by the caller. *)
val fetch_repo_update:
repository_name -> ?cache_dir:dirname -> dirname -> url ->
repository_name -> ?full_fetch:bool -> ?cache_dir:dirname -> dirname -> url ->
update OpamProcess.job

(** [repo_update_complete dirname url] finalizes the update of the repository
Expand Down
14 changes: 7 additions & 7 deletions src/repository/opamVCS.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module type VCS = sig
val exists: dirname -> bool
val init: dirname -> url -> unit OpamProcess.job
val fetch:
?cache_dir:dirname -> ?subpath:subpath -> dirname -> url ->
?full_fetch:bool -> ?cache_dir:dirname -> ?subpath:subpath -> dirname -> url ->
unit OpamProcess.job
val reset_tree: dirname -> url -> unit OpamProcess.job
val patch_applied: dirname -> url -> unit OpamProcess.job
Expand All @@ -41,12 +41,12 @@ module Make (VCS: VCS) = struct

let name = VCS.name

let fetch_repo_update repo_name ?cache_dir repo_root repo_url =
let fetch_repo_update repo_name ?full_fetch ?cache_dir repo_root repo_url =
if VCS.exists repo_root then
OpamProcess.Job.catch (fun e -> Done (OpamRepositoryBackend.Update_err e))
@@ fun () ->
OpamRepositoryBackend.job_text repo_name "sync"
(VCS.fetch ?cache_dir repo_root repo_url)
(VCS.fetch ?full_fetch ?cache_dir repo_root repo_url)
@@+ fun () ->
OpamRepositoryBackend.job_text repo_name "diff"
(VCS.diff repo_root repo_url)
Expand All @@ -62,7 +62,7 @@ module Make (VCS: VCS) = struct
(VCS.init repo_root repo_url)
@@+ fun () ->
OpamRepositoryBackend.job_text repo_name "sync"
(VCS.fetch ?cache_dir repo_root repo_url)
(VCS.fetch ?full_fetch ?cache_dir repo_root repo_url)
@@+ fun () ->
let tmpdir = OpamFilename.Dir.(of_string (to_string repo_root ^".new")) in
OpamFilename.copy_dir ~src:repo_root ~dst:tmpdir;
Expand All @@ -75,7 +75,7 @@ module Make (VCS: VCS) = struct
VCS.patch_applied dirname url @@+ fun () ->
Done ()

let pull_url ?cache_dir ?subpath dirname checksum url =
let pull_url ?full_fetch ?cache_dir ?subpath dirname checksum url =
if checksum <> None then invalid_arg "VC pull_url doesn't allow checksums";
OpamProcess.Job.catch
(fun e ->
Expand All @@ -87,7 +87,7 @@ module Make (VCS: VCS) = struct
@@ fun () ->
if VCS.exists dirname then
VCS.clean dirname @@+ fun () ->
VCS.fetch ?cache_dir ?subpath dirname url @@+ fun () ->
VCS.fetch ?full_fetch ?cache_dir ?subpath dirname url @@+ fun () ->
VCS.is_up_to_date ?subpath dirname url @@+ function
| true -> Done (Up_to_date None)
| false ->
Expand All @@ -96,7 +96,7 @@ module Make (VCS: VCS) = struct
else
(OpamFilename.mkdir dirname;
VCS.init dirname url @@+ fun () ->
VCS.fetch ?cache_dir ?subpath dirname url @@+ fun () ->
VCS.fetch ?full_fetch ?cache_dir ?subpath dirname url @@+ fun () ->
VCS.reset_tree dirname url @@+ fun () ->
Done (Result None))

Expand Down
2 changes: 1 addition & 1 deletion src/repository/opamVCS.mli
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ module type VCS = sig
Be aware that the remote URL might have been changed, so make sure
to update accordingly. *)
val fetch:
?cache_dir:dirname -> ?subpath:subpath -> dirname -> url ->
?full_fetch:bool -> ?cache_dir:dirname -> ?subpath:subpath -> dirname -> url ->
unit OpamProcess.job

(** Reset the master branch of the repository to match the remote repository
Expand Down

0 comments on commit deca4d4

Please sign in to comment.