mergestat-lite icon indicating copy to clipboard operation
mergestat-lite copied to clipboard

tweak the behavior of the `hash` column in the `refs` table when dealing with `tags`

Open patrickdevivo opened this issue 3 years ago β€’ 3 comments

if the ref is an annotated tag, output the hash of the object it is pointing to instead of its own hash. This makes it easier to deal with lightweight and annotated tags when querying the refs table, as the hash column will always point to a commit (and can be joined with the commits table)

@riyaz-ali what do you think? Is this weird to do?

The purpose would be such that

SELECT * FROM refs JOIN commits USING(hash)
WHERE type = 'tag'

Would work for both annotated and lightweight tags, where now it only works for lightweight

patrickdevivo avatar Dec 04 '21 04:12 patrickdevivo

Codecov Report

Merging #217 (6144fe8) into main (0407ab9) will decrease coverage by 0.05%. The diff coverage is 57.14%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #217      +/-   ##
==========================================
- Coverage   69.82%   69.76%   -0.06%     
==========================================
  Files          47       47              
  Lines        2505     2510       +5     
==========================================
+ Hits         1749     1751       +2     
- Misses        481      482       +1     
- Partials      275      277       +2     
Impacted Files Coverage Ξ”
extensions/internal/git/refs.go 73.11% <57.14%> (-1.89%) :arrow_down:

Continue to review full report at Codecov.

Legend - Click here to learn more Ξ” = absolute <relative> (impact), ΓΈ = not affected, ? = missing data Powered by Codecov. Last update 0407ab9...6144fe8. Read the comment docs.

codecov-commenter avatar Dec 04 '21 04:12 codecov-commenter

The change looks good, but how will one fetch the hash of the tag object if they need to?

riyaz-ali avatar Dec 04 '21 12:12 riyaz-ali

Also, there's a COMMIT_FROM_TAG scalar function that gives you the hash of the commit pointed to by the tag. I believe you can combine that with CASE...WHEN to achieve the same result?

The function referred can be found at extensions/git/internal/refs_func.go

riyaz-ali avatar Dec 04 '21 12:12 riyaz-ali