Skip to content

Commit f68af40

Browse files
authored
feat: make git diff algorithm configurable (#434)
Signed-off-by: Luis Davim <luis.davim@gmail.com>
1 parent 5990a99 commit f68af40

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

lua/vgit/git/git_hunks.lua

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ local fs = require('vgit.core.fs')
22
local utils = require('vgit.core.utils')
33
local gitcli = require('vgit.git.gitcli')
44
local GitHunk = require('vgit.git.GitHunk')
5+
local git_setting = require('vgit.settings.git')
56

6-
local git_hunks = { algorithm = 'myers' }
7+
local git_hunks = {}
78

89
function git_hunks.live(reponame, original_lines, current_lines)
910
local lines_limit = 5000
@@ -57,7 +58,7 @@ function git_hunks.live(reponame, original_lines, current_lines)
5758

5859
live_hunks[#live_hunks + 1] = hunk
5960
end,
60-
algorithm = git_hunks.algorithm,
61+
algorithm = git_setting:get('algorithm'),
6162
})
6263

6364
return live_hunks
@@ -113,7 +114,7 @@ function git_hunks.list(reponame, opts)
113114
'core.safecrlf=false',
114115
'diff',
115116
'--color=never',
116-
string.format('--diff-algorithm=%s', git_hunks.algorithm),
117+
string.format('--diff-algorithm=%s', git_setting:get('algorithm')),
117118
'--patch-with-raw',
118119
'--unified=0',
119120
}

lua/vgit/git/gitcli.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
local loop = require('vgit.core.loop')
22
local Spawn = require('vgit.core.Spawn')
33
local console = require('vgit.core.console')
4+
local git_setting = require('vgit.settings.git')
45

56
local gitcli = {}
67

78
gitcli.run = loop.suspend(function(args, opts, callback)
8-
local cmd = 'git'
9+
local cmd = git_setting:get('cmd')
910

1011
opts = opts or {}
1112
local debug = opts.debug

lua/vgit/settings/git.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ local Config = require('vgit.core.Config')
22

33
return Config({
44
cmd = 'git',
5+
algorithm = 'myers',
56
fallback_cwd = '',
67
fallback_args = {},
78
})

0 commit comments

Comments
 (0)