Re: PATCH[1/4]: Allow tree-id to return the ID of a tree object
Patch to re-introduce cg-Xnormid for common ID normalizing.
Signed-off-by: Philip Pokorny <ppokorny@mindspring.com>
Index: cg-Xnormid
===================================================================
--- /dev/null (tree:6ad600e20c89323c1d3049f75b8ca9b0a2d72167)
+++ uncommitted/cg-Xnormid (mode:100755 sha1:6dc089c8d571f330e2e01d96f79616d6146840ee)
@@ -0,0 +1,47 @@
+#!/usr/bin/env bash
+#
+# Normalize an ID to an SHA1 hash value
+# Strings resolve in order:
+# NULL, this, HEAD => .git/HEAD
+# <tags>
+# <heads>
+# short SHA1 (4 or more hex digits)
+#
+# Copyright (c) Philip Pokorny, 2005
+
+id="$1"
+
+if [ ! "$id" ] || [ "$id" = "this" ] || [ "$id" = "HEAD" ]; then
+ read id < .git/HEAD
+
+elif [ -r ".git/refs/tags/$id" ]; then
+ read id < ".git/refs/tags/$id"
+
+elif [ -r ".git/refs/heads/$id" ]; then
+ read id < ".git/refs/heads/$id"
+
+# Short id's must be lower case and at least 4 digits.
+elif [[ "$id" == [0-9a-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then
+ idpost=${id#??}
+ idpref=${id%$idpost}
+
+ # Assign array elements to matching names
+ idmatch=(.git/objects/$idpref/$idpost*)
+
+ if [ ${#idmatch[*]} -eq 1 ] && [ -r "$idmatch" ]; then
+ id=$idpref${idmatch#.git/objects/$idpref/}
+ elif [ ${#idmatch[*]} -gt 1 ]; then
+ echo "Ambiguous id: $id" >&2
+ exit 1
+ fi
+fi
+
+# FIXME? Should we verify the existance of the ID in the object cache?
+
+# If we don't have a 40-char ID by now, it's an error
+if [ ${#id} -ne 40 ]; then
+ echo "Invalid id: $id" >&2
+ exit 1
+fi
+
+echo $id
Index: Makefile
===================================================================
--- 6ad600e20c89323c1d3049f75b8ca9b0a2d72167/Makefile (mode:100644 sha1:d73bea1cbb9451a89b03d6066bf2ed7fec32fd31)
+++ uncommitted/Makefile (mode:100664)
@@ -44,7 +44,7 @@
cg-add cg-admin-lsobj cg-cancel cg-clone cg-commit cg-diff \
cg-export cg-help cg-init cg-log cg-ls cg-merge cg-mkpatch \
cg-patch cg-pull cg-branch-add cg-branch-ls cg-rm cg-seek cg-status \
- cg-tag cg-update cg-Xlib
+ cg-tag cg-update cg-Xlib cg-Xnormid
COMMON= read-cache.o