Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Apply patch in Sync view
Contents
Problem
Provide an alternative way of applying patches. Desired behavior, which could in future replace the current one, is to use the Synchronize View to display content of a patch, resolve potential conflicts and apply the patch eventually. This way while the comparison is being done, other features of Eclipse are available to use, we are not bounded to the current Apply Patch wizard.
This is tracked by bug 236169.
Solution
The proposed solution consist of several parts:
- Subscriber - a subscriber implementation that provides synchronization between local resources to be patched and their in-memory representation with changes from the patch applied. As the result of it's nature, the subscriber does not contact any remote server. It's a three-way comparison, all changes from the patch are treated as incoming.
- SyncInfo - sync info node is returned to resources that would be affected by the patch. The direction of the sync info node can be either incoming or conflicting (for unmatched changes).
- IResourceVariant - represents local resource with changes from the patch
- ModelProvider - provider for Patch logical model
- model objects - PatchDiffNodes are used as model objects: PatchProjectDiffNode for projects in the patch, PatchFileDiffNode for files and HunkDiffNode for hunks. PatchDiffNode implements ICompareInput so it can be used as input to a two-way or three-way compare viewer.
- ResourceMappings - each model object is accompanied by resource mapping. Resource mapping for a hunk object returns traversal containing the IFile affected by the hunk.
- org.eclipse.team.ui.synchronizeWizards extension point - used to register a synchronize participant creation wizard. In the proposed solution a subclass of PatchWizard is used. An extra page is added where user can decide to preview patch in the Synchronize view, so when 'Finish' button is pressed the participant is refreshed and the result is displayed in the Synchronize view.
- org.eclipse.team.ui.synchronizeParticipants extension point - sublass of ModelSynchronizeParticipant
- org.eclipse.ui.navigator.navigatorContent extension point - provides a content and label provider used by a navigator content service in the Synchronize View when model aware synchronization takes place
- content provider - a content provider that implements IPipelinedTreeContentProvider so contributions provided by an "upstream" extension (resourceContent) can be replaced with Patch model objects
- label provider - a label provider decorating Patch model objects with probel labeling and image
- org.eclipse.team.ui.teamContentProviders - associates the patch model provider with the patch navigator content provider
- org.eclipse.core.runtime.adapters - allows to declaratively register adapter factory which supports different adapters including IResourceMapping (used by the model provider), IWorkbenchAdapter (required by label provider) and others
Tasks
Required changes are grouped in the following areas:
Synchronize participant, subscriber
- Add synchronize participant + subscriber
- IResourceVariant implementation should return patched files when asked for Storage
- Persistable, intitialized on startup; remember which hunks have been applied; remember patch options set
- Pinnable
- Listen to workspace changes, reapply all hunks for a file when needed using the patch options already set
- bug: Applying a change should remove it from the sync view - change state to 'in sync' bug 298923
- Make sure non-workspace patches can be applied via Sync view as well bug 298923
- Close (ask to close) participant when all hunks have been applied, so it won't bother about forthcoming resource changes (deltas)
- Patches from multiple synchronizations (when pinned) should be applicable in any order. This includes applying only part of a patch.
Synchronize wizard
- Embed apply patch wizard into synchronize wizard so patch (input) can be selected
- Setting bounds for a nested wizard is an issue, see bug 297470
- Add a page to the new wizard where user can select how the patch should be applied (traditionally, preview in the wizard or in Sync view)
- Add more options to the new wizard page, see bug 198149
- Synchronize resources modified by the patch
- Add affected resources to a Change set bug 117298
- Add affected resource to a Working Set
- Provide a proper icon for the participant bug 298923
- Provide valid description for the participant bug 298923
Model Provider
- Model objects for hunks
- Allow other model providers to participate in synchronization (applying patch)
-
Other model providers do not display hunksOnly Patch Model provider displays hunks
-
Use DiffProject, FilePatch2 and Hunk as model objects - Use PatchDiffNodes as model objects, they represent the result of applying a patch (not the patch strucutre as types above) and they implement ICompareInput so are compare-ready
- Missing objects representing folders, this results in something similar to 'flat presentation'
- Other models do not indicate any conflicts when applying a patch -> unmatched hunks should be treated as sync view conflicts, see also #Label provider
- NPE when trying to execute a team action from context menu in Package Explorer
- bug: 'Patch Contents' model provider should not appear in CVS synchronizations bug 298923 [Szymon]
- bug: 'Patch Contents' model provider interfere unrelated Team operations (e.g. 'Replace with Another Branch or Version') bug 298923 [Szymon]
- bug: CCE when switched to 'Patch Contents' model if the Sync view opened with a different model displayed initially (e.g. Java Workspace) bug 298923
Sync view
- Treat unmerged hunks/files as conflicts
- Status line should display lines added/removed by the patch.
- NPE when trying to switch to a different synchronization when applying patch (see bug 256972)
- 'Schedule' action in the view's drop down menu should be disabled (or removed)
- Support 'Link with Editor'
- Applying patch ('Update' action) should process only matched hunks bug 298923
Content provider
Label provider
- Indicate that a hunk cannot be applied.
- Display Patch options settings: fuzz factor, offset used (bug 205762), moved from(?). All per hunk.
- Use conflict ('double-headed red arrow') icon instead of 'red X' icon for unmatched hunks
- Indicate when a project from the patch doesn't exist in the workspace bug 298923
- bug: Missing 'incoming change' indicator for model provider different than 'Patch' when open for the first time. Workaround: switch to 'Patch' model and back.
- bug: Folders to be created by an addition are not displayed when in 'All Models' mode
Context menu issues need to fixed before merging to HEAD, see bug 298923.
- 'Update' means 'Apply' in the Apply Patch world
- 'Apply' should work for projects, files and individual hunks
- 'Apply' should be disabled for unmatched hunks
- 'Apply' on file/project containing unmatched hunks should affect matched hunks only
-
Do we need two 'Apply' variants: merge and overwrite-and-update?I assume we don't. - Add 'Open'/'Open With' actions
- Add 'Open in Compare' action
-
'Remove from View' means 'Exclude' in the Apply Patch worldI think we will stick to 'Remove from View' action to be consistent with other synchronizations. -
No 'Exclude' action available, replaced with 'Remove from the view' -
'Mark as Merged' does the same thing as 'Exclude' in the Apply Patch world (?)See 'Remove from View'. - 'Apply' made on a hunk should affect only the selected hunk not the whole file as it happens now
View toolbar
- 'Copy All Incoming Changes...' / 'Merge All Non-conflicting Changes' means 'Apply All'
- Only 'Incoming' and 'Conflicts' mode should be available
- 'Flat presentation' is meaningless for Patch Model (see also bug 277107)
Operations
Make all operations in the Apply Patch wizard be available in the Sync view (when applying a patch).
Patch options
- Re-applying patch -> synchronize again
- Remember set options when re-applying: fuzz factor, ignored segments, moved hunks
- Ignore segments setting applies to all files in the patch -> re-apply
- Reverse patch on sync's view toolbar(?)
- Show matched Hunks: All hunks are shown
- Show excluded Hunks -> Sync's view drop down > Restore Removed Items
- Fuzz factor / Guess
- Generate .rej files for unmerged hunks - applies to all changes from the patch
- Move hunk
Compare Editor
- 'Open In Compare Editor' for a file should display full file content with changes from all hunks
- bug: Open in Compare editor for a file (in a patch) displays Hunks in the structure view. First hunk is select on start but nothing is displayed in the compare content area.
- 'Open In Compare Editor' should be available for hunks
- bug: No Java structure available for Java files; fine(?) for hunks
- bug: ClassCastException when right-clicking in comparison for a file
- Update context menu, rename Merge, Mark as Merged and Overwrite action as in #Context menu
- For Java files (All Models, Java Workspace modes) Java compare editor should be opened, instead Text compare is used. Works fine when compare is open for Java file from Patch Contents mode
Source code
You have two options here:
- apply the latest patch from bug 236169
- checkout "branch_20091215_bug236169" branch created for o.e.compare and o.e.team.ui (suggested)