summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorMatthias Sohn <matthias.sohn@sap.com>2015-07-17 16:22:56 +0200
committerSaša Živkov <sasa.zivkov@sap.com>2016-02-04 17:49:42 +0100
commit536db18cc62afab2d38aac5b2af73f575f40d8b6 (patch)
tree94dccd9b5a11010044efd27f126bd21a94d5a665 /org.eclipse.jgit
parent2de33d7678ffe865e44fc5007ee5fc59afa03404 (diff)
downloadjgit-536db18cc62afab2d38aac5b2af73f575f40d8b6.tar.gz
jgit-536db18cc62afab2d38aac5b2af73f575f40d8b6.zip
Implement SHA-256 abstraction
The Large File Storage extension specified by GitHub [1] uses SHA-256 to compute the ID of large files stored by the extension. Hence implement a SHA-256 abstraction similar to the SHA-1 abstraction used by JGit. [1] https://git-lfs.github.com/ Bug: 470333 Change-Id: I3a95954543c8570d73929e55f4a884b55dbf1b7a Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java33
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java66
2 files changed, 98 insertions, 1 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
index 85c1648a0a..8536f1dc25 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/NB.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
+ * Copyright (C) 2008, 2015 Shawn O. Pearce <spearce@spearce.org>
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -66,6 +66,37 @@ public final class NB {
}
/**
+ * Compare a 64 bit unsigned integer stored in a 64 bit signed integer.
+ * <p>
+ * This function performs an unsigned compare operation, even though Java
+ * does not natively support unsigned integer values. Negative numbers are
+ * treated as larger than positive ones.
+ *
+ * @param a
+ * the first value to compare.
+ * @param b
+ * the second value to compare.
+ * @return &lt; 0 if a &lt; b; 0 if a == b; &gt; 0 if a &gt; b.
+ * @since 4.3
+ */
+ public static int compareUInt64(final long a, final long b) {
+ long cmp = (a >>> 1) - (b >>> 1);
+ if (cmp > 0) {
+ return 1;
+ } else if (cmp < 0) {
+ return -1;
+ }
+ cmp = ((a & 1) - (b & 1));
+ if (cmp > 0) {
+ return 1;
+ } else if (cmp < 0) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+
+ /**
* Convert sequence of 2 bytes (network byte order) into unsigned value.
*
* @param intbuf
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java
index f2955f7e6b..86777b9cdc 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/RawParseUtils.java
@@ -366,6 +366,72 @@ public final class RawParseUtils {
}
/**
+ * Parse 16 character base 16 (hex) formatted string to unsigned long.
+ * <p>
+ * The number is read in network byte order, that is, most significant
+ * nibble first.
+ *
+ * @param bs
+ * buffer to parse digits from; positions {@code [p, p+16)} will
+ * be parsed.
+ * @param p
+ * first position within the buffer to parse.
+ * @return the integer value.
+ * @throws ArrayIndexOutOfBoundsException
+ * if the string is not hex formatted.
+ * @since 4.3
+ */
+ public static final long parseHexInt64(final byte[] bs, final int p) {
+ long r = digits16[bs[p]] << 4;
+
+ r |= digits16[bs[p + 1]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 2]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 3]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 4]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 5]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 6]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 7]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 8]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 9]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 10]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 11]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 12]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 13]];
+ r <<= 4;
+
+ r |= digits16[bs[p + 14]];
+
+ final int last = digits16[bs[p + 15]];
+ if (r < 0 || last < 0)
+ throw new ArrayIndexOutOfBoundsException();
+ return (r << 4) | last;
+ }
+
+ /**
* Parse a single hex digit to its numeric value (0-15).
*
* @param digit