-
Notifications
You must be signed in to change notification settings - Fork 234
refactor: unify tree modification to use ApplyTreeChanges #573
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -168,20 +168,24 @@ func fetchAndMergeSessionsCommon(ctx context.Context, remote, branchName string) | |||||||||||||||||||||||||||||||
| return fmt.Errorf("failed to get remote tree: %w", err) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Flatten both trees and combine entries | ||||||||||||||||||||||||||||||||
| // Session logs have unique cond-* directories, so no conflicts expected | ||||||||||||||||||||||||||||||||
| entries := make(map[string]object.TreeEntry) | ||||||||||||||||||||||||||||||||
| if err := checkpoint.FlattenTree(repo, localTree, "", entries); err != nil { | ||||||||||||||||||||||||||||||||
| // Compute what the remote has that differs from local, then apply surgically. | ||||||||||||||||||||||||||||||||
| // Session logs have unique cond-* directories, so no conflicts expected. | ||||||||||||||||||||||||||||||||
| localEntries := make(map[string]object.TreeEntry) | ||||||||||||||||||||||||||||||||
| if err := checkpoint.FlattenTree(repo, localTree, "", localEntries); err != nil { | ||||||||||||||||||||||||||||||||
| return fmt.Errorf("failed to flatten local tree: %w", err) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| if err := checkpoint.FlattenTree(repo, remoteTree, "", entries); err != nil { | ||||||||||||||||||||||||||||||||
| remoteEntries := make(map[string]object.TreeEntry) | ||||||||||||||||||||||||||||||||
| if err := checkpoint.FlattenTree(repo, remoteTree, "", remoteEntries); err != nil { | ||||||||||||||||||||||||||||||||
| return fmt.Errorf("failed to flatten remote tree: %w", err) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // Build merged tree | ||||||||||||||||||||||||||||||||
| mergedTreeHash, err := checkpoint.BuildTreeFromEntries(repo, entries) | ||||||||||||||||||||||||||||||||
| // DiffTrees computes changes to transform local into remote (remote wins on collision) | ||||||||||||||||||||||||||||||||
| changes := checkpoint.DiffTrees(localEntries, remoteEntries) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
|
Comment on lines
+182
to
+184
|
||||||||||||||||||||||||||||||||
| // DiffTrees computes changes to transform local into remote (remote wins on collision) | |
| changes := checkpoint.DiffTrees(localEntries, remoteEntries) | |
| // Build a union of local and remote entries where remote overwrites on collision. | |
| // This ensures we only add/update entries and never delete local-only session logs. | |
| unionEntries := make(map[string]object.TreeEntry, len(localEntries)+len(remoteEntries)) | |
| for path, entry := range localEntries { | |
| unionEntries[path] = entry | |
| } | |
| for path, entry := range remoteEntries { | |
| unionEntries[path] = entry | |
| } | |
| // DiffTrees computes changes to transform local into the union (remote wins on collision), | |
| // preserving local-only entries. | |
| changes := checkpoint.DiffTrees(localEntries, unionEntries) |
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.
DiffTreesonly comparesTreeEntry.Hashwhen deciding whether an entry changed. Git tree entries also encode the file mode (e.g., regular vs executable), so a pure mode change with identical blob content would be missed and not applied. Includeentry.Mode(and any other relevant metadata) in the equality check so mode-only changes produce aTreeChange.