Skip to content

Commit 7581bc6

Browse files
rjboudra27kit-ty-kate
authored
Apply suggestions from code review
Co-authored-by: David Allsopp <[email protected]> Co-authored-by: Kate <[email protected]>
1 parent 21e50c7 commit 7581bc6

File tree

4 files changed

+25
-10
lines changed

4 files changed

+25
-10
lines changed

src/state/opamFormatUpgrade.ml

+21-6
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,20 @@ let from_2_2_beta_to_2_2 ~on_the_fly:_ _ conf = conf, gtc_none
11571157

11581158
let latest_version = OpamFile.Config.root_version
11591159

1160-
(* Note to dev: try as possible to not change that value *)
1160+
(* Development notes:
1161+
opam differentiates two kinds of format upgrade - "Hard" upgrades, which
1162+
must be written straight to disk, and "Light" upgrades, which can be
1163+
performed in-memory, and don't have to be written immediately.
1164+
This distinction was added in opam 2.1, as it allows users of a _newer_
1165+
version of opam-state to _read_ an opam root which is still being maintained
1166+
by an _older_ version of opam (for example, it allows a program compiled with
1167+
opam-state 2.1.0 to load the global configuration of an opam 2.0 user's root
1168+
without forcing the upgrade of that root to 2.1).
1169+
1170+
Essentially, a "Hard" upgrade is used where the change is difficult (or even
1171+
impossible) to perform in-memory. We try our hardest to keep all format
1172+
upgrades "Light" - i.e. the aim is that this version below should never
1173+
change. *)
11611174
let latest_hard_upgrade = (* to *) v2_0_beta5
11621175

11631176
(* intermediate roots that need a hard upgrade when upgrading from them *)
@@ -1360,14 +1373,16 @@ let as_necessary_repo_switch_t updates changes read_f lock_kind gt =
13601373
(* If we don't have a written opam root version in a config file,
13611374
we are unable to determine if there is an upgrade to do. This can happen in
13621375
case there is only on the fly upgrades from 2.0. Should we fail ? *)
1363-
let written_root_version = OpamFile.Config.raw_root_version config_f
1376+
let written_root_version =
1377+
OpamFile.Config.raw_root_version config_f
13641378
in
13651379
(* Config already upgraded *)
1366-
if OpamStd.Option.equal OpamVersion.equal
1367-
written_root_version
1368-
(Some OpamFile.Config.root_version) then None else
1380+
if OpamStd.Option.equal_some OpamVersion.equal
1381+
OpamFile.Config.root_version written_root_version then
1382+
None
1383+
else
13691384
let written_root_version =
1370-
OpamStd.Option.default v2_0 written_root_version
1385+
OpamStd.Option.default OpamFile.Config.default_old_root_version written_root_version
13711386
in
13721387
let updates =
13731388
List.filter (fun (v,_) ->

src/state/opamFormatUpgrade.mli

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ val as_necessary:
3838
OpamFile.Config.t ->
3939
OpamFile.Config.t * gt_changes
4040

41-
(* [as_necessary_repo lock gt] does he upgrades at repo level. [lock] is the
41+
(* [as_necessary_repo lock gt] does the upgrades at repo level. [lock] is the
4242
required lock for repo state and gt the on-the-fly upgraded global lock. If
43-
[lock] is non or read, it will perform an on-the-fly upgrade of repos-config
43+
[lock] is none or read, it will perform an on-the-fly upgrade of repos-config
4444
and return it. if [lock] is a write lock, it locks opam root and perform and
4545
apply all needed upgrades (write global, repo & state config if needed).
4646
At global state loading, [as_necessary] is called, so this function will do

src/state/opamRepositoryState.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let load lock_kind gt =
159159
log "LOAD-REPOSITORY-STATE %@ %a" (slog OpamFilename.Dir.to_string) gt.root;
160160
let lock = OpamFilename.flock lock_kind (OpamPath.repos_lock gt.root) in
161161
let repos_map =
162-
match repos_config with
162+
match OpamFormatUpgrade.as_necessary_switch lock_kind switch gt with
163163
| Some repos_map -> repos_map
164164
| None -> OpamStateConfig.Repos.safe_read ~lock_kind gt
165165
in

src/state/opamSwitchState.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ let load lock_kind gt rt switch =
259259
OpamFilename.flock lock_kind (OpamPath.Switch.lock gt.root switch)
260260
in
261261
let switch_config =
262-
match switch_config with
262+
match OpamFormatUpgrade.as_necessary_switch lock_kind switch gt with
263263
| Some switch_config -> switch_config
264264
| None -> load_switch_config ~lock_kind gt switch
265265
in

0 commit comments

Comments
 (0)