-
-
Notifications
You must be signed in to change notification settings - Fork 184
Expand file tree
/
Copy pathlog_entry.lua
More file actions
105 lines (89 loc) · 2.43 KB
/
log_entry.lua
File metadata and controls
105 lines (89 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
local lazy = require("diffview.lazy")
local oop = require("diffview.oop")
local FileEntry = lazy.access("diffview.scene.file_entry", "FileEntry") ---@type FileEntry
local utils = lazy.require("diffview.utils") ---@module "diffview.utils"
local M = {}
---@class LogEntry : diffview.Object
---@operator call : LogEntry
---@field path_args string[]
---@field commit Commit
---@field files FileEntry[]
---@field status string
---@field stats GitStats
---@field single_file boolean
---@field folded boolean
---@field nulled boolean
local LogEntry = oop.create_class("LogEntry")
function LogEntry:init(opt)
self.path_args = opt.path_args
self.commit = opt.commit
self.files = opt.files
self.folded = true
self.single_file = opt.single_file
self.nulled = utils.sate(opt.nulled, false)
self:update_status()
self:update_stats()
end
function LogEntry:destroy()
for _, file in ipairs(self.files) do
file:destroy()
end
end
function LogEntry:update_status()
self.status = nil
local missing_status = 0
for _, file in ipairs(self.files) do
if not file.status then
missing_status = missing_status + 1
else
if self.status and file.status ~= self.status then
self.status = "M"
return
elseif self.status ~= file.status then
self.status = file.status
end
end
end
if missing_status < #self.files and not self.status then
self.status = "X"
end
end
function LogEntry:update_stats()
self.stats = { additions = 0, deletions = 0 }
local missing_stats = 0
for _, file in ipairs(self.files) do
if not file.stats then
missing_stats = missing_stats + 1
else
self.stats.additions = self.stats.additions + file.stats.additions
self.stats.deletions = self.stats.deletions + file.stats.deletions
end
end
if missing_stats == #self.files then
self.stats = nil
end
end
---@param path string
---@return diff.FileEntry?
function LogEntry:get_diff(path)
if not self.commit.diff then return nil end
for _, diff_entry in ipairs(self.commit.diff) do
if path == (diff_entry.path_new or diff_entry.path_old) then
return diff_entry
end
end
end
---@param adapter VCSAdapter
---@param opt table
---@return LogEntry
function LogEntry.new_null_entry(adapter, opt)
opt = opt or {}
return LogEntry(
vim.tbl_extend("force", opt, {
nulled = true,
files = { FileEntry.new_null_entry(adapter) },
})
)
end
M.LogEntry = LogEntry
return M