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

Subsystems: the rest

DORMANTno replies

6 messages, 2 authors, 2016-06-15 · open the first message on its own page

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

From: Andy Parkins <hidden>
Date: 2016-06-15 22:43:10

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 <redacted>
---
 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

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

From: Andy Parkins <hidden>
Date: 2016-06-15 22:43:10

On Monday 2007 May 14, Andy Parkins wrote:
When the ident attribute is found for a path, then git replaces $ident$
with:

  $ident: df2a1fd3ebce86876721bd7e12ce02ac89c885db $
Is it too late to request a change to this?  Make the field $Id$.  $Id$ is 
present already in SVN and CVS; it would mean that people converting their 
existing repositories won't have to make any changes to the source files 
should they want to make use of the ident attribute.

Given that it's a feature that's meant to calm those very people, it seems 
obtuse to make them edit every file just to make use of it.

I think that bzr uses $Id$; Mercurial has examples for $Id$; monotone has $Id$ 
on its wishlist.  I can't think of a good reason not to stick with the 
de-facto standard and call ours $Id$ instead of $ident$.

(I accept that this doesn't help those using $Author$, $Rev$, etc, but it's 
better than nothing)


Andy
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com

[PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs

From: Andy Parkins <hidden>
Date: 2016-06-15 22:43:10

$Id$ is present already in SVN and CVS; it would mean that people
converting their existing repositories won't have to make any changes to
the source files should they want to make use of the ident attribute.

Given that it's a feature that's meant to calm those very people, it
seems obtuse to make them edit every file just to make use of it.

I think that bzr uses $Id$; Mercurial has examples hooks for $Id$;
monotone has $Id$ on its wishlist.  I can't think of a good reason not
to stick with the de-facto standard and call ours $Id$ instead of
$ident$.

Signed-off-by: Andy Parkins <redacted>
---

Patch, should anyone agree with the idea.

 convert.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)
diff --git a/convert.c b/convert.c
index 79dfbcf..23257aa 100644
--- a/convert.c
+++ b/convert.c
@@ -412,7 +412,7 @@ static void setup_convert_check(struct git_attr_check *check)
 static int count_ident(const char *cp, unsigned long size)
 {
 	/*
-	 * "$ident: 0000000000000000000000000000000000000000 $" <=> "$ident$"
+	 * "$Id: 0000000000000000000000000000000000000000 $" <=> "$Id$"
 	 */
 	int cnt = 0;
 	char ch;
@@ -466,10 +466,10 @@ static char *ident_to_git(const char *path, const char *src, unsigned long *size
 	for (dst = buf; size; size--) {
 		char ch = *src++;
 		*dst++ = ch;
-		if ((ch == '$') && (6 <= size) &&
-		    !memcmp("ident:", src, 6)) {
-			unsigned long rem = size - 6;
-			const char *cp = src + 6;
+		if ((ch == '$') && (3 <= size) &&
+		    !memcmp("Id:", src, 3)) {
+			unsigned long rem = size - 3;
+			const char *cp = src + 3;
 			do {
 				ch = *cp++;
 				if (ch == '$')
@@ -478,8 +478,8 @@ static char *ident_to_git(const char *path, const char *src, unsigned long *size
 			} while (rem);
 			if (!rem)
 				continue;
-			memcpy(dst, "ident$", 6);
-			dst += 6;
+			memcpy(dst, "Id$", 3);
+			dst += 3;
 			size -= (cp - src);
 			src = cp;
 		}
@@ -511,13 +511,13 @@ static char *ident_to_worktree(const char *path, const char *src, unsigned long
 		const char *cp;
 		char ch = *src++;
 		*dst++ = ch;
-		if ((ch != '$') || (size < 6) || memcmp("ident", src, 5))
+		if ((ch != '$') || (size < 3) || memcmp("Id", src, 2))
 			continue;
 
-		if (src[5] == ':') {
+		if (src[2] == ':') {
 			/* discard up to but not including the closing $ */
-			unsigned long rem = size - 6;
-			cp = src + 6;
+			unsigned long rem = size - 3;
+			cp = src + 3;
 			do {
 				ch = *cp++;
 				if (ch == '$')
@@ -527,13 +527,13 @@ static char *ident_to_worktree(const char *path, const char *src, unsigned long
 			if (!rem)
 				continue;
 			size -= (cp - src);
-		} else if (src[5] == '$')
-			cp = src + 5;
+		} else if (src[2] == '$')
+			cp = src + 2;
 		else
 			continue;
 
-		memcpy(dst, "ident: ", 7);
-		dst += 7;
+		memcpy(dst, "Id: ", 4);
+		dst += 4;
 		memcpy(dst, sha1_to_hex(sha1), ident);
 		dst += ident;
 		*dst++ = ' ';
-- 
1.5.2.rc3.27.g43d151-dirty

Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs

From: Johannes Sixt <hidden>
Date: 2016-06-15 22:43:10

Andy Parkins wrote:
I think that bzr uses $Id$; Mercurial has examples hooks for $Id$;
monotone has $Id$ on its wishlist.  I can't think of a good reason not
to stick with the de-facto standard and call ours $Id$ instead of
$ident$.
I very much agree. I wondered why it was named $ident$ in the first
place. Now that I'm not alone, I thought I'd throw my 2 cents in...

-- Hannes

Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs

From: Andy Parkins <hidden>
Date: 2016-06-15 22:43:10

On Monday 2007 May 14, Johannes Sixt wrote:

Oops: response via private email, obviously intended for git mailing list.
Andy Parkins wrote:
quoted
I think that bzr uses $Id$; Mercurial has examples hooks for $Id$;
monotone has $Id$ on its wishlist.  I can't think of a good reason not
to stick with the de-facto standard and call ours $Id$ instead of
$ident$.
I very much agree. I wondered why it was named $ident$ in the first
place. Now that I'm not alone, I thought I'd throw my 2 cents in...
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com

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

From: Andy Parkins <hidden>
Date: 2016-06-15 22:43:10

On Monday 2007 May 14, Andy Parkins wrote:
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.
Were there any thoughts on this patch?  I think it might have got drowned in 
the noise I made about $ident$ -> $Id$.


Andy
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help