Lines 67-73
Link Here
|
67 |
import org.eclipse.jgit.treewalk.WorkingTreeOptions; |
67 |
import org.eclipse.jgit.treewalk.WorkingTreeOptions; |
68 |
import org.eclipse.jgit.treewalk.filter.PathFilter; |
68 |
import org.eclipse.jgit.treewalk.filter.PathFilter; |
69 |
import org.eclipse.jgit.treewalk.filter.PathFilterGroup; |
69 |
import org.eclipse.jgit.treewalk.filter.PathFilterGroup; |
70 |
import org.netbeans.libs.git.GitClient.DiffMode; |
70 |
import org.netbeans.libs.git.GitClient; |
71 |
import org.netbeans.libs.git.GitException; |
71 |
import org.netbeans.libs.git.GitException; |
72 |
import org.netbeans.libs.git.jgit.GitClassFactory; |
72 |
import org.netbeans.libs.git.jgit.GitClassFactory; |
73 |
import org.netbeans.libs.git.jgit.Utils; |
73 |
import org.netbeans.libs.git.jgit.Utils; |
Lines 82-97
Link Here
|
82 |
public class ExportDiffCommand extends GitCommand { |
82 |
public class ExportDiffCommand extends GitCommand { |
83 |
private final File[] roots; |
83 |
private final File[] roots; |
84 |
private final ProgressMonitor monitor; |
84 |
private final ProgressMonitor monitor; |
85 |
private final DiffMode mode; |
|
|
86 |
private final OutputStream out; |
85 |
private final OutputStream out; |
87 |
private final FileListener listener; |
86 |
private final FileListener listener; |
|
|
87 |
private final String firstCommit; |
88 |
private final String secondCommit; |
88 |
|
89 |
|
89 |
public ExportDiffCommand (Repository repository, GitClassFactory gitFactory, File[] roots, DiffMode mode, OutputStream out, ProgressMonitor monitor, FileListener listener) { |
90 |
public ExportDiffCommand (Repository repository, GitClassFactory gitFactory, |
|
|
91 |
File[] roots, String firstCommit, String secondCommit, |
92 |
OutputStream out, ProgressMonitor monitor, FileListener listener) { |
90 |
super(repository, gitFactory, monitor); |
93 |
super(repository, gitFactory, monitor); |
91 |
this.roots = roots; |
94 |
this.roots = roots; |
92 |
this.monitor = monitor; |
95 |
this.monitor = monitor; |
93 |
this.listener = listener; |
96 |
this.listener = listener; |
94 |
this.mode = mode; |
97 |
this.firstCommit = firstCommit; |
|
|
98 |
this.secondCommit = secondCommit; |
95 |
this.out = out; |
99 |
this.out = out; |
96 |
} |
100 |
} |
97 |
|
101 |
|
Lines 111-136
Link Here
|
111 |
// work-around for autocrlf |
115 |
// work-around for autocrlf |
112 |
formatter.setDiffComparator(new AutoCRLFComparator()); |
116 |
formatter.setDiffComparator(new AutoCRLFComparator()); |
113 |
} |
117 |
} |
114 |
AbstractTreeIterator firstTree; |
118 |
or = repository.newObjectReader(); |
115 |
AbstractTreeIterator secondTree; |
119 |
AbstractTreeIterator firstTree = getIterator(firstCommit, or); |
116 |
switch (mode) { |
120 |
AbstractTreeIterator secondTree = getIterator(secondCommit, or); |
117 |
case HEAD_VS_INDEX: |
|
|
118 |
or = repository.newObjectReader(); |
119 |
firstTree = getHeadIterator(or); |
120 |
secondTree = new DirCacheIterator(repository.readDirCache()); |
121 |
break; |
122 |
case HEAD_VS_WORKINGTREE: |
123 |
or = repository.newObjectReader(); |
124 |
firstTree = getHeadIterator(or); |
125 |
secondTree = new FileTreeIterator(repository); |
126 |
break; |
127 |
case INDEX_VS_WORKINGTREE: |
128 |
firstTree = new DirCacheIterator(repository.readDirCache()); |
129 |
secondTree = new FileTreeIterator(repository); |
130 |
break; |
131 |
default: |
132 |
throw new IllegalArgumentException("Unknown diff mode: " + mode); |
133 |
} |
134 |
List<DiffEntry> diffEntries; |
121 |
List<DiffEntry> diffEntries; |
135 |
if (secondTree instanceof WorkingTreeIterator) { |
122 |
if (secondTree instanceof WorkingTreeIterator) { |
136 |
// remote when fixed in JGit, see ExportDiffTest.testDiffRenameDetectionProblem |
123 |
// remote when fixed in JGit, see ExportDiffTest.testDiffRenameDetectionProblem |
Lines 140-148
Link Here
|
140 |
RenameDetector detector = formatter.getRenameDetector(); |
127 |
RenameDetector detector = formatter.getRenameDetector(); |
141 |
detector.reset(); |
128 |
detector.reset(); |
142 |
detector.addAll(diffEntries); |
129 |
detector.addAll(diffEntries); |
143 |
if (or == null) { |
|
|
144 |
or = repository.newObjectReader(); |
145 |
} |
146 |
diffEntries = detector.compute(new ContentSource.Pair(ContentSource.create(or), ContentSource.create((WorkingTreeIterator) secondTree)), NullProgressMonitor.INSTANCE); |
130 |
diffEntries = detector.compute(new ContentSource.Pair(ContentSource.create(or), ContentSource.create((WorkingTreeIterator) secondTree)), NullProgressMonitor.INSTANCE); |
147 |
} else { |
131 |
} else { |
148 |
formatter.setDetectRenames(true); |
132 |
formatter.setDetectRenames(true); |
Lines 166-171
Link Here
|
166 |
} |
150 |
} |
167 |
} |
151 |
} |
168 |
|
152 |
|
|
|
153 |
private AbstractTreeIterator getIterator (String commit, ObjectReader or) throws IOException, GitException { |
154 |
Repository repository = getRepository(); |
155 |
switch (commit) { |
156 |
case Constants.HEAD: |
157 |
return getHeadIterator(or); |
158 |
case GitClient.INDEX: |
159 |
return new DirCacheIterator(repository.readDirCache()); |
160 |
case GitClient.WORKING_TREE: |
161 |
return new FileTreeIterator(repository); |
162 |
default: |
163 |
CanonicalTreeParser p = new CanonicalTreeParser(); |
164 |
p.reset(or, Utils.findCommit(repository, commit).getTree()); |
165 |
return p; |
166 |
} |
167 |
} |
168 |
|
169 |
@Override |
169 |
@Override |
170 |
protected String getCommandDescription () { |
170 |
protected String getCommandDescription () { |
171 |
StringBuilder sb = new StringBuilder("git diff"); //NOI18N |
171 |
StringBuilder sb = new StringBuilder("git diff"); //NOI18N |