From 3a499d441fb435cdcf514c564161eb0e53172fe2 Mon Sep 17 00:00:00 2001 From: Masaya Suzuki Date: Mon, 26 Aug 2024 12:49:42 -0700 Subject: [PATCH] Add blobFetchDebugInfo Fixes https://github.com/aviator-co/niche-git/issues/15 --- cmd/squash_cherry_pick.go | 26 +++++++++++++------------ squash_cherry_pick.go | 40 +++++++++++++++++++-------------------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/cmd/squash_cherry_pick.go b/cmd/squash_cherry_pick.go index 1cd5c5e..efb9c56 100644 --- a/cmd/squash_cherry_pick.go +++ b/cmd/squash_cherry_pick.go @@ -59,7 +59,7 @@ var squashCherryPick = &cobra.Command{ r := plumbing.ReferenceName(squashCherryPickArgs.conflictRef) conflictRef = &r } - result, fetchDebugInfo, pushDebugInfo, pushErr := nichegit.PushSquashCherryPick( + result, fetchDebugInfo, blobFetchDebugInfo, pushDebugInfo, pushErr := nichegit.PushSquashCherryPick( squashCherryPickArgs.repoURL, client, plumbing.NewHash(squashCherryPickArgs.cherryPickFrom), @@ -74,8 +74,9 @@ var squashCherryPick = &cobra.Command{ squashCherryPickArgs.abortOnConflict, ) output := squashCherryPickOutput{ - FetchDebugInfo: fetchDebugInfo, - PushDebugInfo: pushDebugInfo, + FetchDebugInfo: fetchDebugInfo, + BlobFetchDebugInfo: blobFetchDebugInfo, + PushDebugInfo: pushDebugInfo, } if result != nil { output.CommitHash = result.CommitHash.String() @@ -129,15 +130,16 @@ func newSignature(name, email, timestamp string) (object.Signature, error) { } type squashCherryPickOutput struct { - CommitHash string `json:"commitHash"` - CherryPickedFiles []string `json:"cherryPickedFiles"` - ConflictOpenFiles []string `json:"conflictOpenFiles"` - ConflictResolvedFiles []string `json:"conflictResolvedFiles"` - BinaryConflictFiles []string `json:"binaryConflictFiles"` - NonFileConflictFiles []string `json:"nonFileConflictFiles"` - FetchDebugInfo debug.FetchDebugInfo `json:"fetchDebugInfo"` - PushDebugInfo *debug.PushDebugInfo `json:"pushDebugInfo"` - Error string `json:"error,omitempty"` + CommitHash string `json:"commitHash"` + CherryPickedFiles []string `json:"cherryPickedFiles"` + ConflictOpenFiles []string `json:"conflictOpenFiles"` + ConflictResolvedFiles []string `json:"conflictResolvedFiles"` + BinaryConflictFiles []string `json:"binaryConflictFiles"` + NonFileConflictFiles []string `json:"nonFileConflictFiles"` + FetchDebugInfo debug.FetchDebugInfo `json:"fetchDebugInfo"` + BlobFetchDebugInfo *debug.FetchDebugInfo `json:"blobFetchDebugInfo"` + PushDebugInfo *debug.PushDebugInfo `json:"pushDebugInfo"` + Error string `json:"error,omitempty"` } func init() { diff --git a/squash_cherry_pick.go b/squash_cherry_pick.go index 108a82c..82b7ca1 100644 --- a/squash_cherry_pick.go +++ b/squash_cherry_pick.go @@ -41,61 +41,61 @@ func PushSquashCherryPick( conflictRef *plumbing.ReferenceName, currentRefhash *plumbing.Hash, abortOnConflict bool, -) (*PushSquashCherryPickResult, debug.FetchDebugInfo, *debug.PushDebugInfo, error) { +) (*PushSquashCherryPickResult, debug.FetchDebugInfo, *debug.FetchDebugInfo, *debug.PushDebugInfo, error) { packfilebs, fetchDebugInfo, err := fetch.FetchBlobNonePackfile(repoURL, client, []plumbing.Hash{commitHashCherryPickFrom, commitHashCherryPickBase, commitHashCherryPickTo}) if err != nil { - return nil, fetchDebugInfo, nil, err + return nil, fetchDebugInfo, nil, nil, err } storage := memory.NewStorage() parser, err := packfile.NewParserWithStorage(packfile.NewScanner(bytes.NewReader(packfilebs)), storage) if err != nil { - return nil, fetchDebugInfo, nil, fmt.Errorf("failed to parse packfile: %v", err) + return nil, fetchDebugInfo, nil, nil, fmt.Errorf("failed to parse packfile: %v", err) } if _, err := parser.Parse(); err != nil { - return nil, fetchDebugInfo, nil, fmt.Errorf("failed to parse packfile: %v", err) + return nil, fetchDebugInfo, nil, nil, fmt.Errorf("failed to parse packfile: %v", err) } treeCPFrom, err := getTreeFromCommit(storage, commitHashCherryPickFrom) if err != nil { - return nil, fetchDebugInfo, nil, err + return nil, fetchDebugInfo, nil, nil, err } treeCPBase, err := getTreeFromCommit(storage, commitHashCherryPickBase) if err != nil { - return nil, fetchDebugInfo, nil, err + return nil, fetchDebugInfo, nil, nil, err } treeCPTo, err := getTreeFromCommit(storage, commitHashCherryPickTo) if err != nil { - return nil, fetchDebugInfo, nil, err + return nil, fetchDebugInfo, nil, nil, err } collector := &conflictBlobCollector{} mergeResult, err := merge.MergeTree(storage, treeCPFrom, treeCPTo, treeCPBase, collector.Resolve) if err != nil { - return nil, fetchDebugInfo, nil, fmt.Errorf("failed to merge the trees: %v", err) + return nil, fetchDebugInfo, nil, nil, fmt.Errorf("failed to merge the trees: %v", err) } resolver := resolvediff3.NewDiff3Resolver(storage, "Cherry-pick content", "Base content", ".rej", "") + var blobFetchDebugInfo *debug.FetchDebugInfo if len(mergeResult.FilesConflict) != 0 { // Need to fetch blobs and resolve the conflicts. if len(collector.blobHashes) > 0 { packfilebs, fetchBlobDebugInfo, err := fetch.FetchBlobPackfile(repoURL, client, collector.blobHashes) - // TODO: return debug info - _ = fetchBlobDebugInfo + blobFetchDebugInfo = &fetchBlobDebugInfo if err != nil { - return nil, fetchDebugInfo, nil, err + return nil, fetchDebugInfo, blobFetchDebugInfo, nil, err } parser, err := packfile.NewParserWithStorage(packfile.NewScanner(bytes.NewReader(packfilebs)), storage) if err != nil { - return nil, fetchDebugInfo, nil, fmt.Errorf("failed to parse packfile: %v", err) + return nil, fetchDebugInfo, blobFetchDebugInfo, nil, fmt.Errorf("failed to parse packfile: %v", err) } if _, err := parser.Parse(); err != nil { - return nil, fetchDebugInfo, nil, fmt.Errorf("failed to parse packfile: %v", err) + return nil, fetchDebugInfo, blobFetchDebugInfo, nil, fmt.Errorf("failed to parse packfile: %v", err) } } mergeResult, err = merge.MergeTree(storage, treeCPFrom, treeCPTo, treeCPBase, resolver.Resolve) if err != nil { - return nil, fetchDebugInfo, nil, fmt.Errorf("failed to merge the trees: %v", err) + return nil, fetchDebugInfo, blobFetchDebugInfo, nil, fmt.Errorf("failed to merge the trees: %v", err) } } @@ -108,7 +108,7 @@ func PushSquashCherryPick( } hasConflict := len(cpResult.ConflictOpenFiles) > 0 || len(cpResult.BinaryConflictFiles) > 0 || len(cpResult.NonFileConflictFiles) > 0 if abortOnConflict && hasConflict { - return cpResult, fetchDebugInfo, nil, errors.New("conflict detected") + return cpResult, fetchDebugInfo, blobFetchDebugInfo, nil, errors.New("conflict detected") } commit := &object.Commit{ Message: commitMessage, @@ -119,11 +119,11 @@ func PushSquashCherryPick( } obj := storage.NewEncodedObject() if err := commit.Encode(obj); err != nil { - return cpResult, fetchDebugInfo, nil, fmt.Errorf("failed to create a commit: %v", err) + return cpResult, fetchDebugInfo, blobFetchDebugInfo, nil, fmt.Errorf("failed to create a commit: %v", err) } commitHash, err := storage.SetEncodedObject(obj) if err != nil { - return cpResult, fetchDebugInfo, nil, fmt.Errorf("failed to create a commit: %v", err) + return cpResult, fetchDebugInfo, blobFetchDebugInfo, nil, fmt.Errorf("failed to create a commit: %v", err) } cpResult.CommitHash = commitHash @@ -134,7 +134,7 @@ func PushSquashCherryPick( var buf bytes.Buffer packEncoder := packfile.NewEncoder(&buf, storage, false) if _, err := packEncoder.Encode(newHashes, 0); err != nil { - return cpResult, fetchDebugInfo, nil, fmt.Errorf("failed to create a packfile: %v", err) + return cpResult, fetchDebugInfo, blobFetchDebugInfo, nil, fmt.Errorf("failed to create a packfile: %v", err) } var destRef plumbing.ReferenceName @@ -152,9 +152,9 @@ func PushSquashCherryPick( }, }) if err != nil { - return cpResult, fetchDebugInfo, &pushDebugInfo, err + return cpResult, fetchDebugInfo, blobFetchDebugInfo, &pushDebugInfo, err } - return cpResult, fetchDebugInfo, &pushDebugInfo, nil + return cpResult, fetchDebugInfo, blobFetchDebugInfo, &pushDebugInfo, nil } type conflictBlobCollector struct {