Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix check version #1103

Merged
merged 5 commits into from
Feb 9, 2021
Merged

fix check version #1103

merged 5 commits into from
Feb 9, 2021

Conversation

bnkai
Copy link
Collaborator

@bnkai bnkai commented Feb 3, 2021

On rare occasions git rev-parse --short HEAD generates a longer than the default 7 characters short hash
I adjusted the version check code to take that into account

I added also an extra debug print for statistical reasons in case this occurs
eg

DEBU[0000] Short Hash:0dd2e269 Length:8 differs from default 7
INFO[0000] Version: (0dd2e269) is already the latest released.

to force the issue for testing you can either export the needed > 7 chars GITHASH or just do a GITHASH=0dd2e269 make pre-ui && GITHASH=0dd2e269 make release
0dd2e269 is used to match the current (as of testing) dev build/commit hash

@WithoutPants WithoutPants added the bug Something isn't working label Feb 3, 2021
@WithoutPants WithoutPants added this to the Version 0.5.0 milestone Feb 3, 2021
@WithoutPants
Copy link
Collaborator

Is there much point doing all the length checking and logging? Can't we just use the length of the current version short hash as the end point for the sha substring (with some sanity checking I guess)?

@bnkai
Copy link
Collaborator Author

bnkai commented Feb 4, 2021

I have removed the debug prints and tweaked a bit the sanity check.
For the checks we need at least one check to make sure no out of bounds exception exists ( check index < legth of sliced string)
I 've included the second one as a sanity one ( default length 7 ) as this is the default minimal that git uses and that happens to be the same (fixed this time) that github uses.Using that makes sure we have a fallback with the 7 first digits of the hash.

what remains is like this

        if shortHash {
                last := defaultSHLength 
                _, gitShort, _ := GetVersion() 
                if len(gitShort) > last && len(gitShort) < shaLength { 
                        last = len(gitShort)
                }
                return release.Target_commitish[0:last]
        }

setting by default to the length of the gitShort hash would give something like that

if shortHash {
   _, gitShort, _ := GetVersion() 
   last := len(gitShort)
  if last > shaLength  || last < defaultSHLength { //index+sanity check
            last = defaultSHLength
            }
   return release.Target_commitish[0:last]
} 

If we partially skip the sanity check
we can just do

if shortHash {
   _, gitShort, _ := GetVersion() 
   last := len(gitShort)
  if last > shaLength { // index check
               last = defaultSHLength 
                }
   return release.Target_commitish[0:last]
} 

which imo isnt a big difference
I would prefer one of the two first options or some other more efficient if possible (i couldnt think of anything else)

@WithoutPants WithoutPants merged commit bcbbd14 into stashapp:develop Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants