Allow the ident attribute to include a length specifier
PATCH 1/1 Allow the ident attribute to include a length specifier
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.
--- convert.c | 12 +++++++++--- 1 files changed, 9 insertions(+), 3 deletions(-)
convert.c +9 -3
@@ -534,8 +534,8 @@ static char *ident_to_worktree(const char *path, const char *src, unsigned longmemcpy (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)
Signature · 1 line
1.5.2.rc3.27.g43d151-dirty
Quoted 4 lines · Andy Parkins
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
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
PATCH 1/1 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$.
---
Patch, should anyone agree with the idea.
convert.c | 30 +++++++++++++++--------------- 1 files changed, 15 insertions(+), 15 deletions(-)
convert.c +15 -15
@@ -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 *sizefor (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 longconst 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 longif (!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++ =' ' ;
Signature · 1 line
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
Quoted 4 lines · Andy Parkins
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
On Monday 2007 May 14, Johannes Sixt wrote:
Oops: response via private email, obviously intended for git mailing list.
Quoted 8 lines
Quoted 4 lines · Andy Parkins
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...
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs
In reply to Johannes SixtQuoted 8 lines · Johannes Sixt
Quoted 4 lines · Andy Parkins
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.
Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs
Quoted 2 lines · Junio C Hamano
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.
Quoted 3 lines
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.
Quoted 4 lines
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.
Quoted 4 lines
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
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs
Quoted 8 lines · Andy Parkins
Quoted 4 lines · Junio C Hamano
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(-)
Documentation/RelNotes-1.5.2.txt +1 -1
@@ -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
Documentation/gitattributes.txt +3 -3
@@ -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
convert.c +7 -7
@@ -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++;
t/t0021-conversion.sh +2 -2
@@ -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 '
Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs
Quoted 2 lines · Junio C Hamano
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
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs
Quoted 8 lines · Andy Parkins
Quoted 2 lines · Junio C Hamano
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().
Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs
Quoted 2 lines · Junio C Hamano
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
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Re: [PATCH] Use $Id$ as the ident attribute keyword rather than $ident$ to be consistent with other VCSs
In reply to Andy ParkinsQuoted 4 lines · Andy Parkins
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.
Quoted 7 lines · Andy Parkins
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:
Quoted 8 lines
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
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Quoted 5 lines · Andy Parkins
Quoted 2 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 ;-).