* [PATCH JGIT 2/5] FileMode: Store bit masks in int constants
@ 2009-08-12 14:33 Jonas Fonseca
2009-08-12 15:09 ` Jonas Fonseca
0 siblings, 1 reply; 3+ messages in thread
From: Jonas Fonseca @ 2009-08-12 14:33 UTC (permalink / raw)
To: Robin Rosenberg, Shawn O. Pearce; +Cc: git
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
.../src/org/spearce/jgit/lib/FileMode.java | 38 ++++++++++++--------
.../spearce/jgit/treewalk/WorkingTreeIterator.java | 8 ++--
2 files changed, 27 insertions(+), 19 deletions(-)
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH JGIT 2/5] FileMode: Store bit masks in int constants
2009-08-12 14:33 [PATCH JGIT 2/5] FileMode: Store bit masks in int constants Jonas Fonseca
@ 2009-08-12 15:09 ` Jonas Fonseca
2009-08-12 15:22 ` Shawn O. Pearce
0 siblings, 1 reply; 3+ messages in thread
From: Jonas Fonseca @ 2009-08-12 15:09 UTC (permalink / raw)
To: Robin Rosenberg, Shawn O. Pearce; +Cc: git
Signed-off-by: Jonas Fonseca <fonseca@diku.dk>
---
.../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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH JGIT 2/5] FileMode: Store bit masks in int constants
2009-08-12 15:09 ` Jonas Fonseca
@ 2009-08-12 15:22 ` Shawn O. Pearce
0 siblings, 0 replies; 3+ messages in thread
From: Shawn O. Pearce @ 2009-08-12 15:22 UTC (permalink / raw)
To: Jonas Fonseca; +Cc: Robin Rosenberg, git
Jonas Fonseca <fonseca@diku.dk> wrote:
> + 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;
These last 5 entries aren't masks, they are type codes. I'd rather
they be called FOO_TYPE than FOO_MASK. In particular what is really
troubling is MISSING_MASK, being all 0 it always destroys the input
and then matches everything. :-)
I'm going to amend this name change in here, s/_MASK/_TYPE/ on the
last 5 fields.
--
Shawn.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-08-12 15:23 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-12 14:33 [PATCH JGIT 2/5] FileMode: Store bit masks in int constants Jonas Fonseca
2009-08-12 15:09 ` Jonas Fonseca
2009-08-12 15:22 ` Shawn O. Pearce
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).