[PATCH JGIT 2/5] FileMode: Store bit masks in int constants

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

 



Signed-off-by: Jonas Fonseca <fonseca@xxxxxxx>
---
 .../src/org/spearce/jgit/lib/FileMode.java         |   38 ++++++++++++--------
 .../spearce/jgit/treewalk/WorkingTreeIterator.java |    8 ++--
 2 files changed, 27 insertions(+), 19 deletions(-)

 Resend without mailer errors ...

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java b/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java
index cf42f37..a1f82f8 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/FileMode.java
@@ -50,21 +50,29 @@
  * </p>
  */
 public abstract class FileMode {
+
+	public static final int TYPE_MASK = 0170000;
+	public static final int TREE_MASK = 0040000;
+	public static final int SYMLINK_MASK = 0120000;
+	public static final int FILE_MASK = 0100000;
+	public static final int GITLINK_MASK = 0160000;
+	public static final int MISSING_MASK = 0000000;
+
 	/** Mode indicating an entry is a {@link Tree}. */
 	@SuppressWarnings("synthetic-access")
-	public static final FileMode TREE = new FileMode(0040000,
+	public static final FileMode TREE = new FileMode(TREE_MASK,
 			Constants.OBJ_TREE) {
 		public boolean equals(final int modeBits) {
-			return (modeBits & 0170000) == 0040000;
+			return (modeBits & TYPE_MASK) == TREE_MASK;
 		}
 	};
 
 	/** Mode indicating an entry is a {@link SymlinkTreeEntry}. */
 	@SuppressWarnings("synthetic-access")
-	public static final FileMode SYMLINK = new FileMode(0120000,
+	public static final FileMode SYMLINK = new FileMode(SYMLINK_MASK,
 			Constants.OBJ_BLOB) {
 		public boolean equals(final int modeBits) {
-			return (modeBits & 0170000) == 0120000;
+			return (modeBits & TYPE_MASK) == SYMLINK_MASK;
 		}
 	};
 
@@ -73,7 +81,7 @@ public boolean equals(final int modeBits) {
 	public static final FileMode REGULAR_FILE = new FileMode(0100644,
 			Constants.OBJ_BLOB) {
 		public boolean equals(final int modeBits) {
-			return (modeBits & 0170000) == 0100000 && (modeBits & 0111) == 0;
+			return (modeBits & TYPE_MASK) == FILE_MASK && (modeBits & 0111) == 0;
 		}
 	};
 
@@ -82,22 +90,22 @@ public boolean equals(final int modeBits) {
 	public static final FileMode EXECUTABLE_FILE = new FileMode(0100755,
 			Constants.OBJ_BLOB) {
 		public boolean equals(final int modeBits) {
-			return (modeBits & 0170000) == 0100000 && (modeBits & 0111) != 0;
+			return (modeBits & TYPE_MASK) == FILE_MASK && (modeBits & 0111) != 0;
 		}
 	};
 
 	/** Mode indicating an entry is a submodule commit in another repository. */
 	@SuppressWarnings("synthetic-access")
-	public static final FileMode GITLINK = new FileMode(0160000,
+	public static final FileMode GITLINK = new FileMode(GITLINK_MASK,
 			Constants.OBJ_COMMIT) {
 		public boolean equals(final int modeBits) {
-			return (modeBits & 0170000) == 0160000;
+			return (modeBits & TYPE_MASK) == GITLINK_MASK;
 		}
 	};
 
 	/** Mode indicating an entry is missing during parallel walks. */
 	@SuppressWarnings("synthetic-access")
-	public static final FileMode MISSING = new FileMode(0000000,
+	public static final FileMode MISSING = new FileMode(MISSING_MASK,
 			Constants.OBJ_BAD) {
 		public boolean equals(final int modeBits) {
 			return modeBits == 0;
@@ -112,20 +120,20 @@ public boolean equals(final int modeBits) {
 	 * @return the FileMode instance that represents the given bits.
 	 */
 	public static final FileMode fromBits(final int bits) {
-		switch (bits & 0170000) {
-		case 0000000:
+		switch (bits & TYPE_MASK) {
+		case MISSING_MASK:
 			if (bits == 0)
 				return MISSING;
 			break;
-		case 0040000:
+		case TREE_MASK:
 			return TREE;
-		case 0100000:
+		case FILE_MASK:
 			if ((bits & 0111) != 0)
 				return EXECUTABLE_FILE;
 			return REGULAR_FILE;
-		case 0120000:
+		case SYMLINK_MASK:
 			return SYMLINK;
-		case 0160000:
+		case GITLINK_MASK:
 			return GITLINK;
 		}
 
diff --git a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
index d4291ea..6003736 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/treewalk/WorkingTreeIterator.java
@@ -134,16 +134,16 @@ protected WorkingTreeIterator(final WorkingTreeIterator p) {
 	public byte[] idBuffer() {
 		if (contentIdFromPtr == ptr)
 			return contentId;
-		switch (mode & 0170000) {
-		case 0100000: /* normal files */
+		switch (mode & FileMode.TYPE_MASK) {
+		case FileMode.FILE_MASK:
 			contentIdFromPtr = ptr;
 			return contentId = idBufferBlob(entries[ptr]);
-		case 0120000: /* symbolic links */
+		case FileMode.SYMLINK_MASK:
 			// Java does not support symbolic links, so we should not
 			// have reached this particular part of the walk code.
 			//
 			return zeroid;
-		case 0160000: /* gitlink */
+		case FileMode.GITLINK_MASK:
 			// TODO: Support obtaining current HEAD SHA-1 from nested repository
 			//
 			return zeroid;
-- 
1.6.4.rc3.195.g2b05f

--
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]