diff src/com/tmate/hgkit/ll/Nodeid.java @ 31:346b66add79d

Basic lookup for incoming changes
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 12 Jan 2011 00:30:55 +0100
parents b2251b7a9823
children 51bc56c0addd
line wrap: on
line diff
--- a/src/com/tmate/hgkit/ll/Nodeid.java	Tue Jan 11 04:49:06 2011 +0100
+++ b/src/com/tmate/hgkit/ll/Nodeid.java	Wed Jan 12 00:30:55 2011 +0100
@@ -3,6 +3,8 @@
  */
 package com.tmate.hgkit.ll;
 
+import static com.tmate.hgkit.ll.DigestHelper.toHexString;
+
 import java.util.Arrays;
 
 
@@ -17,7 +19,7 @@
  */
 public final class Nodeid {
 	
-	public static int NULLREV = -1;
+	public static final Nodeid NULL = new Nodeid(new byte[20], false);
 	private final byte[] binaryData; 
 
 	/**
@@ -53,19 +55,29 @@
 	
 	@Override
 	public String toString() {
-		return new DigestHelper().toHexString(binaryData, 0, binaryData.length);
+		return toHexString(binaryData, 0, binaryData.length);
 	}
-	
+
+	public String shortNotation() {
+		return toHexString(binaryData, 0, 6);
+	}
+
 	// binascii.unhexlify()
 	public static Nodeid fromAscii(byte[] asciiRepresentation, int offset, int length) {
 		if (length != 40) {
 			throw new IllegalArgumentException();
 		}
 		byte[] data = new byte[20];
+		boolean zeroBytes = true;
 		for (int i = 0, j = offset; i < data.length; i++) {
 			int hiNibble = Character.digit(asciiRepresentation[j++], 16);
 			int lowNibble = Character.digit(asciiRepresentation[j++], 16);
-			data[i] = (byte) (((hiNibble << 4) | lowNibble) & 0xFF);
+			byte b = (byte) (((hiNibble << 4) | lowNibble) & 0xFF);
+			data[i] = b;
+			zeroBytes = zeroBytes && b == 0;
+		}
+		if (zeroBytes) {
+			return NULL;
 		}
 		return new Nodeid(data, false);
 	}