Skip to content

Commit

Permalink
simplifies folder restoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgomez committed Nov 27, 2024
1 parent 66bcb7b commit 12d2f3e
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/nimblepkg/nimblesat.nim
Original file line number Diff line number Diff line change
Expand Up @@ -482,20 +482,18 @@ proc saveTaggedVersions*(repoDir: string, taggedVersions: TaggedPackageVersions)
except CatchableError as e:
displayWarning(&"Error saving tagged versions: {e.msg}", HighPriority)

proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, downloadMethod: DownloadMethod, options: Options): seq[PackageMinimalInfo] =
proc getPackageMinimalVersionsFromRepo*(repoDir: string, name: string, version: Version, downloadMethod: DownloadMethod, options: Options): seq[PackageMinimalInfo] =
#This is expensive. We need to cache it. Potentially it could be also run in parallel
# echo &"Discovering version for {pkgName}"
let taggedVersions = getTaggedVersions(repoDir, options)
if taggedVersions.isSome:
return taggedVersions.get.versions
gitFetchTags(repoDir, downloadMethod)
var lastMinimalInfo = none(PackageMinimalInfo)
#First package must be the current one
try:
lastMinimalInfo = some getPkgInfo(repoDir, options).getMinimalInfo(options)
result.add lastMinimalInfo.get
result.add getPkgInfo(repoDir, options).getMinimalInfo(options)
except CatchableError as e:
displayWarning(&"Error getting package info for {pkgName}: {e.msg}", HighPriority)
displayWarning(&"Error getting package info for {name}: {e.msg}", HighPriority)
let tags = getTagsList(repoDir, downloadMethod).getVersionList()
var checkedTags = 0
for (ver, tag) in tags.pairs:
Expand All @@ -508,16 +506,15 @@ proc getPackageMinimalVersionsFromRepo*(repoDir, pkgName: string, downloadMethod
doCheckout(downloadMethod, repoDir, tag)
let nimbleFile = findNimbleFile(repoDir, true, options)
let pkgInfo = getPkgInfoFromFile(nimbleFile, options, useCache=false)
lastMinimalInfo = some pkgInfo.getMinimalInfo(options)
result.addUnique lastMinimalInfo.get()
result.addUnique pkgInfo.getMinimalInfo(options)
except CatchableError as e:
displayWarning(&"Error reading tag {tag}: for package {pkgName}. This may not be relevant as it could be an old version of the package. \n {e.msg}", HighPriority)
displayWarning(&"Error reading tag {tag}: for package {name}. This may not be relevant as it could be an old version of the package. \n {e.msg}", HighPriority)

#make sure we let this folder as it was
if lastMinimalInfo.isSome:
for (ver, tag) in tags.pairs:
if ver == lastMinimalInfo.get.version:
doCheckout(downloadMethod, repoDir, tag)
for (ver, tag) in tags.pairs:
if ver == version:
doCheckout(downloadMethod, repoDir, tag)

saveTaggedVersions(repoDir, TaggedPackageVersions(maxTaggedVersions: options.maxTaggedVersions, versions: result))

proc downloadMinimalPackage*(pv: PkgTuple, options: Options): seq[PackageMinimalInfo] =
Expand All @@ -527,7 +524,7 @@ proc downloadMinimalPackage*(pv: PkgTuple, options: Options): seq[PackageMinimal
result = @[downloadPkInfoForPv(pv, options).getMinimalInfo(options)]
else:
let (downloadRes, downloadMeth) = downloadPkgFromUrl(pv, options)
result = getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadMeth, options)
result = getPackageMinimalVersionsFromRepo(downloadRes.dir, pv.name, downloadRes.version, downloadMeth, options)
# echo "Downloading minimal package for ", pv.name, " ", $pv.ver, result

proc fillPackageTableFromPreferred*(packages: var Table[string, PackageVersions], preferredPackages: seq[PackageMinimalInfo]) =
Expand Down

0 comments on commit 12d2f3e

Please sign in to comment.