Subject: [PATCH] Allow the ident attribute to include a length specifier

From: Andy Parkins <[email-masked]>
Date: Mon, 14 May 2007 14:05:29 +0100

When the ident attribute is found for a path, then git replaces $ident$
with:

  $ident: df2a1fd3ebce86876721bd7e12ce02ac89c885db $

With this patch, you can put the following in your attribute file:

  somepath ident=10

And get expansions like this:

  $ident: df2a1fd3eb $

There is no change to existing behaviour.  With no parameter, the
expansion is all 40 hex digits.

Signed-off-by: Andy Parkins <[email-masked]>
---
 convert.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/convert.c b/convert.c
index 9ee31b0..79dfbcf 100644
--- a/convert.c
+++ b/convert.c
@@ -534,8 +534,8 @@ static char *ident_to_worktree(const char *path, const char *src, unsigned long
 
 		memcpy(dst, "ident: ", 7);
 		dst += 7;
-		memcpy(dst, sha1_to_hex(sha1), 40);
-		dst += 40;
+		memcpy(dst, sha1_to_hex(sha1), ident);
+		dst += ident;
 		*dst++ = ' ';
 		size -= (cp - src);
 		src = cp;
@@ -580,7 +580,13 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)
 {
 	const char *value = check->value;
 
-	return !!ATTR_TRUE(value);
+	if( ATTR_UNSET(value) || ATTR_FALSE(value) )
+		return 0;
+
+	if( ATTR_TRUE(value) )
+		return 40;
+
+	return atoi(value);
 }
 
 char *convert_to_git(const char *path, const char *src, unsigned long *sizep)
-- 
1.5.2.rc3.27.g43d151-dirty