Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 333219

Summary: Support creation of patch from synchronize view
Product: [Technology] EGit Reporter: Andreas Höhmann <andreas.hoehmann>
Component: CoreAssignee: Project Inbox <egit.core-inbox>
Status: NEW --- QA Contact:
Severity: enhancement    
Priority: P3 CC: b.muskalla, Knut.Friedhelm, mauromol, piotr.findeisen
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
ui mock none

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.