[JGIT PATCH 10/12] Use FileMode.MISSING when a file is added or deleted rather than null

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Null is better used to indicate "no mode information at all" in the
patch, while FileMode.MISSING is already commonly used within the
TreeWalk code to mean "this path doesn't exist in this tree".  In
the context of a patch to create or delete a file, MISSING makes a
lot more sense for the application to work with.

Signed-off-by: Shawn O. Pearce <spearce@xxxxxxxxxxx>
---
 .../tst/org/spearce/jgit/patch/FileHeaderTest.java |    4 ++--
 .../tst/org/spearce/jgit/patch/PatchTest.java      |    1 +
 .../src/org/spearce/jgit/patch/FileHeader.java     |    2 ++
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/FileHeaderTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/FileHeaderTest.java
index 36c528e..69e06ab 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/FileHeaderTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/FileHeaderTest.java
@@ -153,7 +153,7 @@ public void testParseUnicodeName_NewFile() {
 		assertSame(FileHeader.PatchType.UNIFIED, fh.getPatchType());
 		assertTrue(fh.hasMetaDataChanges());
 
-		assertNull(fh.getOldMode());
+		assertSame(FileMode.MISSING, fh.getOldMode());
 		assertSame(FileMode.REGULAR_FILE, fh.getNewMode());
 
 		assertEquals("0000000", fh.getOldId().name());
@@ -179,7 +179,7 @@ public void testParseUnicodeName_DeleteFile() {
 		assertTrue(fh.hasMetaDataChanges());
 
 		assertSame(FileMode.REGULAR_FILE, fh.getOldMode());
-		assertNull(fh.getNewMode());
+		assertSame(FileMode.MISSING, fh.getNewMode());
 
 		assertEquals("7898192", fh.getOldId().name());
 		assertEquals("0000000", fh.getNewId().name());
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java
index 13eab5f..2c617d3 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/patch/PatchTest.java
@@ -160,6 +160,7 @@ public void testParse_NoBinary() throws IOException {
 			assertNotNull(fh.getOldId());
 			assertNotNull(fh.getNewId());
 			assertEquals("0000000", fh.getOldId().name());
+			assertSame(FileMode.MISSING, fh.getOldMode());
 			assertSame(FileMode.REGULAR_FILE, fh.getNewMode());
 			assertTrue(fh.getNewName().startsWith(
 					"org.spearce.egit.ui/icons/toolbar/"));
diff --git a/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java b/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java
index f93129d..48d7623 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/patch/FileHeader.java
@@ -386,9 +386,11 @@ int parseGitHeaders(int ptr, final int end) {
 
 			} else if (match(buf, ptr, DELETED_FILE_MODE) >= 0) {
 				oldMode = parseFileMode(ptr + DELETED_FILE_MODE.length, eol);
+				newMode = FileMode.MISSING;
 				changeType = ChangeType.DELETE;
 
 			} else if (match(buf, ptr, NEW_FILE_MODE) >= 0) {
+				oldMode = FileMode.MISSING;
 				newMode = parseFileMode(ptr + NEW_FILE_MODE.length, eol);
 				changeType = ChangeType.ADD;
 
-- 
1.6.1.rc2.306.ge5d5e

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux