From 451a7ce77f94a32522c0a956918a6e111e082e1a Mon Sep 17 00:00:00 2001
From: Joey Hess <joeyh@joeyh.name>
Date: Thu, 15 Sep 2022 15:11:59 -0400
Subject: [PATCH] vicfg: Include mincopies configuration

Sponsored-by: k0ld on Patreon
---
 CHANGELOG        |  1 +
 Command/Vicfg.hs | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG b/CHANGELOG
index be72e2089e..a2e4af40ac 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -13,6 +13,7 @@ git-annex (10.20220823) UNRELEASED; urgency=medium
   * Fix a reversion that made dead keys not be skipped when operating on
     all keys via --all or in a bare repo.
     (Introduced in version 8.20200720)
+  * vicfg: Include mincopies configuration.
 
  -- Joey Hess <id@joeyh.name>  Mon, 29 Aug 2022 15:03:04 -0400
 
diff --git a/Command/Vicfg.hs b/Command/Vicfg.hs
index 3d2d286391..599d067fd9 100644
--- a/Command/Vicfg.hs
+++ b/Command/Vicfg.hs
@@ -1,6 +1,6 @@
 {- git-annex command
  -
- - Copyright 2012-2017 Joey Hess <id@joeyh.name>
+ - Copyright 2012-2022 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -75,6 +75,7 @@ data Cfg = Cfg
 	, cfgScheduleMap :: M.Map UUID [ScheduledActivity]
 	, cfgGlobalConfigs :: M.Map ConfigKey ConfigValue
 	, cfgNumCopies :: Maybe NumCopies
+	, cfgMinCopies :: Maybe MinCopies
 	}
 
 getCfg :: Annex Cfg
@@ -87,6 +88,7 @@ getCfg = Cfg
 	<*> scheduleMap
 	<*> loadGlobalConfig
 	<*> getGlobalNumCopies
+	<*> getGlobalMinCopies
 
 setCfg :: Cfg -> Cfg -> Annex ()
 setCfg curcfg newcfg = do
@@ -99,6 +101,7 @@ setCfg curcfg newcfg = do
 	mapM_ (uncurry scheduleSet) $ M.toList $ cfgScheduleMap diff
 	mapM_ (uncurry setGlobalConfig) $ M.toList $ cfgGlobalConfigs diff
 	maybe noop setGlobalNumCopies $ cfgNumCopies diff
+	maybe noop setGlobalMinCopies $ cfgMinCopies diff
 
 {- Default config has all the keys from the input config, but with their
  - default values. -}
@@ -112,6 +115,7 @@ defCfg curcfg = Cfg
 	, cfgScheduleMap = mapdef $ cfgScheduleMap curcfg
 	, cfgGlobalConfigs = mapdef $ cfgGlobalConfigs curcfg
 	, cfgNumCopies = Nothing
+	, cfgMinCopies = Nothing
 	}
   where
 	mapdef :: forall k v. Default v => M.Map k v -> M.Map k v
@@ -127,6 +131,7 @@ diffCfg curcfg newcfg = Cfg
 	, cfgScheduleMap = diff cfgScheduleMap
 	, cfgGlobalConfigs = diff cfgGlobalConfigs
 	, cfgNumCopies = cfgNumCopies newcfg
+	, cfgMinCopies = cfgMinCopies newcfg
 	}
   where
 	diff f = M.differenceWith (\x y -> if x == y then Nothing else Just x)
@@ -236,6 +241,7 @@ genCfg cfg descs = unlines $ intercalate [""]
 	numcopies =
 		[ com "Numcopies configuration"
 		, line' "numcopies" (show . fromNumCopies <$> cfgNumCopies cfg)
+		, line' "mincopies" (show . fromMinCopies <$> cfgMinCopies cfg)
 		]
 	
 settings :: Ord v => Cfg -> UUIDDescMap -> (Cfg -> M.Map UUID v) -> [String] -> ((v, UUID) -> [String]) -> (UUID -> [String]) -> [String]
@@ -316,6 +322,9 @@ parseCfg defcfg = go [] defcfg . lines
 		| setting == "numcopies" = case readish val of
 			Nothing -> Left "parse error (expected an integer)"
 			Just n -> Right $ cfg { cfgNumCopies = Just (configuredNumCopies n) }
+		| setting == "mincopies" = case readish val of
+			Nothing -> Left "parse error (expected an integer)"
+			Just n -> Right $ cfg { cfgMinCopies = Just (configuredMinCopies n) }
 		| otherwise = badval "setting" setting
 	  where
 		u = toUUID f