Skip to content

Conversation

straight-shoota
Copy link
Member

This also enables full-length commit hash reporting for dependencies. Maybe we could use abbreviated hashes in non-critical situations (such as error messages), but I think it might actually be better to always be explicit. Otherwise there's no indication whether the actual hash value is abbreviated or it's only abbreviated for display.

Resolves #384

@waj
Copy link
Member

waj commented May 9, 2020

Thanks @straight-shoota! I was working on a similar fix already 😅, but I like the operator you used for the comparison.

However, I'm not sure about displaying the full hash when installing. I think it's unnecessary because if it works correctly it's because there was a match with the ref. I might only want to see the value so I can make a quick check if the right commits was selected (and GitHub shows the first 7 digits as well, so the visual match is easier). Bundler does a similar thing. It shows the first 7 chars of the hash, no matter how many digits were given in the Gemfile:

Using json 2.3.0 from https://github.com/flori/json (at master@da50acc)

When there is an error, it's different, because the user needs to understand why the value didn't match:

Revision ffffffffffffffff does not exist in the repository https://github.com/flori/json. Maybe you misspelled it?

The two values live in different objects in Shards. The value that was matched is always a Version (a unequivocal identifier of a single version), while the value given by the user in shards.yml is a GitCommitRef in this case. In other words, I think commit hash from Version, which is always full no matter what the user provides, must be abbreviated (look at GitResolver#report_version), while the GitCommitRef which is only printed on diagnostics or error messages, must be always full.

@@ -46,12 +46,16 @@ module Shards
def initialize(@commit : String)
end

def =~(other : GitCommitRef)
commit.size >= 7 && other.commit.starts_with?(commit)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why impose this minimum limit? I think git accepts a minimum of 4 digits if there is no conflicts.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At this point it's not trivial to check whether there are no conflicts. With a minimum size of 7 the probability for a conflict is very low.

I don't think that's the correct solution though. If we keep this behaviour it should already fail when reading a hash that is too short for comparison.
But a better solution would probably to check whether the abbreviated commit is actually conflict-free by asking git to resolve it. Then we can be sure that the starts_with? match is valid.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because at that point it shouldn't make any assumptions at all. It would be correct even allowing no minimum size for the hash. The resolution will fail at a different place if there is not matching commit or if there is a conflict.

The second part is already being done, although it could handle the error differently to show a more meaningful message. For example, when the hash is incorrect or have conflicts it's currently showing:

Unable to satisfy the following requirements:

- `db (commit abcdef)` required by `shard.yml`

That's because GitResolver already returned an empty set for the available versions.

def to_git_ref
@commit
end

def to_s(io)
io << "commit " << @commit[0...7]
def to_s(io, *, commit_length = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this commit_length argument is in use

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I originally wanted to use that to display different lengths depending on context, but decided that's too complex for this fix PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, check my comment: #386 (comment)

Actually I think the right way to solve this is raise an error with a better message at latest_version_for_ref when there is no available matches, (instead of returning nil). That message should contain the exact input read from the shard.yml. And leave here the abbreviated commit. At that point it will be used only to show conflicts with other dependencies, but already knowing the commit exists.

@straight-shoota
Copy link
Member Author

straight-shoota commented May 9, 2020

@waj do you want to take over? You probably know better how to deal with this.
I just thought it was quick and easy and wanted to help out 😆

@waj
Copy link
Member

waj commented May 9, 2020

@straight-shoota absolutely! 😄 I'll schedule some time to write some docs too.

@waj
Copy link
Member

waj commented May 12, 2020

Superseded by #388 and #389

@waj waj closed this May 12, 2020
@straight-shoota straight-shoota deleted the fix/commit-version-restriction branch May 12, 2020 22:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commit version restriction cannot be resolved
2 participants