mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-25 18:28:57 -06:00
/go/store/blobstore: reuse temp index file
This commit is contained in:
@@ -21,8 +21,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -841,7 +839,7 @@ func (gbs *GitBlobstore) casRetryPolicy(ctx context.Context) backoff.BackOff {
|
||||
}
|
||||
|
||||
func (gbs *GitBlobstore) buildCommitForKeyWrite(ctx context.Context, parent git.OID, hasParent bool, key string, plan putPlan, msg string) (git.OID, error) {
|
||||
_, indexFile, cleanup, err := newTempIndex()
|
||||
_, indexFile, cleanup, err := git.NewTempIndex()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -1386,26 +1384,6 @@ func isMissingGitIdentityErr(err error) bool {
|
||||
strings.Contains(msg, "empty ident name")
|
||||
}
|
||||
|
||||
func newTempIndex() (dir, indexFile string, cleanup func(), err error) {
|
||||
// Create a unique temp index file. This is intentionally *not* placed under GIT_DIR:
|
||||
// - some git dirs may be read-only or otherwise unsuitable for scratch files
|
||||
// - we don't want to leave temp files inside the repo on crashes
|
||||
//
|
||||
// Note: git will also create a sibling lock file (<index>.lock) during index writes.
|
||||
f, err := os.CreateTemp("", "dolt-gitblobstore-index-")
|
||||
if err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
indexFile = f.Name()
|
||||
_ = f.Close()
|
||||
dir = filepath.Dir(indexFile)
|
||||
cleanup = func() {
|
||||
_ = os.Remove(indexFile)
|
||||
_ = os.Remove(indexFile + ".lock")
|
||||
}
|
||||
return dir, indexFile, cleanup, nil
|
||||
}
|
||||
|
||||
// normalizeGitTreePath normalizes and validates a blobstore key for use as a git tree path.
|
||||
//
|
||||
// Rules:
|
||||
|
||||
@@ -11,15 +11,20 @@
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
package gitrebase
|
||||
package git
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func newTempIndex() (dir, indexFile string, cleanup func(), err error) {
|
||||
f, err := os.CreateTemp("", "dolt-gitrebase-index-")
|
||||
// NewTempIndex creates a unique temporary git index file (for use as GIT_INDEX_FILE).
|
||||
// The index is created outside of any repo's GIT_DIR to avoid read-only repos and to
|
||||
// avoid leaving scratch files in the repo on crashes.
|
||||
//
|
||||
// Note: git may also create a sibling lock file (<index>.lock) during index writes.
|
||||
func NewTempIndex() (dir, indexFile string, cleanup func(), err error) {
|
||||
f, err := os.CreateTemp("", "dolt-git-index-")
|
||||
if err != nil {
|
||||
return "", "", nil, err
|
||||
}
|
||||
@@ -365,7 +365,7 @@ func mergeUnits(base map[string]unit, local map[string]unit, remote map[string]u
|
||||
}
|
||||
|
||||
func writeMergedTree(ctx context.Context, api git.GitAPI, merged map[string]unit, base treeSnapshot, local treeSnapshot, remote treeSnapshot) (git.OID, error) {
|
||||
_, indexFile, cleanup, err := newTempIndex()
|
||||
_, indexFile, cleanup, err := git.NewTempIndex()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func newTestGitAPI(t *testing.T, ctx context.Context) (*git.Runner, git.GitAPI)
|
||||
func mkCommit(t *testing.T, ctx context.Context, api git.GitAPI, parent *git.OID, files map[string][]byte, msg string) git.OID {
|
||||
t.Helper()
|
||||
|
||||
_, indexFile, cleanup, err := newTempIndex()
|
||||
_, indexFile, cleanup, err := git.NewTempIndex()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user