Apply patch in Sync view
- 1 Problem
- 2 Solution
- 3 Tasks
- 3.1 Synchronize participant, subscriber
- 3.2 Synchronize wizard
- 3.3 Model Provider
- 3.4 Sync view
- 3.5 Operations
- 3.6 Compare Editor
- 4 Source code
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.
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
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
- Pinning synchronization... seems to be working fine.
- Response 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'
- Make sure non-workspace patches can be applied via Sync view as well
Close (ask to close) participant when all hunks have been applied, so it won't bother about forthcoming resource changes (deltas)It's not an issue anymore, resource changes do not make applied hunks to reappear.
- Patches from multiple synchronizations (when pinned) should be applicable in any order. This includes applying only part of a patch.
- Synchronizing against multiple patches and applying changes to the same file from these patches causes data loss. The file's content is overwritten, so changes from the previously applied patch are lost.
- bug: synchronize with patch, close the project, do 'Apply All' -> Error dialog saying "Project is not open" will pop up. When closing the project, no changes should be visible in the synch view, 'Apply All' button should be disabled. How does CVS Synchronization behave in such situation?
- 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 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: 'Patch Contents' model provider interfere unrelated Team operations (e.g. 'Replace with Another Branch or Version')
- bug: CCE when switched to 'Patch Contents' model if the Sync view opened with a different model displayed initially (e.g. Java Workspace)
- 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). Not a blocking issue anymore, added icon for the participant.
- 'Schedule' action in the view's drop down menu should be disabled (or removed) bug 301243
- Support 'Link with Editor'
- Applying patch ('Update' action) should process only matched hunks
- Clicking on the model switching drop-down doesn't turn Patch Contents model on. Same thing for Change Sets when doing CVS synchronization. bug 210087
- bug: Do 'apply' on a file with an unmatched hunk. Other matching hunks should disappear from the view (applied and marked as excluded), the only one remaining should be the unmatched hunk.
- Display hunks in Sync view
- Hunks objects never have children, get rid of the [+] sign
- Fix hunks sorting. Hunk labeled '123...' should not appear before '13...'.
- 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. bug 300350
- Indicate when a project from the patch doesn't exist in the workspace. Currently 'No change' msg is displayed, which is ok when applying a patch for a single project. For multiple projects, showing no changes may result in omitting part of the patch without noticing it. Showing a dialog with a warning message seems to be reasonable. What does CVS Synchronization do in such cases? Does it ever happen for CVS? bug 300215
- 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
- Display 'busy' hint in the sync view for diffs that are being reapplied.
- Direction indicator vanishes after merge bug 300656
- bug: Patched project receives 'unmatched' decoration after merge bug 301432
Context menu issues need to fixed before merging to HEAD, see bug 298923.
'Update' means 'Apply' in the Apply Patch worldWe will stick to the Synchronize naming i.e. 'Merge'. bug 300211
- 'Apply' should work for projects, files
and individual hunks.
'Apply' should be disabled for unmatched projects/files/hunks. 'Update' action (equivalent of 'Apply' in patch world) in other synchronizations is enabled for conflicts.
- '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 to 'Patch Contents' model.
- 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. bug 300211
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'. bug 300211
- 'Apply' done on a hunk should affect only the selected hunk not the whole file as it happens now... bug 300214
- ... but for now, disable 'Apply' for all (matched and unmatched) hunks
'Copy All Incoming Changes...' / 'Merge All Non-conflicting Changes' means 'Apply All'We will stick to the Synchronize naming.
- Only 'Incoming' and 'Conflicts' mode should be available
- 'Flat presentation' is meaningless for Patch Model (see also bug 277107)
Make all operations in the Apply Patch wizard be available in the Sync view (when applying a patch). bug 300348
- Re-apply the 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 for Patch Contents model
- 'Open In Compare Editor' for a file should display full file content with changes from all hunks
- bug: 'Open in Compare Editor' for a patch file displays hunks in the structure view, which is fine. The problem is that initially first hunk is selected and 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. It's shown only when a hunk is selected or compare editor has been opened for a hunk.
- bug: ClassCastException when right-clicking in comparison for a file
- Make left side editable
- Refresh contents when local resource changes
All compare editors
- Update context menu, rename Merge, Mark as Merged and Overwrite action as in #Context menu bug 300231
- 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.
- Manually copying changes from right to left causes the copied hunk to appear as conflict in the Sync View.
The code is in HEAD.