sindrets / diffview.nvim

Single tabpage interface for easily cycling through diffs for all modified files for any git rev.
Other
3.74k stars 105 forks source link

Mercurial version is outdated! #363

Closed Pagliacii closed 1 year ago

Pagliacii commented 1 year ago

hg version output:

Mercurial Distributed SCM (version 6.3.1+hg4.c44f350759c3)
(see https://mercurial-scm.org for more information)

Copyright (C) 2005-2022 Olivia Mackall and others
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

But when using :DiffviewOpen on a hg repo, the "Mercurial version is outdated!" error will be popup.

After reading source code, I found that the version_ok function has a bug:

https://github.com/sindrets/diffview.nvim/blob/bff58a6ea3e081ca50049700f9848b2f84ea57be/lua/diffview/vcs/adapters/hg/init.lua#L73-L82

In my case, the v.major is 6 and it was greater than the target.major, which is 5. But the v.minor is 3 that was less than the target.minor, which is 4. And it causes the version_ok is false.

Seems the correct logic is:

 local version_ok = (function() 
   if v.major < target.major then 
     return false
   elseif v.major == target.major and v.minor < target.minor then 
     return false
   elseif v.major == target.major and v.minor == target.minor and v.patch < target.patch then 
     return false 
   end 
   return true 
 end)() 

And the match pattern could not extract the correct version digits:

  bs.version_string = out[1] and out[1]:match("Mercurial .*%(version (%S+)%)") or nil

The bs.version_string is 6.3.1+hg4.c44f350759c3 in my case. I think the match pattern should be "Mercurial .*%(version (%d%.%d%.%d).*%)".