Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 333219 - Support creation of patch from synchronize view
Summary: Support creation of patch from synchronize view
Status: NEW
Alias: None
Product: EGit
Classification: Technology
Component: Core (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P3 enhancement with 1 vote (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-12-26 13:48 EST by Andreas Höhmann CLA
Modified: 2015-04-29 17:55 EDT (History)
4 users (show)

See Also:


Attachments
ui mock (69.60 KB, image/png)
2010-12-26 13:49 EST, Andreas Höhmann CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Höhmann CLA 2010-12-26 13:48:18 EST
Build Identifier: 

Like Bug 316523 : it would be nice to create a patch from the synchronization view (via context menu)

Reproducible: Always
Comment 1 Andreas Höhmann CLA 2010-12-26 13:49:02 EST
Created attachment 185819 [details]
ui mock
Comment 2 Andreas Höhmann CLA 2010-12-26 20:31:53 EST
I tried last night to understand the code behind org.eclipse.egit.ui.internal.history.FileDiff.compute(TreeWalk, RevCommit) ... without success :D

Is it impossible to calculate a Diff between the head (last commited state) and a local changed file (changes not commited) ?

I tried to use the Code from org.eclipse.egit.ui.internal.history.command.CreatePatchHandler.execute(ExecutionEvent) to implement 
a new org.eclipse.egit.ui.internal.actions.CreatePatchActionHandler.execute(ExecutionEvent) ... no way :-(

CreatePatchHandler:
			RevCommit commit = (RevCommit) selection.getFirstElement();
            Repository repo = getRepository(event);
			TreeWalk fileWalker = new TreeWalk(repo);
			fileWalker.setRecursive(true);
			fileWalker.setFilter(TreeFilter.ANY_DIFF);
			GitCreatePatchWizard.run(getPart(event), commit, fileWalker, repo);

CreatePatchActionHandler:
        final IResource resource = getSelectedResources(event)[0];
		final RepositoryMapping mapping = RepositoryMapping.getMapping(resource);
		final Repository repository = mapping.getRepository();
		try {
			Ref head = repository.getRef(Constants.HEAD);
			RevWalk rw = new RevWalk(repository);
			RevCommit commit = rw.parseCommit(head.getObjectId());
			final String gitPath = mapping.getRepoRelativePath(resource);
			ITypedElement next = CompareUtils.getFileRevisionTypedElement(gitPath, commit,repository);
	
			TreeWalk fileWalker = new TreeWalk(repository);
			fileWalker.setRecursive(true);
			fileWalker.setFilter(AndTreeFilter.create(PathFilterGroup.createFromStrings(Arrays.asList(gitPath)), TreeFilter.ANY_DIFF));

			GitCreatePatchWizard.run(getPart(event), commit, fileWalker, repository);
			...
			
But I get always a NPE ... 

Caused by: java.lang.NullPointerException
	at org.eclipse.egit.ui.internal.history.FileDiff.trees(FileDiff.java:57)
	at org.eclipse.egit.ui.internal.history.FileDiff.compute(FileDiff.java:69)
	at org.eclipse.egit.ui.internal.history.GitCreatePatchWizard$1.run(GitCreatePatchWizard.java:165)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Root exception:
java.lang.NullPointerException
	at org.eclipse.egit.ui.internal.history.FileDiff.trees(FileDiff.java:57)
	at org.eclipse.egit.ui.internal.history.FileDiff.compute(FileDiff.java:69)
	at org.eclipse.egit.ui.internal.history.GitCreatePatchWizard$1.run(GitCreatePatchWizard.java:165)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)

private static ObjectId[] trees(final RevCommit commit) {
    final ObjectId[] r = new ObjectId[commit.getParentCount() + 1];	
	for (int i = 0; i < r.length - 1; i++) {
			RevCommit parent = commit.getParent(i);
			RevTree tree = parent.getTree();
			// if (tree == null)
			// continue;
			r[i] = tree.getId();
		}
the tree is null ?

Any hint would be nice :D
Comment 3 Benjamin Muskalla CLA 2011-01-18 05:51:10 EST
How about submitting your initial version to Gerrit (maybe prefix it with Draft) so we can look at it together to resolve the problem.