threads / patch / 8145

patchAllow the ident attribute to include a length specifier

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

## tl;dr

14 messages between May 14, 2007 and May 17, 2007. Diffs are folded; open one to read it.

replies: 13people: 3as markdown or json

Andy Parkins· May 14, 2007, 13:05 UTC · lore

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 <andyparkins@gmail.com>
---
 convert.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
Show changes to convert.c +9 −3
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
Andy Parkins· May 14, 2007, 13:29 UTC · re: Andy Parkins · lore

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

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
Andy Parkins· May 14, 2007, 13:37 UTC · re: Andy Parkins · lore

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

$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 <andyparkins@gmail.com>
---
Patch, should anyone agree with the idea.
 convert.c |   30 +++++++++++++++---------------
 1 files changed, 15 insertions(+), 15 deletions(-)
Show changes to convert.c +15 −15
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
Johannes Sixt· May 14, 2007, 14:19 UTC · re: Andy Parkins · lore

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

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
Andy Parkins· May 14, 2007, 14:39 UTC · re: Johannes Sixt · lore

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

On Monday 2007 May 14, Johannes Sixt wrote:
Oops: response via private email, obviously intended for git mailing list.
Show 8 quoted lines
> 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...
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com
Junio C Hamano· May 14, 2007, 14:54 UTC · re: Johannes Sixt · lore

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

Johannes Sixt <J.Sixt@eudaptics.com> writes:
Show 8 quoted lines
> 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...

My take when I did the $ident$ stuff on this issue was quite the opposite. CVS "$Id$" means quite a different thing (pathname, per-file revision number, date, and status) and it would not be right to overwrite it with $ident$ which does not record any of those "context sensitive" information.

I did not think other systems making that mistake was not an excuse for us to do so, but on the other hand, if the users of those other systems are happy to lose the information from CVS then perhaps the users do want $Id$.

Obviously I do not care much about this feature and I have not look at Andy's patch too deeply yet, but in any case I think the inverse conversion needs to be modified to match it, if it hasn't been done so.

Andy Parkins· May 14, 2007, 22:24 UTC · re: Junio C Hamano · lore

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

On Monday 2007, May 14, Junio C Hamano wrote:
> My take when I did the $ident$ stuff on this issue was quite the
> opposite.  CVS "$Id$" means quite a different thing (pathname,

You're right, but I think it's intended as a unique identifier rather than that specific information. If that were wanted by a CVS/SVN user they would have used $Author$, $Rev$, $Date$, etc. $Id$ to me was just some way of identifying the file its in uniquely - the fact that git has a much better way of doing that is a bonus, and is exactly right for $Id$ IMHO.

> per-file revision number, date, and status) and it would not be
> right to overwrite it with $ident$ which does not record any of
> those "context sensitive" information.

It would be perfectly correct to overwrite it, as in the repository version none of that information is present, and even if it wasn't, as we've discussed at length, it's all meaningless in a git context anyway - the best thing that you could do for it _is_ overwrite it.

> I did not think other systems making that mistake was not an
> excuse for us to do so, but on the other hand, if the users of
> those other systems are happy to lose the information from CVS
> then perhaps the users do want $Id$.

As I said, there is no information in that field when we import from CVS/SVN - the repository versions are stored with the fields collapsed - so you are not overwriting anything, and therefore not losing information.

> Obviously I do not care much about this feature and I have not
> look at Andy's patch too deeply yet, but in any case I think the
> inverse conversion needs to be modified to match it, if it
> hasn't been done so.

I believe I did the inverse conversion as well. It's only rough, in the end I don't care much either way - I've already converted everything of mine to git so it affects me not at all. I offer it only as a suggestion for imports from other repositories.

Andy
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com
Junio C Hamano· May 15, 2007, 00:17 UTC · re: Andy Parkins · lore

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

Andy Parkins <andyparkins@gmail.com> writes:
> It would be perfectly correct to overwrite it, as in the repository 
> version none of that information is present, and even if it wasn't, as 
> we've discussed at length, it's all meaningless in a git context 
> anyway - the best thing that you could do for it _is_ overwrite it.

Ok, you are right, and we should obviously do this before v1.5.2 final.

Junio C Hamano· May 15, 2007, 02:03 UTC · re: Andy Parkins · lore

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

Andy Parkins <andyparkins@gmail.com> writes:
Show 8 quoted lines
> On Monday 2007, May 14, Junio C Hamano wrote:
>
>> Obviously I do not care much about this feature and I have not
>> look at Andy's patch too deeply yet, but in any case I think the
>> inverse conversion needs to be modified to match it, if it
>> hasn't been done so.
>
> I believe I did the inverse conversion as well.

I think this on top of your patch would be the minimum necessary for v1.5.2.

 Documentation/RelNotes-1.5.2.txt |    2 +-
 Documentation/gitattributes.txt  |    6 +++---
 convert.c                        |   14 +++++++-------
 t/t0021-conversion.sh            |    4 ++--
 4 files changed, 13 insertions(+), 13 deletions(-)
Show changes to 4 files +13 −13

Documentation/RelNotes-1.5.2.txt, Documentation/gitattributes.txt, convert.c, t/t0021-conversion.sh

diff --git a/Documentation/RelNotes-1.5.2.txt b/Documentation/RelNotes-1.5.2.txt
index d1c2cac..7dbdb26 100644
--- a/Documentation/RelNotes-1.5.2.txt
+++ b/Documentation/RelNotes-1.5.2.txt
@@ -26,7 +26,7 @@ Updates since v1.5.1
   considered a binary or text (the former would be treated by
   'git diff' not to produce textual output; the latter can go
   through the line endings conversion process in repositories
-  with core.autocrlf set), expand and unexpand '$ident$' keyword
+  with core.autocrlf set), expand and unexpand '$Id$' keyword
   with blob object name, specify a custom 3-way merge driver,
   and specify a custom diff driver.  You can also apply
   arbitrary filter to contents on check-in/check-out codepath
diff --git a/Documentation/gitattributes.txt b/Documentation/gitattributes.txt
index 8772310..d3ac9c7 100644
--- a/Documentation/gitattributes.txt
+++ b/Documentation/gitattributes.txt
@@ -138,11 +138,11 @@ upon checkout.
 ^^^^^^^
 
 When the attribute `ident` is set to a path, git replaces
-`$ident$` in the blob object with `$ident:`, followed by
+`$Id$` in the blob object with `$Id:`, followed by
 40-character hexadecimal blob object name, followed by a dollar
 sign `$` upon checkout.  Any byte sequence that begins with
-`$ident:` and ends with `$` in the worktree file is replaced
-with `$ident$` upon check-in.
+`$Id:` and ends with `$` in the worktree file is replaced
+with `$Id$` upon check-in.
 
 
 Interaction between checkin/checkout attributes
diff --git a/convert.c b/convert.c
index c46ab1b..12abdaf 100644
--- a/convert.c
+++ b/convert.c
@@ -422,20 +422,20 @@ static int count_ident(const char *cp, unsigned long size)
 		size--;
 		if (ch != '$')
 			continue;
-		if (size < 6)
+		if (size < 3)
 			break;
-		if (memcmp("ident", cp, 5))
+		if (memcmp("Id", cp, 2))
 			continue;
-		ch = cp[5];
-		cp += 6;
-		size -= 6;
+		ch = cp[2];
+		cp += 3;
+		size -= 3;
 		if (ch == '$')
-			cnt++; /* $ident$ */
+			cnt++; /* $Id$ */
 		if (ch != ':')
 			continue;
 
 		/*
-		 * "$ident: ... "; scan up to the closing dollar sign and discard.
+		 * "$Id: ... "; scan up to the closing dollar sign and discard.
 		 */
 		while (size) {
 			ch = *cp++;
diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh
index bab9ecc..6c26fd8 100755
--- a/t/t0021-conversion.sh
+++ b/t/t0021-conversion.sh
@@ -21,7 +21,7 @@ test_expect_success setup '
 	{
 	    echo a b c d e f g h i j k l m
 	    echo n o p q r s t u v w x y z
-	    echo '\''$ident$'\''
+	    echo '\''$Id$'\''
 	} >test &&
 	cat test >test.t &&
 	cat test >test.o &&
@@ -31,7 +31,7 @@ test_expect_success setup '
 	git checkout -- test test.t test.i
 '
 
-script='s/^\$ident: \([0-9a-f]*\) \$/\1/p'
+script='s/^\$Id: \([0-9a-f]*\) \$/\1/p'
 
 test_expect_success check '
 
Andy Parkins· May 15, 2007, 08:14 UTC · re: Junio C Hamano · lore

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

On Tuesday 2007 May 15, Junio C Hamano wrote:
> I think this on top of your patch would be the minimum necessary
> for v1.5.2.

Oops. I think I'm going to mail you a big bat with "Documentation" carved into it that you can use for smacking us (me), for submitting patches without documentation.

Sorry.
Andy
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com
Junio C Hamano· May 15, 2007, 08:54 UTC · re: Andy Parkins · lore

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

Andy Parkins <andyparkins@gmail.com> writes:
Show 8 quoted lines
> On Tuesday 2007 May 15, Junio C Hamano wrote:
>
>> I think this on top of your patch would be the minimum necessary
>> for v1.5.2.
>
> Oops.  I think I'm going to mail you a big bat with
> "Documentation" carved into it that you can use for smacking
> us (me), for submitting patches without documentation.

Actually, Documentation is the least offence. I wanted to have somebody sanity-check the change to count_ident().

Andy Parkins· May 15, 2007, 10:34 UTC · re: Junio C Hamano · lore

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

On Tuesday 2007 May 15, Junio C Hamano wrote:
> Actually, Documentation is the least offence.  I wanted to have
> somebody sanity-check the change to count_ident().

Blimey. It's a good job you're awake. I'm ashamed of myself for missing that. Apologies again. You should have just prodded me - I'm always happy to fix my mistakes; I certainly don't expect you to have to apply patches and fix them as well.

Andy
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com
Andy Parkins· May 17, 2007, 13:53 UTC · re: Andy Parkins · lore

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

On Monday 2007 May 14, Andy Parkins wrote:
Show 15 quoted lines
> 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
Junio C Hamano· May 17, 2007, 19:55 UTC · re: Andy Parkins · lore

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

Andy Parkins <andyparkins@gmail.com> writes:
Show 5 quoted lines
>> 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$.

I was kind of hoping that I can avoid the decision and also I can avoid having to remember it, by waiting long enough and either seeing nobody on the list bring it up again, in which case we can safely forget it, or somebody asks "what happened to this, I want it too!", in which case the original submitter would resubmit after the dust settles after 1.5.2, possibly with a necessary rebase and clean-up. I'll see which one is the case in the coming few weeks ;-).

← back to recent threads