mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 22:24:37 -04:00
Lazy load object format with command line and don't do it in OpenRepository (#29712)
Most time, when invoking `git.OpenRepository`, `objectFormat` will not be used, so it's a waste to invoke commandline to get the object format. This PR make it a lazy operation, only invoke that when necessary. (cherry picked from commit e84e5db6de0306d514b1f1a9657931fb7197a188)
This commit is contained in:
parent
e825d007b1
commit
c9d9255244
15 changed files with 72 additions and 31 deletions
|
@ -94,6 +94,10 @@ func (repo *Repository) LsFiles(filenames ...string) ([]string, error) {
|
|||
|
||||
// RemoveFilesFromIndex removes given filenames from the index - it does not check whether they are present.
|
||||
func (repo *Repository) RemoveFilesFromIndex(filenames ...string) error {
|
||||
objectFormat, err := repo.GetObjectFormat()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cmd := NewCommand(repo.Ctx, "update-index", "--remove", "-z", "--index-info")
|
||||
stdout := new(bytes.Buffer)
|
||||
stderr := new(bytes.Buffer)
|
||||
|
@ -101,7 +105,7 @@ func (repo *Repository) RemoveFilesFromIndex(filenames ...string) error {
|
|||
for _, file := range filenames {
|
||||
if file != "" {
|
||||
buffer.WriteString("0 ")
|
||||
buffer.WriteString(repo.objectFormat.EmptyObjectID().String())
|
||||
buffer.WriteString(objectFormat.EmptyObjectID().String())
|
||||
buffer.WriteByte('\t')
|
||||
buffer.WriteString(file)
|
||||
buffer.WriteByte('\000')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue