-
Notifications
You must be signed in to change notification settings - Fork 219
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
Added support for git stash list
#1280
base: master
Are you sure you want to change the base?
Changes from 14 commits
04fbcd4
17739b3
df55c43
992cd3a
6c00308
c1ce446
b185356
12124b5
4ee97c0
3b7fa9c
ff7c87b
a76789c
b99080a
4098f2e
1ef03c0
35c221e
3d6c898
76bc6bb
bd37ec2
812a8c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
@@ -0,0 +1,60 @@ | ||||
local Buffer = require("neogit.lib.buffer") | ||||
local config = require("neogit.config") | ||||
local CommitViewBuffer = require("neogit.buffers.commit_view") | ||||
|
||||
local ui = require("neogit.buffers.stash_list_view.ui") | ||||
|
||||
---@class StashListBuffer | ||||
---@field stashes StashEntry[] | ||||
local M = {} | ||||
M.__index = M | ||||
|
||||
--- Gets all current stashes | ||||
function M.new(stashes) | ||||
local instance = { | ||||
stashes = stashes, | ||||
} | ||||
|
||||
setmetatable(instance, M) | ||||
return instance | ||||
end | ||||
|
||||
function M:close() | ||||
self.buffer:close() | ||||
self.buffer = nil | ||||
end | ||||
|
||||
--- Creates a buffer populated with output of `git stash list` | ||||
--- and supports related operations. | ||||
function M:open() | ||||
self.buffer = Buffer.create { | ||||
name = "NeogitStashView", | ||||
filetype = "NeogitStashView", | ||||
kind = config.values.stash.kind, | ||||
context_higlight = true, | ||||
-- Define the available mappings here. `git stash list` has the same options | ||||
-- as `git log` refer to git-log(1) for more info. | ||||
mappings = { | ||||
n = { | ||||
["q"] = function() | ||||
self:close() | ||||
end, | ||||
["<esc>"] = function() | ||||
self:close() | ||||
end, | ||||
["<enter>"] = function() | ||||
-- Still looking for how to view a stash | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use neogit/lua/neogit/lib/git/rev_parse.lua Line 23 in f10084a
git rev-parse 'stash@{0}' ) to get the OID from a stash, which can be passed into the buffer constructor.
|
||||
CommitViewBuffer.new(self.buffer.ui:get_commit_under_cursor()):open() | ||||
end, | ||||
} | ||||
}, | ||||
after = function() | ||||
vim.cmd([[setlocal nowrap]]) | ||||
end, | ||||
render = function() | ||||
return ui.View(self.stashes) | ||||
end, | ||||
} | ||||
end | ||||
|
||||
return M |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
local Ui = require("neogit.lib.ui") | ||
local Component = require("neogit.lib.ui.component") | ||
local util = require("neogit.lib.util") | ||
|
||
local text = Ui.text | ||
local col = Ui.col | ||
local row = Ui.row | ||
|
||
-- local StashEntry = require("neogit.lib.git.stash").StashEntry | ||
|
||
CKolkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local M = {} | ||
|
||
---Parses output of `git stash list` and splits elements into table | ||
M.Stash = Component.new(function(stash) | ||
local children = {} | ||
CKolkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
local table = table.concat({" stash@{", stash.idx, "}" }, "") | ||
CKolkey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return col({ | ||
row({ | ||
text.highlight("Comment")(label), | ||
text(" "), | ||
text(stash.message), | ||
}, { | ||
virtual_text = { | ||
{ " ", "Constant" }, | ||
{ stash.rel_date, "Special" }, | ||
}, | ||
}), | ||
}, { oid = label }) | ||
end) | ||
|
||
---@param stashes StashEntry[] | ||
---@return table | ||
function M.View(stashes) | ||
return util.map(stashes, function(stash) | ||
return M.Stash(stash) | ||
end) | ||
end | ||
|
||
return M |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -5,6 +5,11 @@ local util = require("neogit.lib.util") | |||||
|
||||||
local M = {} | ||||||
|
||||||
---@class StashEntry | ||||||
---@field stash_id string the id of the stash i.e. stash@{7} | ||||||
---@field rel_date string relative timestamp | ||||||
---@field message string the message associated with each stash. | ||||||
|
||||||
local function perform_stash(include) | ||||||
if not include then | ||||||
return | ||||||
|
@@ -125,7 +130,13 @@ function M.register(meta) | |||||
state.stashes.items = util.map(M.list(), function(line) | ||||||
local idx, message = line:match("stash@{(%d*)}: (.*)") | ||||||
|
||||||
---@class StashEntry | ||||||
return { | ||||||
rel_date = cli.log | ||||||
.max_count(1) | ||||||
.format("%cr") | ||||||
.args("stash@{" .. idx .. "}") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Not a major thing, but in lua strings are interned, so concatenation operations will re-hash the new string, for every In this case that would be something like:
Many successive re-hashings will have a noticeable performance hit. While it's probable that this list will never be long enough to encounter that, I just prefer to do string formatting or |
||||||
.call({ hidden = true }).stdout[1], | ||||||
idx = tonumber(idx), | ||||||
name = line, | ||||||
message = message, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.