Skip to content

Commit

Permalink
0.7.0: nimph now supports branches
Browse files Browse the repository at this point in the history
  • Loading branch information
disruptek committed Feb 26, 2020
1 parent 42b451e commit d6285cc
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions nimph.nimble
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = "0.6.24"
version = "0.7.0"
author = "disruptek"
description = "nim package handler from the future"
license = "MIT"
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/nimph/dependency.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -300,14 +305,19 @@ 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

# this is really our last gasp opportunity for a Tag requirement
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}"
Expand Down
30 changes: 30 additions & 0 deletions src/nimph/project.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down

0 comments on commit d6285cc

Please sign in to comment.