Skip to content

Commit

Permalink
Merge pull request #249 from crystal-lang/rework-and-fix-natural-sort
Browse files Browse the repository at this point in the history
Implements pre-releases
  • Loading branch information
ysbaddaden authored Jan 11, 2019
2 parents d0fa97c + ccd53b5 commit 301c0ff
Show file tree
Hide file tree
Showing 17 changed files with 478 additions and 118 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

## UNRELEASED

Features:
- Experimental support for prereleases. Add a letter to a version number to
declare a pre-release. For example `1.2.3.alpha` or `1.0.0-rc1`.

Fixes:
- Approximate operator used to match invalid version numbers (e.g. `~> 0.1.0`
wrongly matched `0.10.0`).
- Unbalanced version numbers, such as `1.0.0` and `1.0.0.1` are now correctly
ordered and compared as `1.0.0.1 > 1.0.0`.
- `install -t` isn't supported on macOS.

## v0.8.1 - 2018-06-17
Expand Down
3 changes: 2 additions & 1 deletion SPEC.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ The version number of the library (String, required).

- It must contain digits.
- It may contain dots and dashes but not consecutive ones.
- It may contain a letter to make it a 'prerelease'.

Examples: `1.2.3`, `2.0.0-rc1` or `2016.09`.
Examples: `1.2.3`, `2.0.0.1`, `1.0.0.alpha` `2.0.0-rc1` or `2016.09`.

While Shards doesn't enforce it, following a rational versioning scheme like
[Semantic Versioning](http://semver.org/) or [Calendar Versioning](http://calver.org/)
Expand Down
10 changes: 0 additions & 10 deletions src/cli.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ module Shards
Options:
HELP
puts opts
# info <package>
# search <query>
# update [package package ...]
exit
end

Expand All @@ -42,9 +39,6 @@ module Shards
build(path, args[1..-1])
when "check"
Commands::Check.run(path)
#when "info"
# display_help_and_exit(opts) unless args[1]?
# Commands::Info.run(args[1])
when "init"
Commands::Init.run(path)
when "install"
Expand All @@ -53,12 +47,8 @@ module Shards
Commands::List.run(path, tree: args.includes?("--tree"))
when "prune"
Commands::Prune.run(path)
# when "search"
# display_help_and_exit(opts) unless args[1]?
# Commands::Search.run(path, args[1])
when "update"
Commands::Update.run(path)
# Commands.update(path, *args[1..-1])
when "version"
Commands::Version.run(args[1]? || path)
else
Expand Down
8 changes: 3 additions & 5 deletions src/commands/check.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require "../helpers/versions"
require "./command"
require "../versions"

module Shards
module Commands
class Check < Command
include Helpers::Versions

def run(*args)
if has_dependencies?
locks # ensures that lockfile exists
Expand Down Expand Up @@ -45,7 +43,7 @@ module Shards
end

if version = lock["version"]?
if resolve_requirement([version], dependency.version).empty?
if Versions.resolve([version], dependency.version).empty?
Shards.logger.debug { "#{dependency.name}: lock conflict" }
return false
else
Expand All @@ -61,7 +59,7 @@ module Shards
# end
#end

if resolve_requirement([spec.version], dependency.version).empty?
if Versions.resolve([spec.version], dependency.version).empty?
Shards.logger.debug { "#{dependency.name}: version mismatch" }
return false
end
Expand Down
1 change: 0 additions & 1 deletion src/commands/list.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "../helpers/versions"
require "./command"

module Shards
Expand Down
1 change: 0 additions & 1 deletion src/commands/version.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "../helpers/versions"
require "./command"

module Shards
Expand Down
3 changes: 3 additions & 0 deletions src/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ module Shards
DEFAULT_COMMAND = "install"
DEFAULT_VERSION = "0"

VERSION_REFERENCE = /^v?\d+[-.][-.a-zA-Z\d]+$/
VERSION_TAG = /^v(\d+[-.][-.a-zA-Z\d]+)$/

def self.cache_path
@@cache_path ||= find_or_create_cache_path
end
Expand Down
38 changes: 0 additions & 38 deletions src/helpers/natural_sort.cr

This file was deleted.

46 changes: 0 additions & 46 deletions src/helpers/versions.cr

This file was deleted.

6 changes: 2 additions & 4 deletions src/package.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require "file_utils"
require "./resolvers/*"
require "./helpers/versions"
require "./versions"

module Shards
class Package
include Helpers::Versions

getter requirements : Array(String)
@resolver : Resolver?
@available_versions : Array(String)?
Expand Down Expand Up @@ -43,7 +41,7 @@ module Shards
end

def matching_versions
resolve_versions(available_versions, requirements)
Versions.resolve(available_versions, requirements)
end

def spec
Expand Down
10 changes: 3 additions & 7 deletions src/resolvers/git.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
require "uri"
require "./resolver"
require "../helpers/natural_sort"
require "../versions"
require "../helpers/path"

module Shards
VERSION_REFERENCE = /^v?[\d\.]+$/

class GitResolver < Resolver
@@has_git_command : Bool?
@@git_column_never : String?
Expand All @@ -29,7 +27,7 @@ module Shards
end

protected def self.git_column_never
@@git_column_never ||= Helpers::NaturalSort.sort(git_version, "1.7.11") < 0 ? "--column=never" : ""
@@git_column_never ||= Versions.compare(git_version, "1.7.11") < 0 ? "--column=never" : ""
end

def read_spec(version = "*")
Expand Down Expand Up @@ -60,14 +58,12 @@ module Shards
end
end

RELEASE_VERSION_TAG = /^v([\d\.]+)$/

protected def versions_from_tags(refs = nil)
options = "--contains #{refs}" if refs

capture("git tag --list #{options} #{GitResolver.git_column_never}")
.split('\n')
.compact_map { |tag| $1 if tag =~ RELEASE_VERSION_TAG }
.compact_map { |tag| $1 if tag =~ VERSION_TAG }
end

def matches?(commit)
Expand Down
Loading

0 comments on commit 301c0ff

Please sign in to comment.