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

Bug 354919

Summary: DiffFormatter#format(List<DiffEntry>) fails unless #scan(ATI, ATI) is called first
Product: [Technology] JGit Reporter: Tomasz Zarna <tomasz.zarna>
Component: JGitAssignee: Robin Rosenberg <robin.rosenberg>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: caniszczyk, christian.halstrick, Szymon.Brandys
Version: 1.1   
Target Milestone: ---   
Hardware: PC   
OS: All   
URL: http://egit.eclipse.org/r/4036
Whiteboard:
Bug Depends on:    
Bug Blocks: 338205    
Attachments:
Description Flags
mylyn/context/zip none

Description Tomasz Zarna CLA 2011-08-17 05:09:17 EDT
With bug 334766 fixed I wanted to start using the new command by taking the returned list of DiffEntries and passing it to DiffFormatter#format(List <? extends DiffEntry>)[1]. To my surprise, in some cases it failed with a MissingObjectException. After a quick investigation it turned out that DiffFormatter#format(List<DiffEntry>) cannot be used if #scan(AbstractTreeIterator, AbstractTreeIterator)[2] hasn't been called first. The reason for this is simple, the #scan method updates the pair of sources used access the old and new sides of a DiffEntry[3]. It doesn't happen if you create a DiffFormatter from the scratch, init it properly and then try to call the #format(List<DiffEntry>) method with a list returned by the DiffCommand.

I can think of two solutions here:
* fix the formatter so the #format method can be called in isolation
* hide the method and enhance the DiffCommand so it returns formatted diffs

[1] org.eclipse.jgit.diff.DiffFormatter.format(List<? extends DiffEntry>)
[2] org.eclipse.jgit.diff.DiffFormatter.scan(AbstractTreeIterator, AbstractTreeIterator)
[1] org.eclipse.jgit.diff.DiffFormatter.source
Comment 1 Tomasz Zarna CLA 2011-08-18 07:29:56 EDT
Created attachment 201707 [details]
mylyn/context/zip
Comment 2 Tomasz Zarna CLA 2011-08-18 07:47:33 EDT
Implemented a third solution here: http://egit.eclipse.org/r/4036. The DiffCommand now accepts OutputStream to write line data, so DiffFormat#format(List<DiffEntry>) is no longer called in the command explicitly. The method has been also annotated with a warning that #scan should be called first.
Comment 3 Szymon Brandys CLA 2011-11-03 06:41:59 EDT
Ping.
Comment 4 Tomasz Zarna CLA 2011-12-27 09:24:30 EST
This has been fixed with acd8aee98ac851b0c091bc5c5ea53cb2eaabbad0 Available in JGit 1.3