Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 354919 - DiffFormatter#format(List<DiffEntry>) fails unless #scan(ATI, ATI) is called first
Summary: DiffFormatter#format(List<DiffEntry>) fails unless #scan(ATI, ATI) is called ...
Status: RESOLVED FIXED
Alias: None
Product: JGit
Classification: Technology
Component: JGit (show other bugs)
Version: 1.1   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Robin Rosenberg CLA
QA Contact:
URL: http://egit.eclipse.org/r/4036
Whiteboard:
Keywords:
Depends on:
Blocks: 338205
  Show dependency tree
 
Reported: 2011-08-17 05:09 EDT by Tomasz Zarna CLA
Modified: 2011-12-27 09:24 EST (History)
3 users (show)

See Also:


Attachments
mylyn/context/zip (65.38 KB, application/octet-stream)
2011-08-18 07:29 EDT, Tomasz Zarna CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
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