@@ -127,41 +127,38 @@ function FileEntry:convert_layout(target_layout)
127127 })
128128end
129129
130- --- @param adapter VCSAdapter
131130--- @param stat ? table
132- function FileEntry :validate_stage_buffers (adapter , stat )
133- stat = stat or utils .path :stat (utils .path :join (adapter .ctx .dir , " index" ))
134- local cached_stat = utils .tbl_access (fstat_cache , { adapter .ctx .toplevel , " index" })
135-
136- if stat then
137- if not cached_stat or cached_stat .mtime < stat .mtime .sec then
138- for _ , f in ipairs (self .layout :files ()) do
139- if f .rev .type == RevType .STAGE and f :is_valid () then
140- if f .rev .stage > 0 then
141- -- We only care about stage 0 here
142- f :dispose_buffer ()
143- else
144- local is_modified = vim .bo [f .bufnr ].modified
145-
146- if f .blob_hash then
147- local new_hash = f .adapter :file_blob_hash (f .path )
148-
149- if new_hash and new_hash ~= f .blob_hash then
150- if is_modified then
151- utils .warn ((
152- " A file was changed in the index since you started editing it!"
153- .. " Be careful not to lose any staged changes when writing to this buffer: %s"
154- ):format (api .nvim_buf_get_name (f .bufnr )))
155- else
156- f :dispose_buffer ()
157- end
131+ function FileEntry :validate_stage_buffers (stat )
132+ stat = stat or utils .path :stat (utils .path :join (self .adapter .ctx .dir , " index" ))
133+ local cached_stat = utils .tbl_access (fstat_cache , { self .adapter .ctx .toplevel , " index" })
134+
135+ if stat and (not cached_stat or cached_stat .mtime < stat .mtime .sec ) then
136+ for _ , f in ipairs (self .layout :files ()) do
137+ if f .rev .type == RevType .STAGE and f :is_valid () then
138+ if f .rev .stage > 0 then
139+ -- We only care about stage 0 here
140+ f :dispose_buffer ()
141+ else
142+ local is_modified = vim .bo [f .bufnr ].modified
143+
144+ if f .blob_hash then
145+ local new_hash = self .adapter :file_blob_hash (f .path )
146+
147+ if new_hash and new_hash ~= f .blob_hash then
148+ if is_modified then
149+ utils .warn ((
150+ " A file was changed in the index since you started editing it!"
151+ .. " Be careful not to lose any staged changes when writing to this buffer: %s"
152+ ):format (api .nvim_buf_get_name (f .bufnr )))
153+ else
154+ f :dispose_buffer ()
158155 end
159- elseif not is_modified then
160- -- Should be very rare that we don't have an index-buffer's blob
161- -- hash. But in that case, we can't warn the user when a file
162- -- changes in the index while they're editing its index buffer.
163- f :dispose_buffer ()
164156 end
157+ elseif not is_modified then
158+ -- Should be very rare that we don't have an index-buffer's blob
159+ -- hash. But in that case, we can't warn the user when a file
160+ -- changes in the index while they're editing its index buffer.
161+ f :dispose_buffer ()
165162 end
166163 end
167164 end
0 commit comments