aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkitsunyan2018-10-22 13:26:13 +0000
committerkitsunyan2018-10-22 13:26:13 +0000
commita25e544b717edab821779b4e7d978e8bf24debcb (patch)
tree08ff14f28e0225141b1cf9c389d1fc345453a0fe /src
parentd125243edc87a4bc961c7976f73fb2248050effb (diff)
Replace package target object tree with tuples
Diffstat (limited to 'src')
-rw-r--r--src/common.nim79
-rw-r--r--src/feature/syncinfo.nim25
-rw-r--r--src/feature/syncinstall.nim48
-rw-r--r--src/feature/syncsource.nim7
4 files changed, 80 insertions, 79 deletions
diff --git a/src/common.nim b/src/common.nim
index 4412952..8be51f8 100644
--- a/src/common.nim
+++ b/src/common.nim
@@ -21,16 +21,21 @@ type
pkg: Option[SyncFoundPackageInfo]
]
- PackageTarget* = object of RootObj
- reference*: PackageReference
- repo*: Option[string]
- destination*: Option[string]
+ PackageTarget* = tuple[
+ reference: PackageReference,
+ repo: Option[string],
+ destination: Option[string]
+ ]
- SyncPackageTarget* = object of PackageTarget
- foundInfos*: seq[SyncFoundInfo]
+ SyncPackageTarget* = tuple[
+ target: PackageTarget,
+ foundInfos: seq[SyncFoundInfo]
+ ]
- FullPackageTarget* = object of SyncPackageTarget
- rpcInfo*: Option[RpcPackageInfo]
+ FullPackageTarget* = tuple[
+ sync: SyncPackageTarget,
+ rpcInfo: Option[RpcPackageInfo]
+ ]
LookupBaseGroup = tuple[
base: string,
@@ -90,31 +95,32 @@ proc packageTargets*(args: seq[Argument], parseDestination: bool): seq[PackageTa
(none(string), noDestinationTarget)
let reference = parsePackageReference(nameConstraint, false)
- PackageTarget(reference: reference, repo: repo, destination: destination)))
+ (reference, repo, destination)))
-proc isAurTargetSync*(target: SyncPackageTarget, aurRepo: string): bool =
- target.foundInfos.len == 0 and (target.repo.isNone or target.repo == some(aurRepo))
+proc isAurTargetSync*(sync: SyncPackageTarget, aurRepo: string): bool =
+ sync.foundInfos.len == 0 and (sync.target.repo.isNone or sync.target.repo == some(aurRepo))
-proc isAurTargetFull*(target: SyncPackageTarget, aurRepo: string): bool =
- target.foundInfos.len > 0 and target.foundInfos[0].repo == aurRepo
+proc isAurTargetFull*(full: FullPackageTarget, aurRepo: string): bool =
+ full.sync.foundInfos.len > 0 and full.sync.foundInfos[0].repo == aurRepo
proc filterNotFoundSyncTargets*(syncTargets: seq[SyncPackageTarget],
rpcInfos: seq[RpcPackageInfo], upToDateNeededTable: Table[string, PackageReference],
aurRepo: string): seq[SyncPackageTarget] =
let pkgInfoReferencesTable = rpcInfos.map(i => (i.name, i.toPackageReference)).toTable
- syncTargets.filter(t => not (upToDateNeededTable.opt(t.reference.name)
- .map(r => t.reference.isProvidedBy(r, true)).get(false)) and t.foundInfos.len == 0 and
- not (t.isAurTargetSync(aurRepo) and pkgInfoReferencesTable.opt(t.reference.name)
- .map(r => t.reference.isProvidedBy(r, true)).get(false)))
+ syncTargets.filter(s => not (upToDateNeededTable.opt(s.target.reference.name)
+ .map(r => s.target.reference.isProvidedBy(r, true)).get(false)) and s.foundInfos.len == 0 and
+ not (s.isAurTargetSync(aurRepo) and pkgInfoReferencesTable.opt(s.target.reference.name)
+ .map(r => s.target.reference.isProvidedBy(r, true)).get(false)))
proc printSyncNotFound*(config: Config, notFoundTargets: seq[SyncPackageTarget]) =
let dbs = config.common.dbs.toSet
- for target in notFoundTargets:
- if target.repo.isNone or target.repo == some(config.aurRepo) or target.repo.unsafeGet in dbs:
- printError(config.color, trp("target not found: %s\n") % [$target.reference])
+ for sync in notFoundTargets:
+ if sync.target.repo.isNone or sync.target.repo == some(config.aurRepo) or
+ sync.target.repo.unsafeGet in dbs:
+ printError(config.color, trp("target not found: %s\n") % [$sync.target.reference])
else:
- printError(config.color, trp("database not found: %s\n") % [target.repo.unsafeGet])
+ printError(config.color, trp("database not found: %s\n") % [sync.target.repo.unsafeGet])
proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase],
targets: seq[PackageTarget], aurRepo: string, allowGroups: bool, checkProvides: bool):
@@ -173,19 +179,20 @@ proc findSyncTargets*(handle: ptr AlpmHandle, dbs: seq[ptr AlpmDatabase],
else:
return @[]
- let syncTargets = targets.map(t => SyncPackageTarget(reference: t.reference,
- repo: t.repo, destination: t.destination, foundInfos: findSync(t)))
- let checkAurNames = syncTargets.filter(t => t.isAurTargetSync(aurRepo)).map(t => t.reference.name)
+ let syncTargets: seq[SyncPackageTarget] = targets.map(t => (t, findSync(t)))
+ let checkAurNames = syncTargets
+ .filter(s => s.isAurTargetSync(aurRepo))
+ .map(s => s.target.reference.name)
(syncTargets, checkAurNames)
proc mapAurTargets*(targets: seq[SyncPackageTarget], rpcInfos: seq[RpcPackageInfo],
aurRepo: string): seq[FullPackageTarget] =
let aurTable = rpcInfos.map(i => (i.name, i)).toTable
- targets.map(proc (target: SyncPackageTarget): FullPackageTarget =
- let res = if target.foundInfos.len == 0 and aurTable.hasKey(target.reference.name): (block:
- let rpcInfo = aurTable[target.reference.name]
- if target.reference.isProvidedBy(rpcInfo.toPackageReference, true):
+ targets.map(proc (sync: SyncPackageTarget): FullPackageTarget =
+ let res = if sync.foundInfos.len == 0 and aurTable.hasKey(sync.target.reference.name): (block:
+ let rpcInfo = aurTable[sync.target.reference.name]
+ if sync.target.reference.isProvidedBy(rpcInfo.toPackageReference, true):
some(((aurRepo, some((rpcInfo.base, rpcInfo.version, none(string)))), rpcInfo))
else:
none((SyncFoundInfo, RpcPackageInfo)))
@@ -194,13 +201,9 @@ proc mapAurTargets*(targets: seq[SyncPackageTarget], rpcInfos: seq[RpcPackageInf
if res.isSome:
let (syncInfo, rpcInfo) = res.get
- FullPackageTarget(reference: target.reference, repo: target.repo,
- destination: target.destination, foundInfos: @[syncInfo],
- rpcInfo: some(rpcInfo))
+ ((sync.target, @[syncInfo]), some(rpcInfo))
else:
- FullPackageTarget(reference: target.reference, repo: target.repo,
- destination: target.destination, foundInfos: target.foundInfos,
- rpcInfo: none(RpcPackageInfo)))
+ (sync, none(RpcPackageInfo)))
proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptional: bool,
assumeExplicit: HashSet[string]): (seq[PackageReference], HashSet[string], HashSet[string],
@@ -264,7 +267,7 @@ proc queryUnrequired*(handle: ptr AlpmHandle, withOptional: bool, withoutOptiona
(installed, withOptionalSet, withoutOptionalSet, alternatives)
-proc `$`*[T: PackageTarget](target: T): string =
+proc `$`*(target: PackageTarget): string =
target.repo.map(proc (r: string): string = r & "/" & $target.reference).get($target.reference)
template tmpRoot(config: Config, dropPrivileges: bool): string =
@@ -640,13 +643,13 @@ proc obtainBuildPkgInfos*(config: Config, pacmanTargets: seq[FullPackageTarget],
progressCallback: (int, int) -> void, dropPrivileges: bool):
(seq[PackageInfo], seq[string], seq[string]) =
let bases = pacmanTargets
- .map(proc (target: FullPackageTarget): LookupBaseGroup =
- let info = target.foundInfos[0]
+ .map(proc (full: FullPackageTarget): LookupBaseGroup =
+ let info = full.sync.foundInfos[0]
let pkg = info.pkg.get
(pkg.base, pkg.version, pkg.arch.get, info.repo))
.deduplicate
- let pacmanTargetNames = pacmanTargets.map(t => t.reference.name)
+ let pacmanTargetNames = pacmanTargets.map(f => f.sync.target.reference.name)
obtainBuildPkgInfosInternal(config, bases, pacmanTargetNames, progressCallback, dropPrivileges)
proc cloneAurRepo*(config: Config, base: string, gitUrl: string,
diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim
index 39d682a..9bee287 100644
--- a/src/feature/syncinfo.nim
+++ b/src/feature/syncinfo.nim
@@ -57,9 +57,9 @@ proc formatDate(date: int64): Option[string] =
if res > 0: some(buffer.toString(none(int))) else: none(string)
proc handleTarget(config: Config, padding: int, args: seq[Argument],
- target: FullPackageTarget, pkgInfoOption: Option[PackageInfo]): int =
- if target.foundInfos.len > 0:
- if isAurTargetFull(target, config.aurRepo):
+ full: FullPackageTarget, pkgInfoOption: Option[PackageInfo]): int =
+ if full.sync.foundInfos.len > 0:
+ if full.isAurTargetFull(config.aurRepo):
let pkgInfo = pkgInfoOption.get
printPackageInfo(padding, config.color,
@@ -86,19 +86,19 @@ proc handleTarget(config: Config, padding: int, args: seq[Argument],
(tr"Rating", @[formatPkgRating(pkgInfo.rpc.votes, pkgInfo.rpc.popularity)], false))
0
- elif target.reference.constraint.isSome:
+ elif full.sync.target.reference.constraint.isSome:
# pacman doesn't support constraints for --info queries
- pacmanRun(false, config.color, args & target.foundInfos.map(i =>
- (i.repo & "/" & target.reference.name, none(string), ArgumentType.target)))
+ pacmanRun(false, config.color, args & full.sync.foundInfos.map(i =>
+ (i.repo & "/" & full.sync.target.reference.name, none(string), ArgumentType.target)))
else:
pacmanRun(false, config.color, args &
- ($target, none(string), ArgumentType.target))
+ ($full.sync.target, none(string), ArgumentType.target))
else:
- if target.repo == some(config.aurRepo):
- printError(config.color, trp("package '%s' was not found\n") % [$target])
+ if full.sync.target.repo == some(config.aurRepo):
+ printError(config.color, trp("package '%s' was not found\n") % [$full.sync.target])
1
else:
- pacmanRun(false, config.color, args & ($target, none(string), ArgumentType.target))
+ pacmanRun(false, config.color, args & ($full.sync.target, none(string), ArgumentType.target))
proc handleSyncInfo*(args: seq[Argument], config: Config): int =
let (refreshCode, callArgs) = checkAndRefresh(config.color, args)
@@ -118,8 +118,9 @@ proc handleSyncInfo*(args: seq[Argument], config: Config): int =
let fullTargets = mapAurTargets(syncTargets, pkgInfos.map(p => p.rpc), config.aurRepo)
let code = min(aerrors.len, 1)
- if fullTargets.filter(t => isAurTargetFull(t, config.aurRepo) or
- t.repo == some(config.aurRepo) or t.reference.constraint.isSome).len == 0:
+ if fullTargets.filter(f => f.isAurTargetFull(config.aurRepo) or
+ f.sync.target.repo == some(config.aurRepo) or
+ f.sync.target.reference.constraint.isSome).len == 0:
if code == 0:
pacmanExec(false, config.color, callArgs)
else:
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index 19fd3ce..1f079ee 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -818,8 +818,7 @@ proc removeBuildDependencies(config: Config, commonArgs: seq[Argument],
printColon(config.color, tr"Removing build dependencies...")
pacmanRun(true, config.color, removeArgs &
("R", none(string), ArgumentType.short) &
- toSeq(unrequired.items).map(t =>
- (t, none(string), ArgumentType.target))))
+ toSeq(unrequired.items).map(t => (t, none(string), ArgumentType.target))))
else:
0
@@ -827,8 +826,7 @@ proc removeBuildDependencies(config: Config, commonArgs: seq[Argument],
printColon(config.color, tr"Removing optional build dependencies...")
pacmanRun(true, config.color, removeArgs &
("R", none(string), ArgumentType.short) &
- toSeq(unrequiredOptional.items).map(t =>
- (t, none(string), ArgumentType.target)))
+ toSeq(unrequiredOptional.items).map(t => (t, none(string), ArgumentType.target)))
else:
code)
else:
@@ -941,7 +939,7 @@ proc obtainAurPackageInfos(config: Config, rpcInfos: seq[RpcPackageInfo],
printMode: bool, needed: bool, upgradeCount: int): (seq[PackageInfo], seq[PackageInfo],
seq[string], seq[Installed], seq[LocalIsNewer], seq[string]) =
let targetRpcInfoPairs: seq[tuple[rpcInfo: RpcPackageInfo, upgradeable: bool]] =
- rpcAurTargets.map(t => t.rpcInfo.get).map(i => (i, installed
+ rpcAurTargets.map(f => f.rpcInfo.get).map(i => (i, installed
.checkNeeded(i.name, i.version, true).needed))
let upToDateNeeded: seq[Installed] = if needed:
@@ -957,7 +955,7 @@ proc obtainAurPackageInfos(config: Config, rpcInfos: seq[RpcPackageInfo],
let installedUpgradeRpcInfos = rpcInfos.filter(i => upgradeCount > 0 and (block:
let reference = i.toPackageReference
- rpcAurTargets.filter(t => t.reference.isProvidedBy(reference, true)).len == 0))
+ rpcAurTargets.filter(f => f.sync.target.reference.isProvidedBy(reference, true)).len == 0))
let upgradeStructs: seq[tuple[rpcInfo: RpcPackageInfo, needed: bool,
localIsNewer: Option[LocalIsNewer]]] = installedUpgradeRpcInfos
@@ -1003,21 +1001,21 @@ proc obtainPacmanBuildTargets(config: Config, pacmanTargets: seq[FullPackageTarg
(bool, seq[PackageInfo], seq[(string, string)], seq[string], seq[string]) =
let (neededPacmanBuildTargets, buildUpToDateNeeded) = if not printMode and
build and needed: (block:
- let neededPairs: seq[tuple[target: FullPackageTarget,
- skipVersion: Option[string]]] = pacmanTargets.map(target => (block:
- let version = target.foundInfos[0].pkg.get.version
- if installedTable.checkNeeded(target.reference.name, version, true).needed:
- (target, none(string))
+ let neededPairs: seq[tuple[full: FullPackageTarget,
+ skipVersion: Option[string]]] = pacmanTargets.map(full => (block:
+ let version = full.sync.foundInfos[0].pkg.get.version
+ if installedTable.checkNeeded(full.sync.target.reference.name, version, true).needed:
+ (full, none(string))
else:
- (target, some(version))))
+ (full, some(version))))
let neededPacmanBuildTargets = neededPairs
.filter(p => p.skipVersion.isNone)
- .map(p => p.target)
+ .map(p => p.full)
let buildUpToDateNeeded = neededPairs
.filter(p => p.skipVersion.isSome)
- .map(p => (p.target.reference.name, p.skipVersion.unsafeGet))
+ .map(p => (p.full.sync.target.reference.name, p.skipVersion.unsafeGet))
(neededPacmanBuildTargets, buildUpToDateNeeded))
else:
@@ -1076,7 +1074,7 @@ proc resolveBuildTargets(config: Config, syncTargets: seq[SyncPackageTarget],
@[]
let installedTable = installed.map(i => (i.name, i)).toTable
- let rpcAurTargets = fullTargets.filter(t => t.isAurTargetFull(config.aurRepo))
+ let rpcAurTargets = fullTargets.filter(f => f.isAurTargetFull(config.aurRepo))
let targetRpcInfos = lc[x | (t <- rpcAurTargets, x <- t.rpcInfo), RpcPackageInfo]
let targetRpcInfoNames = targetRpcInfos.map(i => i.name).toSet
@@ -1098,11 +1096,11 @@ proc resolveBuildTargets(config: Config, syncTargets: seq[SyncPackageTarget],
errorResult
else:
let fullTargets = mapAurTargets(syncTargets
- .filter(t => not (upToDateNeededTable.opt(t.reference.name)
- .map(r => t.reference.isProvidedBy(r, true)).get(false))),
+ .filter(s => not (upToDateNeededTable.opt(s.target.reference.name)
+ .map(r => s.target.reference.isProvidedBy(r, true)).get(false))),
aurPkgInfos.map(p => p.rpc), config.aurRepo)
- let pacmanTargets = fullTargets.filter(t => not isAurTargetFull(t, config.aurRepo))
- let aurTargets = fullTargets.filter(t => isAurTargetFull(t, config.aurRepo))
+ let pacmanTargets = fullTargets.filter(f => not f.isAurTargetFull(config.aurRepo))
+ let aurTargets = fullTargets.filter(f => f.isAurTargetFull(config.aurRepo))
let (checkPacmanBuildPkgInfos, buildPkgInfos, buildUpToDateNeeded, buildPaths,
obtainBuildErrorMessages) = obtainPacmanBuildTargets(config, pacmanTargets, installedTable,
@@ -1116,7 +1114,7 @@ proc resolveBuildTargets(config: Config, syncTargets: seq[SyncPackageTarget],
else:
let pkgInfos = (buildPkgInfos & aurPkgInfos)
.deduplicatePkgInfos(config, not printMode)
- let targetNamesSet = (pacmanTargets & aurTargets).map(t => t.reference.name).toSet
+ let targetNamesSet = (pacmanTargets & aurTargets).map(f => f.sync.target.reference.name).toSet
let (finalPkgInfos, acceptedPkgInfos) = filterIgnoresAndConflicts(config, pkgInfos,
targetNamesSet, installedTable, printMode, noconfirm)
@@ -1137,9 +1135,9 @@ proc assumeInstalled(args: seq[Argument]): seq[PackageReference] =
proc handleInstall(args: seq[Argument], config: Config, syncTargets: seq[SyncPackageTarget],
fullTargets: seq[FullPackageTarget], upgradeCount: int, nodepsCount: int,
wrapUpgrade: bool, noconfirm: bool, needed: bool, build: bool, noaur: bool): int =
- let pacmanTargets = fullTargets.filter(t => not isAurTargetFull(t, config.aurRepo))
+ let pacmanTargets = fullTargets.filter(f => not f.isAurTargetFull(config.aurRepo))
- let workDirectPacmanTargets = if build: @[] else: pacmanTargets.map(`$`)
+ let workDirectPacmanTargets = if build: @[] else: pacmanTargets.map(f => $f.sync.target)
# check for sysupgrade instead of upgradeCount since upgrade could be done before
# and then removed from the list of arguments
@@ -1265,7 +1263,7 @@ proc handleInstall(args: seq[Argument], config: Config, syncTargets: seq[SyncPac
else:
code
else:
- let aurTargets = fullTargets.filter(t => isAurTargetFull(t, config.aurRepo))
+ let aurTargets = fullTargets.filter(f => f.isAurTargetFull(config.aurRepo))
if (not noaur and (aurTargets.len > 0 or upgradeCount > 0)) or build:
echo(trp(" there is nothing to do\n"))
clearPaths(paths)
@@ -1274,8 +1272,8 @@ proc handleInstall(args: seq[Argument], config: Config, syncTargets: seq[SyncPac
proc handlePrint(args: seq[Argument], config: Config, syncTargets: seq[SyncPackageTarget],
fullTargets: seq[FullPackageTarget], upgradeCount: int, nodepsCount: int,
needed: bool, build: bool, noaur: bool, printFormat: string): int =
- let pacmanTargets = fullTargets.filter(t => not isAurTargetFull(t, config.aurRepo))
- let directPacmanTargets = pacmanTargets.map(`$`)
+ let pacmanTargets = fullTargets.filter(f => not f.isAurTargetFull(config.aurRepo))
+ let directPacmanTargets = pacmanTargets.map(f => $f.sync.target)
let (resolveTargetsCode, _, _, pkgInfos, additionalPkgInfos, _) = resolveBuildTargets(config,
syncTargets, fullTargets, false, true, upgradeCount, true, needed, noaur, build)
diff --git a/src/feature/syncsource.nim b/src/feature/syncsource.nim
index 20ff56f..b080aff 100644
--- a/src/feature/syncsource.nim
+++ b/src/feature/syncsource.nim
@@ -117,17 +117,16 @@ proc cloneAndCopy(config: Config, quiet: bool, fullTargets: seq[FullPackageTarge
if rpcInfo.base in bases:
a
else:
- a & (rpcInfo.base, rpcInfo.version, b.destination.get(rpcInfo.base),
+ a & (rpcInfo.base, rpcInfo.version, b.sync.target.destination.get(rpcInfo.base),
some(rpcInfo.gitUrl), none(GitRepo))
else:
- let foundInfo = b.foundInfos[0]
+ let foundInfo = b.sync.foundInfos[0]
let pkg = foundInfo.pkg.get
if pkg.base in bases:
a
else:
let git = lookupGitRepo(foundInfo.repo, pkg.base, pkg.arch.get)
- a & (pkg.base, pkg.version, b.destination.get(pkg.base),
- none(string), git),
+ a & (pkg.base, pkg.version, b.sync.target.destination.get(pkg.base), none(string), git),
newSeq[BaseTarget]())
let (update, terminate) = if quiet: