From d6285cc0c82fb23164fe01b1571986f6bd3c6a97 Mon Sep 17 00:00:00 2001 From: Andy Davidoff Date: Tue, 25 Feb 2020 20:46:10 -0500 Subject: [PATCH] 0.7.0: nimph now supports branches --- nimph.nimble | 4 ++-- src/nimph/dependency.nim | 12 +++++++++++- src/nimph/project.nim | 30 ++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/nimph.nimble b/nimph.nimble index ea240e7..a8b69ed 100644 --- a/nimph.nimble +++ b/nimph.nimble @@ -1,4 +1,4 @@ -version = "0.6.24" +version = "0.7.0" author = "disruptek" description = "nim package handler from the future" license = "MIT" @@ -9,7 +9,7 @@ requires "bump >= 1.8.18 & < 2.0.0" requires "npeg >= 0.21.3 & < 0.23.0" requires "https://github.com/disruptek/results < 2.0.0" requires "https://github.com/disruptek/cutelog >= 1.1.0 & < 2.0.0" -requires "https://github.com/disruptek/gittyup >= 2.1.13 & < 3.0.0" +requires "https://github.com/disruptek/gittyup >= 2.4.0 & < 3.0.0" requires "https://github.com/stefantalpalaru/nim-unittest2 >= 0.0.1 & < 1.0.0" # fixup a dependency: regex 0.10.0 doesn't build with 1.0.4 stdlib diff --git a/src/nimph/dependency.nim b/src/nimph/dependency.nim index 4677d64..8b3fc18 100644 --- a/src/nimph/dependency.nim +++ b/src/nimph/dependency.nim @@ -247,9 +247,14 @@ iterator symbolicMatch*(project: Project; req: Requirement): Release = # this currently could duplicate a release emitted above, but that's okay if req.release.kind == Tag: block: + # try to find a matching oid in the current branch + for branch in project.matchingBranches(req.release.reference): + debug &"found {req.release.reference} in {project}" + yield newRelease($branch.oid, operator = Tag) repository := openRepository(project.gitDir): error &"unable to open repo at `{project.repo}`: {code.dumpError}" break + # else, it's a random oid, maybe? look it up! thing := repository.lookupThing(req.release.reference): debug &"could not find {req.release.reference} in {project}" break @@ -300,7 +305,7 @@ proc isSatisfiedBy*(req: Requirement; project: Project; release: Release): bool let oid = project.demandHead for match in req.matchingReleases(head = oid, tags = project.tags): - result = match == release + result = release == match if result: break satisfied @@ -308,6 +313,11 @@ proc isSatisfiedBy*(req: Requirement; project: Project; release: Release): bool if req.release.kind == Tag: # match against a specific oid or symbol if release.kind == Tag: + # try to find a matching branch name + for branch in project.matchingBranches(req.release.reference): + result = true + break satisfied + block: repository := openRepository(project.gitDir): error &"unable to open repo at `{project.repo}`: {code.dumpError}" diff --git a/src/nimph/project.nim b/src/nimph/project.nim index ca7b2c1..e62d664 100644 --- a/src/nimph/project.nim +++ b/src/nimph/project.nim @@ -264,6 +264,32 @@ proc shortOid(oid: GitOid; size = 6): string = else: result = short.get +template matchingBranches(project: Project; body: untyped): untyped = + block: + repository := openRepository(project.gitDir): + error &"unable to open repo at `{project.repo}`: {code.dumpError}" + break + for bref in repository.branches: + if bref.isOk: + try: + var + branch {.inject.}: GitReference = bref.get + body + finally: + free bref.get + else: + warn &"unable to fetch branch in {repository}" + +iterator matchingBranches*(project: Project; oid: GitOid): GitReference = + project.matchingBranches: + if oid == branch.oid: + yield branch + +iterator matchingBranches*(project: Project; name: string): GitReference = + project.matchingBranches: + if name == branch.branchName.split("/")[^1]: + yield branch + proc nameMyRepo(project: Project): string = ## name a repository directory in such a way that the compiler can grok it block complete: @@ -277,6 +303,10 @@ proc nameMyRepo(project: Project): string = let tag = project.tags.shortestTag($oid) # use the nimble style of project-#head when appropriate if tag == $oid: + # try to find a matching oid in the current branch + for branch in project.matchingBranches(oid): + result = project.name & "-" & "#" & branch.name.split("/")[^1] + break complete result = project.name & "-" & "#head" else: let loose = parseVersionLoosely(tag)