Merge branch 'stable-4.3' into stable-4.4
* stable-4.3: Fix computation of id in WorkingTreeIterator with autocrlf and smudging Prepare 4.3.2-SNAPSHOT builds JGit v4.3.1.201605051710-r Scan loose ref before packed in case gc about to remove the loose Fix possible NPEs when reporting transport errors Fix calling of clean/smudge filters from Checkout,MergeCommands Fix ApplyCommand when result of patch is an empty file Change-Id: I829f06699f6670e519d04c927bdba4b82df29199 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
commit
fc0ec94bc3
Binary file not shown.
Binary file not shown.
|
@ -146,6 +146,16 @@ public void testModifyE() throws Exception {
|
||||||
b.getString(0, b.size(), false));
|
b.getString(0, b.size(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testModifyW() throws Exception {
|
||||||
|
ApplyResult result = init("W");
|
||||||
|
assertEquals(1, result.getUpdatedFiles().size());
|
||||||
|
assertEquals(new File(db.getWorkTree(), "W"),
|
||||||
|
result.getUpdatedFiles().get(0));
|
||||||
|
checkFile(new File(db.getWorkTree(), "W"),
|
||||||
|
b.getString(0, b.size(), false));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testModifyX() throws Exception {
|
public void testModifyX() throws Exception {
|
||||||
ApplyResult result = init("X");
|
ApplyResult result = init("X");
|
||||||
|
|
|
@ -88,7 +88,6 @@
|
||||||
import org.eclipse.jgit.transport.URIish;
|
import org.eclipse.jgit.transport.URIish;
|
||||||
import org.eclipse.jgit.util.FileUtils;
|
import org.eclipse.jgit.util.FileUtils;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class CheckoutCommandTest extends RepositoryTestCase {
|
public class CheckoutCommandTest extends RepositoryTestCase {
|
||||||
|
@ -740,11 +739,9 @@ public void testSmudgeFilter_deleteFileAndCreateBranchAndRestoreFromCommit()
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Ignore
|
public void testSmudgeAndClean() throws Exception {
|
||||||
public void testSmudgeAndClean() throws IOException, GitAPIException {
|
File clean_filter = writeTempFile("sed s/V1/@version/g");
|
||||||
// @TODO: fix this test
|
File smudge_filter = writeTempFile("sed s/@version/V1/g");
|
||||||
File clean_filter = writeTempFile("sed s/V1/@version/g -");
|
|
||||||
File smudge_filter = writeTempFile("sed s/@version/V1/g -");
|
|
||||||
|
|
||||||
try (Git git2 = new Git(db)) {
|
try (Git git2 = new Git(db)) {
|
||||||
StoredConfig config = git.getRepository().getConfig();
|
StoredConfig config = git.getRepository().getConfig();
|
||||||
|
@ -753,33 +750,39 @@ public void testSmudgeAndClean() throws IOException, GitAPIException {
|
||||||
config.setString("filter", "tstFilter", "clean",
|
config.setString("filter", "tstFilter", "clean",
|
||||||
"sh " + slashify(clean_filter.getPath()));
|
"sh " + slashify(clean_filter.getPath()));
|
||||||
config.save();
|
config.save();
|
||||||
writeTrashFile(".gitattributes", "*.txt filter=tstFilter");
|
writeTrashFile(".gitattributes", "filterTest.txt filter=tstFilter");
|
||||||
git2.add().addFilepattern(".gitattributes").call();
|
git2.add().addFilepattern(".gitattributes").call();
|
||||||
git2.commit().setMessage("add attributes").call();
|
git2.commit().setMessage("add attributes").call();
|
||||||
|
|
||||||
writeTrashFile("filterTest.txt", "hello world, V1");
|
fsTick(writeTrashFile("filterTest.txt", "hello world, V1\n"));
|
||||||
git2.add().addFilepattern("filterTest.txt").call();
|
git2.add().addFilepattern("filterTest.txt").call();
|
||||||
git2.commit().setMessage("add filterText.txt").call();
|
RevCommit one = git2.commit().setMessage("add filterText.txt").call();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
|
"[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:hello world, @version\n]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
|
||||||
git2.checkout().setCreateBranch(true).setName("test2").call();
|
fsTick(writeTrashFile("filterTest.txt", "bon giorno world, V1\n"));
|
||||||
writeTrashFile("filterTest.txt", "bon giorno world, V1");
|
|
||||||
git2.add().addFilepattern("filterTest.txt").call();
|
git2.add().addFilepattern("filterTest.txt").call();
|
||||||
git2.commit().setMessage("modified filterText.txt").call();
|
RevCommit two = git2.commit().setMessage("modified filterTest.txt").call();
|
||||||
|
|
||||||
assertTrue(git2.status().call().isClean());
|
assertTrue(git2.status().call().isClean());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:bon giorno world, @version]",
|
"[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:bon giorno world, @version\n]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
|
|
||||||
git2.checkout().setName("refs/heads/test").call();
|
git2.checkout().setName(one.getName()).call();
|
||||||
assertTrue(git2.status().call().isClean());
|
assertTrue(git2.status().call().isClean());
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"[.gitattributes, mode:100644, content:*.txt filter=tstFilter][Test.txt, mode:100644, content:Some other change][filterTest.txt, mode:100644, content:hello world, @version]",
|
"[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:hello world, @version\n]",
|
||||||
indexState(CONTENT));
|
indexState(CONTENT));
|
||||||
assertEquals("hello world, V1", read("filterTest.txt"));
|
assertEquals("hello world, V1\n", read("filterTest.txt"));
|
||||||
|
|
||||||
|
git2.checkout().setName(two.getName()).call();
|
||||||
|
assertTrue(git2.status().call().isClean());
|
||||||
|
assertEquals(
|
||||||
|
"[.gitattributes, mode:100644, content:filterTest.txt filter=tstFilter][Test.txt, mode:100644, content:Some change][filterTest.txt, mode:100644, content:bon giorno world, @version\n]",
|
||||||
|
indexState(CONTENT));
|
||||||
|
assertEquals("bon giorno world, V1\n", read("filterTest.txt"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@
|
||||||
import org.eclipse.jgit.api.errors.NoFilepatternException;
|
import org.eclipse.jgit.api.errors.NoFilepatternException;
|
||||||
import org.eclipse.jgit.attributes.Attribute;
|
import org.eclipse.jgit.attributes.Attribute;
|
||||||
import org.eclipse.jgit.dircache.DirCache;
|
import org.eclipse.jgit.dircache.DirCache;
|
||||||
|
import org.eclipse.jgit.dircache.DirCacheEditor;
|
||||||
import org.eclipse.jgit.dircache.DirCacheEntry;
|
import org.eclipse.jgit.dircache.DirCacheEntry;
|
||||||
import org.eclipse.jgit.dircache.DirCacheIterator;
|
import org.eclipse.jgit.dircache.DirCacheIterator;
|
||||||
import org.eclipse.jgit.errors.RevisionSyntaxException;
|
import org.eclipse.jgit.errors.RevisionSyntaxException;
|
||||||
|
@ -61,9 +62,11 @@
|
||||||
import org.eclipse.jgit.lib.CoreConfig.EOL;
|
import org.eclipse.jgit.lib.CoreConfig.EOL;
|
||||||
import org.eclipse.jgit.lib.FileMode;
|
import org.eclipse.jgit.lib.FileMode;
|
||||||
import org.eclipse.jgit.lib.ObjectLoader;
|
import org.eclipse.jgit.lib.ObjectLoader;
|
||||||
|
import org.eclipse.jgit.revwalk.RevCommit;
|
||||||
import org.eclipse.jgit.storage.file.FileBasedConfig;
|
import org.eclipse.jgit.storage.file.FileBasedConfig;
|
||||||
import org.eclipse.jgit.treewalk.FileTreeIterator;
|
import org.eclipse.jgit.treewalk.FileTreeIterator;
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk;
|
import org.eclipse.jgit.treewalk.TreeWalk;
|
||||||
|
import org.eclipse.jgit.util.FS;
|
||||||
import org.eclipse.jgit.util.IO;
|
import org.eclipse.jgit.util.IO;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
@ -82,6 +85,14 @@ public class EolRepositoryTest extends RepositoryTestCase {
|
||||||
|
|
||||||
private static final FileMode F = FileMode.REGULAR_FILE;
|
private static final FileMode F = FileMode.REGULAR_FILE;
|
||||||
|
|
||||||
|
@DataPoint
|
||||||
|
public static boolean doSmudgeEntries = true;
|
||||||
|
|
||||||
|
@DataPoint
|
||||||
|
public static boolean dontSmudgeEntries = false;
|
||||||
|
|
||||||
|
private boolean smudge;
|
||||||
|
|
||||||
@DataPoint
|
@DataPoint
|
||||||
public static String smallContents[] = {
|
public static String smallContents[] = {
|
||||||
generateTestData(3, 1, true, false),
|
generateTestData(3, 1, true, false),
|
||||||
|
@ -117,10 +128,11 @@ static String generateTestData(int size, int lineSize, boolean withCRLF,
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public EolRepositoryTest(String[] testContent) {
|
public EolRepositoryTest(String[] testContent, boolean smudgeEntries) {
|
||||||
CONTENT_CRLF = testContent[0];
|
CONTENT_CRLF = testContent[0];
|
||||||
CONTENT_LF = testContent[1];
|
CONTENT_LF = testContent[1];
|
||||||
CONTENT_MIXED = testContent[2];
|
CONTENT_MIXED = testContent[2];
|
||||||
|
this.smudge = smudgeEntries;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String CONTENT_CRLF;
|
protected String CONTENT_CRLF;
|
||||||
|
@ -160,7 +172,7 @@ private static class ActualEntry {
|
||||||
|
|
||||||
private ActualEntry entryMixed = new ActualEntry();
|
private ActualEntry entryMixed = new ActualEntry();
|
||||||
|
|
||||||
private DirCache dc;
|
private DirCache dirCache;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDefaultSetup() throws Exception {
|
public void testDefaultSetup() throws Exception {
|
||||||
|
@ -177,8 +189,10 @@ public void checkEntryContent(ActualEntry entry, String fileContent,
|
||||||
String indexContent) {
|
String indexContent) {
|
||||||
assertEquals(fileContent, entry.file);
|
assertEquals(fileContent, entry.file);
|
||||||
assertEquals(indexContent, entry.index);
|
assertEquals(indexContent, entry.index);
|
||||||
|
if (entry.indexContentLength != 0) {
|
||||||
assertEquals(fileContent.length(), entry.indexContentLength);
|
assertEquals(fileContent.length(), entry.indexContentLength);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test_ConfigAutoCRLF_false() throws Exception {
|
public void test_ConfigAutoCRLF_false() throws Exception {
|
||||||
|
@ -584,6 +598,14 @@ private void setupGitAndDoHardReset(AutoCRLF autoCRLF, EOL eol,
|
||||||
dotGitattributes = null;
|
dotGitattributes = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fileCRLF = createAndAddFile(git, "file1.txt", "a");
|
||||||
|
|
||||||
|
fileLF = createAndAddFile(git, "file2.txt", "a");
|
||||||
|
|
||||||
|
fileMixed = createAndAddFile(git, "file3.txt", "a");
|
||||||
|
|
||||||
|
RevCommit c = gitCommit(git, "create files");
|
||||||
|
|
||||||
fileCRLF = createAndAddFile(git, "file1.txt", CONTENT_CRLF);
|
fileCRLF = createAndAddFile(git, "file1.txt", CONTENT_CRLF);
|
||||||
|
|
||||||
fileLF = createAndAddFile(git, "file2.txt", CONTENT_LF);
|
fileLF = createAndAddFile(git, "file2.txt", CONTENT_LF);
|
||||||
|
@ -593,6 +615,26 @@ private void setupGitAndDoHardReset(AutoCRLF autoCRLF, EOL eol,
|
||||||
gitCommit(git, "addFiles");
|
gitCommit(git, "addFiles");
|
||||||
|
|
||||||
recreateWorktree(git);
|
recreateWorktree(git);
|
||||||
|
|
||||||
|
if (smudge) {
|
||||||
|
DirCache dc = DirCache.lock(git.getRepository().getIndexFile(),
|
||||||
|
FS.detect());
|
||||||
|
DirCacheEditor editor = dc.editor();
|
||||||
|
for (int i = 0; i < dc.getEntryCount(); i++) {
|
||||||
|
editor.add(new DirCacheEditor.PathEdit(
|
||||||
|
dc.getEntry(i).getPathString()) {
|
||||||
|
public void apply(DirCacheEntry ent) {
|
||||||
|
ent.smudgeRacilyClean();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
editor.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// @TODO: find out why the following assertion would break the tests
|
||||||
|
// assertTrue(git.status().call().isClean());
|
||||||
|
git.checkout().setName(c.getName()).call();
|
||||||
|
git.checkout().setName("master").call();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void recreateWorktree(Git git)
|
private void recreateWorktree(Git git)
|
||||||
|
@ -610,8 +652,8 @@ private void recreateWorktree(Git git)
|
||||||
gitAdd(git, ".");
|
gitAdd(git, ".");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void gitCommit(Git git, String msg) throws GitAPIException {
|
protected RevCommit gitCommit(Git git, String msg) throws GitAPIException {
|
||||||
git.commit().setMessage(msg).call();
|
return git.commit().setMessage(msg).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void gitAdd(Git git, String path) throws GitAPIException {
|
protected void gitAdd(Git git, String path) throws GitAPIException {
|
||||||
|
@ -644,7 +686,7 @@ private File createAndAddFile(Git git, String path, String content)
|
||||||
}
|
}
|
||||||
|
|
||||||
private void collectRepositoryState() throws Exception {
|
private void collectRepositoryState() throws Exception {
|
||||||
dc = db.readDirCache();
|
dirCache = db.readDirCache();
|
||||||
walk = beginWalk();
|
walk = beginWalk();
|
||||||
if (dotGitattributes != null)
|
if (dotGitattributes != null)
|
||||||
collectEntryContentAndAttributes(F, ".gitattributes", null);
|
collectEntryContentAndAttributes(F, ".gitattributes", null);
|
||||||
|
@ -680,7 +722,7 @@ private void collectEntryContentAndAttributes(FileMode type, String pathName,
|
||||||
e.attrs = e.attrs.trim();
|
e.attrs = e.attrs.trim();
|
||||||
e.file = new String(
|
e.file = new String(
|
||||||
IO.readFully(new File(db.getWorkTree(), pathName)));
|
IO.readFully(new File(db.getWorkTree(), pathName)));
|
||||||
DirCacheEntry dce = dc.getEntry(pathName);
|
DirCacheEntry dce = dirCache.getEntry(pathName);
|
||||||
ObjectLoader open = walk.getObjectReader().open(dce.getObjectId());
|
ObjectLoader open = walk.getObjectReader().open(dce.getObjectId());
|
||||||
e.index = new String(open.getBytes());
|
e.index = new String(open.getBytes());
|
||||||
e.indexContentLength = dce.getLength();
|
e.indexContentLength = dce.getLength();
|
||||||
|
|
|
@ -223,12 +223,16 @@ private void apply(File f, FileHeader fh)
|
||||||
pos++;
|
pos++;
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
if (!newLines.get(hh.getNewStartLine() - 1 + pos).equals(
|
if (hh.getNewStartLine() == 0) {
|
||||||
hunkLine.substring(1))) {
|
newLines.clear();
|
||||||
|
} else {
|
||||||
|
if (!newLines.get(hh.getNewStartLine() - 1 + pos)
|
||||||
|
.equals(hunkLine.substring(1))) {
|
||||||
throw new PatchApplyException(MessageFormat.format(
|
throw new PatchApplyException(MessageFormat.format(
|
||||||
JGitText.get().patchApplyException, hh));
|
JGitText.get().patchApplyException, hh));
|
||||||
}
|
}
|
||||||
newLines.remove(hh.getNewStartLine() - 1 + pos);
|
newLines.remove(hh.getNewStartLine() - 1 + pos);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case '+':
|
case '+':
|
||||||
newLines.add(hh.getNewStartLine() - 1 + pos,
|
newLines.add(hh.getNewStartLine() - 1 + pos,
|
||||||
|
@ -250,7 +254,9 @@ private void apply(File f, FileHeader fh)
|
||||||
// still there!
|
// still there!
|
||||||
sb.append(l).append('\n');
|
sb.append(l).append('\n');
|
||||||
}
|
}
|
||||||
|
if (sb.length() > 0) {
|
||||||
sb.deleteCharAt(sb.length() - 1);
|
sb.deleteCharAt(sb.length() - 1);
|
||||||
|
}
|
||||||
FileWriter fw = new FileWriter(f);
|
FileWriter fw = new FileWriter(f);
|
||||||
fw.write(sb.toString());
|
fw.write(sb.toString());
|
||||||
fw.close();
|
fw.close();
|
||||||
|
|
|
@ -280,8 +280,9 @@ public void preScanTwoTrees() throws CorruptObjectException, IOException {
|
||||||
|
|
||||||
addTree(walk, headCommitTree);
|
addTree(walk, headCommitTree);
|
||||||
addTree(walk, mergeCommitTree);
|
addTree(walk, mergeCommitTree);
|
||||||
walk.addTree(new DirCacheBuildIterator(builder));
|
int dciPos = walk.addTree(new DirCacheBuildIterator(builder));
|
||||||
walk.addTree(workingTree);
|
walk.addTree(workingTree);
|
||||||
|
workingTree.setDirCacheIterator(walk, dciPos);
|
||||||
|
|
||||||
while (walk.next()) {
|
while (walk.next()) {
|
||||||
processEntry(walk.getTree(0, CanonicalTreeParser.class),
|
processEntry(walk.getTree(0, CanonicalTreeParser.class),
|
||||||
|
@ -320,8 +321,9 @@ public void prescanOneTree()
|
||||||
|
|
||||||
walk = new NameConflictTreeWalk(repo);
|
walk = new NameConflictTreeWalk(repo);
|
||||||
addTree(walk, mergeCommitTree);
|
addTree(walk, mergeCommitTree);
|
||||||
walk.addTree(new DirCacheBuildIterator(builder));
|
int dciPos = walk.addTree(new DirCacheBuildIterator(builder));
|
||||||
walk.addTree(workingTree);
|
walk.addTree(workingTree);
|
||||||
|
workingTree.setDirCacheIterator(walk, dciPos);
|
||||||
|
|
||||||
while (walk.next()) {
|
while (walk.next()) {
|
||||||
processEntry(walk.getTree(0, CanonicalTreeParser.class),
|
processEntry(walk.getTree(0, CanonicalTreeParser.class),
|
||||||
|
@ -1093,8 +1095,10 @@ private void cleanUpConflicts() throws CheckoutConflictException {
|
||||||
private boolean isModifiedSubtree_IndexWorkingtree(String path)
|
private boolean isModifiedSubtree_IndexWorkingtree(String path)
|
||||||
throws CorruptObjectException, IOException {
|
throws CorruptObjectException, IOException {
|
||||||
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) {
|
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(repo)) {
|
||||||
tw.addTree(new DirCacheIterator(dc));
|
int dciPos = tw.addTree(new DirCacheIterator(dc));
|
||||||
tw.addTree(new FileTreeIterator(repo));
|
FileTreeIterator fti = new FileTreeIterator(repo);
|
||||||
|
tw.addTree(fti);
|
||||||
|
fti.setDirCacheIterator(tw, dciPos);
|
||||||
tw.setRecursive(true);
|
tw.setRecursive(true);
|
||||||
tw.setFilter(PathFilter.create(path));
|
tw.setFilter(PathFilter.create(path));
|
||||||
DirCacheIterator dcIt;
|
DirCacheIterator dcIt;
|
||||||
|
|
|
@ -312,11 +312,10 @@ public Ref getRef(final String needle) throws IOException {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Ref> getRefs(String prefix) throws IOException {
|
public Map<String, Ref> getRefs(String prefix) throws IOException {
|
||||||
final RefList<Ref> packed = getPackedRefs();
|
|
||||||
final RefList<LooseRef> oldLoose = looseRefs.get();
|
final RefList<LooseRef> oldLoose = looseRefs.get();
|
||||||
|
|
||||||
LooseScanner scan = new LooseScanner(oldLoose);
|
LooseScanner scan = new LooseScanner(oldLoose);
|
||||||
scan.scan(prefix);
|
scan.scan(prefix);
|
||||||
|
final RefList<Ref> packed = getPackedRefs();
|
||||||
|
|
||||||
RefList<LooseRef> loose;
|
RefList<LooseRef> loose;
|
||||||
if (scan.newLoose != null) {
|
if (scan.newLoose != null) {
|
||||||
|
|
|
@ -1005,13 +1005,14 @@ protected boolean mergeTrees(AbstractTreeIterator baseTree,
|
||||||
builder = dircache.builder();
|
builder = dircache.builder();
|
||||||
DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
|
DirCacheBuildIterator buildIt = new DirCacheBuildIterator(builder);
|
||||||
|
|
||||||
tw = new NameConflictTreeWalk(reader);
|
tw = new NameConflictTreeWalk(db, reader);
|
||||||
tw.addTree(baseTree);
|
tw.addTree(baseTree);
|
||||||
tw.addTree(headTree);
|
tw.addTree(headTree);
|
||||||
tw.addTree(mergeTree);
|
tw.addTree(mergeTree);
|
||||||
tw.addTree(buildIt);
|
int dciPos = tw.addTree(buildIt);
|
||||||
if (workingTreeIterator != null) {
|
if (workingTreeIterator != null) {
|
||||||
tw.addTree(workingTreeIterator);
|
tw.addTree(workingTreeIterator);
|
||||||
|
workingTreeIterator.setDirCacheIterator(tw, dciPos);
|
||||||
} else {
|
} else {
|
||||||
tw.setFilter(TreeFilter.ANY_DIFF);
|
tw.setFilter(TreeFilter.ANY_DIFF);
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,7 +106,7 @@ private static class InCoreMerger extends ThreeWayMerger {
|
||||||
|
|
||||||
InCoreMerger(final Repository local) {
|
InCoreMerger(final Repository local) {
|
||||||
super(local);
|
super(local);
|
||||||
tw = new NameConflictTreeWalk(reader);
|
tw = new NameConflictTreeWalk(local, reader);
|
||||||
cache = DirCache.newInCore();
|
cache = DirCache.newInCore();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -579,17 +579,31 @@ public Attributes getAttributes() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param opType
|
||||||
|
* the operationtype (checkin/checkout) which should be used
|
||||||
|
* @return the EOL stream type of the current entry using the config and
|
||||||
|
* {@link #getAttributes()} Note that this method may return null if
|
||||||
|
* the {@link TreeWalk} is not based on a working tree
|
||||||
|
*/
|
||||||
|
// TODO(msohn) make this method public in 4.4
|
||||||
|
@Nullable
|
||||||
|
EolStreamType getEolStreamType(OperationType opType) {
|
||||||
|
if (attributesNodeProvider == null || config == null)
|
||||||
|
return null;
|
||||||
|
return EolStreamTypeUtil.detectStreamType(opType,
|
||||||
|
config.get(WorkingTreeOptions.KEY), getAttributes());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the EOL stream type of the current entry using the config and
|
* @return the EOL stream type of the current entry using the config and
|
||||||
* {@link #getAttributes()} Note that this method may return null if
|
* {@link #getAttributes()} Note that this method may return null if
|
||||||
* the {@link TreeWalk} is not based on a working tree
|
* the {@link TreeWalk} is not based on a working tree
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
|
// TODO(msohn) deprecate this method in 4.4
|
||||||
public @Nullable EolStreamType getEolStreamType() {
|
public @Nullable EolStreamType getEolStreamType() {
|
||||||
if (attributesNodeProvider == null || config == null)
|
return (getEolStreamType(operationType));
|
||||||
return null;
|
|
||||||
return EolStreamTypeUtil.detectStreamType(operationType,
|
|
||||||
config.get(WorkingTreeOptions.KEY), getAttributes());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Reset this walker so new tree iterators can be added to it. */
|
/** Reset this walker so new tree iterators can be added to it. */
|
||||||
|
|
|
@ -86,6 +86,7 @@
|
||||||
import org.eclipse.jgit.lib.ObjectReader;
|
import org.eclipse.jgit.lib.ObjectReader;
|
||||||
import org.eclipse.jgit.lib.Repository;
|
import org.eclipse.jgit.lib.Repository;
|
||||||
import org.eclipse.jgit.submodule.SubmoduleWalk;
|
import org.eclipse.jgit.submodule.SubmoduleWalk;
|
||||||
|
import org.eclipse.jgit.treewalk.TreeWalk.OperationType;
|
||||||
import org.eclipse.jgit.util.FS;
|
import org.eclipse.jgit.util.FS;
|
||||||
import org.eclipse.jgit.util.FS.ExecutionResult;
|
import org.eclipse.jgit.util.FS.ExecutionResult;
|
||||||
import org.eclipse.jgit.util.Holder;
|
import org.eclipse.jgit.util.Holder;
|
||||||
|
@ -361,7 +362,8 @@ private byte[] idBufferBlob(final Entry e) {
|
||||||
state.initializeDigestAndReadBuffer();
|
state.initializeDigestAndReadBuffer();
|
||||||
|
|
||||||
final long len = e.getLength();
|
final long len = e.getLength();
|
||||||
InputStream filteredIs = possiblyFilteredInputStream(e, is, len);
|
InputStream filteredIs = possiblyFilteredInputStream(e, is, len,
|
||||||
|
OperationType.CHECKIN_OP);
|
||||||
return computeHash(filteredIs, canonLen);
|
return computeHash(filteredIs, canonLen);
|
||||||
} finally {
|
} finally {
|
||||||
safeClose(is);
|
safeClose(is);
|
||||||
|
@ -374,8 +376,15 @@ private byte[] idBufferBlob(final Entry e) {
|
||||||
|
|
||||||
private InputStream possiblyFilteredInputStream(final Entry e,
|
private InputStream possiblyFilteredInputStream(final Entry e,
|
||||||
final InputStream is, final long len) throws IOException {
|
final InputStream is, final long len) throws IOException {
|
||||||
|
return possiblyFilteredInputStream(e, is, len, null);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputStream possiblyFilteredInputStream(final Entry e,
|
||||||
|
final InputStream is, final long len, OperationType opType)
|
||||||
|
throws IOException {
|
||||||
if (getCleanFilterCommand() == null
|
if (getCleanFilterCommand() == null
|
||||||
&& getEolStreamType() == EolStreamType.DIRECT) {
|
&& getEolStreamType(opType) == EolStreamType.DIRECT) {
|
||||||
canonLen = len;
|
canonLen = len;
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
@ -385,7 +394,7 @@ && getEolStreamType() == EolStreamType.DIRECT) {
|
||||||
byte[] raw = rawbuf.array();
|
byte[] raw = rawbuf.array();
|
||||||
int n = rawbuf.limit();
|
int n = rawbuf.limit();
|
||||||
if (!isBinary(raw, n)) {
|
if (!isBinary(raw, n)) {
|
||||||
rawbuf = filterClean(raw, n);
|
rawbuf = filterClean(raw, n, opType);
|
||||||
raw = rawbuf.array();
|
raw = rawbuf.array();
|
||||||
n = rawbuf.limit();
|
n = rawbuf.limit();
|
||||||
}
|
}
|
||||||
|
@ -398,13 +407,14 @@ && getEolStreamType() == EolStreamType.DIRECT) {
|
||||||
return is;
|
return is;
|
||||||
}
|
}
|
||||||
|
|
||||||
final InputStream lenIs = filterClean(e.openInputStream());
|
final InputStream lenIs = filterClean(e.openInputStream(),
|
||||||
|
opType);
|
||||||
try {
|
try {
|
||||||
canonLen = computeLength(lenIs);
|
canonLen = computeLength(lenIs);
|
||||||
} finally {
|
} finally {
|
||||||
safeClose(lenIs);
|
safeClose(lenIs);
|
||||||
}
|
}
|
||||||
return filterClean(is);
|
return filterClean(is, opType);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void safeClose(final InputStream in) {
|
private static void safeClose(final InputStream in) {
|
||||||
|
@ -430,17 +440,23 @@ private static boolean isBinary(Entry entry) throws IOException {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteBuffer filterClean(byte[] src, int n) throws IOException {
|
private ByteBuffer filterClean(byte[] src, int n, OperationType opType)
|
||||||
|
throws IOException {
|
||||||
InputStream in = new ByteArrayInputStream(src);
|
InputStream in = new ByteArrayInputStream(src);
|
||||||
try {
|
try {
|
||||||
return IO.readWholeStream(filterClean(in), n);
|
return IO.readWholeStream(filterClean(in, opType), n);
|
||||||
} finally {
|
} finally {
|
||||||
safeClose(in);
|
safeClose(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream filterClean(InputStream in) throws IOException {
|
private InputStream filterClean(InputStream in) throws IOException {
|
||||||
in = handleAutoCRLF(in);
|
return filterClean(in, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputStream filterClean(InputStream in, OperationType opType)
|
||||||
|
throws IOException {
|
||||||
|
in = handleAutoCRLF(in, opType);
|
||||||
String filterCommand = getCleanFilterCommand();
|
String filterCommand = getCleanFilterCommand();
|
||||||
if (filterCommand != null) {
|
if (filterCommand != null) {
|
||||||
FS fs = repository.getFS();
|
FS fs = repository.getFS();
|
||||||
|
@ -469,8 +485,9 @@ filterCommand, getEntryPathString(),
|
||||||
return in;
|
return in;
|
||||||
}
|
}
|
||||||
|
|
||||||
private InputStream handleAutoCRLF(InputStream in) throws IOException {
|
private InputStream handleAutoCRLF(InputStream in, OperationType opType)
|
||||||
return EolStreamTypeUtil.wrapInputStream(in, getEolStreamType());
|
throws IOException {
|
||||||
|
return EolStreamTypeUtil.wrapInputStream(in, getEolStreamType(opType));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1332,10 +1349,28 @@ public String getCleanFilterCommand() throws IOException {
|
||||||
* @since 4.3
|
* @since 4.3
|
||||||
*/
|
*/
|
||||||
public EolStreamType getEolStreamType() throws IOException {
|
public EolStreamType getEolStreamType() throws IOException {
|
||||||
|
return getEolStreamType(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param opType
|
||||||
|
* The operationtype (checkin/checkout) which should be used
|
||||||
|
* @return the eol stream type for the current entry or <code>null</code> if
|
||||||
|
* it cannot be determined. When state or state.walk is null or the
|
||||||
|
* {@link TreeWalk} is not based on a {@link Repository} then null
|
||||||
|
* is returned.
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
private EolStreamType getEolStreamType(OperationType opType)
|
||||||
|
throws IOException {
|
||||||
if (eolStreamTypeHolder == null) {
|
if (eolStreamTypeHolder == null) {
|
||||||
EolStreamType type=null;
|
EolStreamType type=null;
|
||||||
if (state.walk != null) {
|
if (state.walk != null) {
|
||||||
|
if (opType != null) {
|
||||||
|
type = state.walk.getEolStreamType(opType);
|
||||||
|
} else {
|
||||||
type=state.walk.getEolStreamType();
|
type=state.walk.getEolStreamType();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
switch (getOptions().getAutoCRLF()) {
|
switch (getOptions().getAutoCRLF()) {
|
||||||
case FALSE:
|
case FALSE:
|
||||||
|
|
|
@ -189,7 +189,8 @@ public static int response(final HttpConnection c) throws IOException {
|
||||||
try {
|
try {
|
||||||
return c.getResponseCode();
|
return c.getResponseCode();
|
||||||
} catch (ConnectException ce) {
|
} catch (ConnectException ce) {
|
||||||
final String host = c.getURL().getHost();
|
final URL url = c.getURL();
|
||||||
|
final String host = (url == null) ? "<null>" : url.getHost();
|
||||||
// The standard J2SE error message is not very useful.
|
// The standard J2SE error message is not very useful.
|
||||||
//
|
//
|
||||||
if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$
|
if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$
|
||||||
|
@ -216,7 +217,8 @@ public static int response(final java.net.HttpURLConnection c)
|
||||||
try {
|
try {
|
||||||
return c.getResponseCode();
|
return c.getResponseCode();
|
||||||
} catch (ConnectException ce) {
|
} catch (ConnectException ce) {
|
||||||
final String host = c.getURL().getHost();
|
final URL url = c.getURL();
|
||||||
|
final String host = (url == null) ? "<null>" : url.getHost();
|
||||||
// The standard J2SE error message is not very useful.
|
// The standard J2SE error message is not very useful.
|
||||||
//
|
//
|
||||||
if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$
|
if ("Connection timed out: connect".equals(ce.getMessage())) //$NON-NLS-1$
|
||||||
|
|
Loading…
Reference in New Issue