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 ocaml#5061
  • Loading branch information
moyodiallo committed Mar 19, 2024
1 parent 976455a commit bcef852
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 18 deletions.
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_depth:_ ?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_depth = 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_depth 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_depth:_ ?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_depth:_ ?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_depth:_ ?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_depth:_ ?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_depth:_ ?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
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_depth: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_depth: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_depth: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_depth: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_depth: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_depth ?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_depth ?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_depth ?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_depth ?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_depth ?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_depth ?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_depth: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 bcef852

Please sign in to comment.