Port git-tag.sh to C.
PATCH 1/1 Port git-tag.sh to C.
From: Kristian Høgsberg <[email protected]>
A more or less straight-forward port of git-tag.sh to C.
---
Ok, here's an updated version that passes the test suite. Johannes, I leave it to you and jasam to merge the bits you find useful, but as far as I see it, this conversion is complete, and there's enough other shell scripts to port. My port doesn't pass jasam's test suite, it looks like he is expecting the -l glob to be a regexp, but the git-tag.sh I started from used shell globs.
Anyways, it'd be nice if you or jasam could keep the list a little more in the loop with the SoC changes, it is where most of the development happens, after all. What's next on your list?
cheers,
Kristian
Makefile | 3 +- builtin-tag.c | 371 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ builtin.h | 1 + git-tag.sh | 183 ---------------------------- git.c | 1 + 5 files changed, 375 insertions(+), 184 deletions(-) create mode 100644 builtin-tag.c delete mode 100755 git-tag.sh
Makefile +2 -1
@@ -205,7 +205,7 @@ SCRIPT_SH = \ git-pull.sh git-rebase.sh \ git-repack.sh git-request-pull.sh git-reset.sh \ git-sh-setup.sh \ - git-tag.sh git-verify-tag.sh \ + git-verify-tag.sh \ git-am.sh \ git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \ git-merge-resolve.sh git-merge-ours.sh \
@@ -372,6 +372,7 @@ BUILTIN_OBJS = \ builtin-show-branch.o \ builtin-stripspace.o \ builtin-symbolic-ref.o \ + builtin-tag.o \ builtin-tar-tree.o \ builtin-unpack-objects.o \ builtin-update-index.o \
builtin-tag.c new file +371 -0
371 lines not on this page · raw message
builtin.h +1 -0
@@ -72,6 +72,7 @@ extern int cmd_show(int argc, const char **argv, const char *prefix);extern int cmd_show_branch (int argc,const char **argv,const char *prefix);extern int cmd_stripspace (int argc,const char **argv,const char *prefix);extern int cmd_symbolic_ref (int argc,const char **argv,const char *prefix); +extern int cmd_tag (int argc,const char **argv,const char *prefix);extern int cmd_tar_tree (int argc,const char **argv,const char *prefix);extern int cmd_unpack_objects (int argc,const char **argv,const char *prefix);extern int cmd_update_index (int argc,const char **argv,const char *prefix);
git-tag.sh deleted +0 -183
183 lines not on this page · raw message
git.c +1 -0
@@ -285,6 +285,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) { "show", cmd_show, RUN_SETUP | USE_PAGER }, { "stripspace", cmd_stripspace }, { "symbolic-ref", cmd_symbolic_ref, RUN_SETUP }, + { "tag", cmd_tag, RUN_SETUP }, { "tar-tree", cmd_tar_tree }, { "unpack-objects", cmd_unpack_objects, RUN_SETUP }, { "update-index", cmd_update_index, RUN_SETUP },
Signature · 1 line
1.5.0.6
2007/6/9, Kristian Høgsberg <[email protected]>:
Quoted 6 lines
Ok, here's an updated version that passes the test suite. Johannes, I leave it to you and jasam to merge the bits you find useful, but as far as I see it, this conversion is complete, and there's enough other shell scripts to port. My port doesn't pass jasam's test suite, it looks like he is expecting the -l glob to be a regexp, but the
git-tag.shI started from used shell globs.
That's a good proposal! I agree with your version for matching tag names, apart from the fact that the code is more compact and readable that way.
I will review your code comparing it with mine and I will report everything I feel. However, my desire is to get builtin-tag.c and its tests t7400-tag.sh complete
in a few days or less, so I would appreciate every other correction from you in order to get it ready faster.
Quoted 3 lines
Anyways, it'd be nice if you or jasam could keep the list a little more in the loop with the SoC changes, it is where most of the development happens, after all. What's next on your list?
You're right, the development will be more open than now was, I usually ask questions in the IRC channel and obviously that's not the best way to report my work to everybody.
Feel free to choose the script which you need to get replaced first, or, depending on your urgency, you could ask me for one of them and I would try to concentrate my efforts on it. Why do you started with git-tag? For me, it was enough easy to begin with, perhaps you could have other reasons.
Looking forward to work with you on that,
Carlos
Quoted 5 lines · Carlos Rica
Feel free to choose the script which you need to get replaced first, or, depending on your urgency, you could ask me for one of them and I would try to concentrate my efforts on it. Why do you started with git-tag? For me, it was enough easy to begin with, perhaps you could have other reasons.
Incidentally, I have been working on fetch, based on Julian Phillips's version. I'm trying to split out the "how do I communicate with remote repositories" code, and use it for pushing and ls-remote as well as fetch. I've got a bunch of not-for-official-history development that you should look at if you try any of the remote-repository-access scripts.
-Daniel
*This .sig left intentionally blank*
git-fetch, was Re: [PATCH] Port git-tag.sh to C.
Hi,
Quoted 8 lines · Daniel Barkalow
Quoted 5 lines · Carlos Rica
Feel free to choose the script which you need to get replaced first, or, depending on your urgency, you could ask me for one of them and I would try to concentrate my efforts on it. Why do you started with git-tag? For me, it was enough easy to begin with, perhaps you could have other reasons.
Quoted 5 lines
Incidentally, I have been working on fetch, based on Julian Phillips's version. I'm trying to split out the "how do I communicate with remote repositories" code, and use it for pushing and ls-remote as well as fetch. I've got a bunch of not-for-official-history development that you should look at if you try any of the remote-repository-access scripts.
How about pushing them onto repo.or.cz as a fork of git.git?
Ciao,
Dscho
Re: git-fetch, was Re: [PATCH] Port git-tag.sh to C.
Quoted 12 lines · Johannes Schindelin
Hi,
Quoted 8 lines · Daniel Barkalow
Quoted 5 lines · Carlos Rica
Feel free to choose the script which you need to get replaced first, or, depending on your urgency, you could ask me for one of them and I would try to concentrate my efforts on it. Why do you started with git-tag? For me, it was enough easy to begin with, perhaps you could have other reasons.
Quoted 7 lines
Quoted 5 lines
Incidentally, I have been working on fetch, based on Julian Phillips's version. I'm trying to split out the "how do I communicate with remote repositories" code, and use it for pushing and ls-remote as well as fetch. I've got a bunch of not-for-official-history development that you should look at if you try any of the remote-repository-access scripts.
How about pushing them onto repo.or.cz as a fork of git.git?
I'd quite like to see these changes too - since I haven't finished the fetch work yet, and I don't want to duplicate effort ;)
(It seems that the closer I get to a working fetch the less time I spend on it ... :$)
Signature · 4 lines
Julian --- Old robot: I choose to believe what I was programmed to believe.
Re: git-fetch, was Re: [PATCH] Port git-tag.sh to C.
Quoted 6 lines · Julian Phillips
Quoted 1 line · Johannes Schindelin
How about pushing them onto repo.or.cz as a fork of git.git?
I'd quite like to see these changes too - since I haven't finished the fetch work yet, and I don't want to duplicate effort ;)
I'll put it up on my server this evening; I forgot to push the latest version from my laptop to somewhere I can get it.
Quoted 2 lines
(It seems that the closer I get to a working fetch the less time I spend on it ... :$)
My efforts have similarly stagnated, but the GSoC talk reminded me that a third person could take over. Although the series I just posted adds branch config parsing, which is helpful for making fetch clean, even if it doesn't make it closer to working completely.
-Daniel
*This .sig left intentionally blank*
Re: git-fetch, was Re: [PATCH] Port git-tag.sh to C.
In reply to Julian PhillipsQuoted 20 lines · Julian Phillips
Quoted 18 lines · Johannes Schindelin
Hi,
Quoted 13 lines · Daniel Barkalow
Quoted 5 lines · Carlos Rica
Feel free to choose the script which you need to get replaced first, or, depending on your urgency, you could ask me for one of them and I would try to concentrate my efforts on it. Why do you started with git-tag? For me, it was enough easy to begin with, perhaps you could have other reasons.
Incidentally, I have been working on fetch, based on Julian Phillips's version. I'm trying to split out the "how do I communicate with remote repositories" code, and use it for pushing and ls-remote as well as fetch. I've got a bunch of not-for-official-history development that you should look at if you try any of the remote-repository-access scripts.
Quoted 4 lines
Quoted 1 line
How about pushing them onto repo.or.cz as a fork of git.git?
I'd quite like to see these changes too - since I haven't finished the fetch work yet, and I don't want to duplicate effort ;)
Okay, git://iabervon.org/~barkalow/git.git builtin-fetch.
-Daniel
*This .sig left intentionally blank*
Re: git-fetch, was Re: [PATCH] Port git-tag.sh to C.
Hi,
Quoted 1 line · Daniel Barkalow
Okay,
git://iabervon.org/~barkalow/git.gitbuiltin-fetch.
Thanks!
Ciao,
Dscho
Quoted 8 lines · Kristian Høgsberg
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
From: Kristian Høgsberg <[email protected]>
A more or less straight-forward port of
git-tag.shto C.Signed-off-by Kristian Høgsberg <[email protected]>Cc Johannes Schindelin <[email protected]>
I think your name in your commit message is in UTF-8 but munged your mail was mismarked as iso-8859-1.
builtin-tag.c line 22
Quoted 3 lines
builtin-tag.c new file +3
-0+static int launch_editor (const char *path,const char *template, +char *buffer,size_t size) +{
It would have been nicer to have this in editor.c or somesuch, as other commands will be redone in C in the future.
We could do the moving later, but the problem is that later is
conditional: "if we are lucky enough to remember that we already have this function in builtin-tag when doing so".
builtin-tag.c line 29
Quoted 1 line
builtin-tag.c new file +1
-0+ fd =open (path,O_CREAT |O_TRUNC |O_WRONLY ,0644 );
I would understand an argument to use 0666 (honor umask) or 0600 (this is a temporary file and others have no business looking at it while an edit is in progress), but I cannot justify 0644.
builtin-tag.c line 52
Quoted 1 line
builtin-tag.c new file +1
-0+ fd =open (path,O_RDONLY ,0644 );
Open for reading with mode ;-)?
Quoted 9 lines
builtin-tag.c new file +9
-0+if (fd ==-1 ) +die ("could not read %s." , path); + len =read_in_full (fd, buffer, size); +if (len <0 ) +die ("failed to read '%s', %m" , path); +close (fd); + + blank_lines =1 ; +for (i =0 , j =0 ; i < len; i++) {
builtin-tag.c line 90
Quoted 10 lines
builtin-tag.c new file +9
-0+ } + +if (buffer[j -1 ] !='\n' ) + buffer[j++] ='\n' ; + +unlink (path); + +return j; +}
I really think this function needs to be refactored into three.
* A generic "spawn an editor with this initial seed template, return the result of editing in memory and also give exit status of the editor" function that does not take path parameter (instead perhaps mkstemp a temporary file on your own);
* A function that does what git-stripspace does in core;
* A function for builtin-tag to use, that calls the above two and uses the result (e.g. "did the user kill the editor? does the resulting buffer have any nonempty line?") to decide what it does.
Quoted 23 lines
builtin-tag.c new file +23
-0+static void create_tag (const unsigned char *object,const char *tag, +const char *message,int sign,unsigned char *result) +{ +enum object_type type; +char buffer[4096 ]; +int header, body, total; + + type =sha1_object_info (object,NULL ); +if (type <=0 ) +die ("bad object type." ); + + header =snprintf (buffer,sizeof buffer, +"object %s\n" +"type %s\n" +"tag %s\n" +"tagger %s\n\n" , +sha1_to_hex (object), +typename (type), + tag, +git_committer_info (1 )); + +if (message ==NULL ) + body = launch_editor(git_path("TAGMSG"), tag_template,
builtin-tag.c line 244
Quoted 10 lines
builtin-tag.c new file +10
-0+ buffer + header, sizeof buffer - header); + else + body =snprintf (buffer + header,sizeof buffer - header, +"%s\n" , message); + +if (body ==0 ) +die ("no tag message?" ); + +if (header + body >sizeof buffer) +die ("tag message too big." );
Two issues:
* It used to be a tag had limit of 8kB which was lifted some time ago; now it is limited to 4kB. Fixing this implies that the "launch editor and get results in core" function I mentioned above may need to realloc, and probably the buffer is better passed as (char *, ulong) pair as done everywhere else (although we know this is text so you can pass only a pointer and have the user run strlen() when needed).
* I do not see any validation on the value of "tag". Do we want to allow passing "" to it? What about "my\ntag"?
Quoted 3 lines · Junio C Hamano
Quoted 1 line
Signed-off-by Kristian Høgsberg <[email protected]>I think your name in your commit message is in UTF-8 but munged your mail was mismarked as iso-8859-1.
This is the same git-send-email bug that we fixed recently (missing MIME-Version header). Just look for the vger "we munged your message" headers in the version you received.
-Peff
Quoted 3 lines · Jeff King
This is the same git-send-email bug that we fixed recently (missing MIME-Version header). Just look for the vger "we munged your message" headers in the version you received.
Ahh. You are right. The message does have these:
X-Warning: Original message contained 8-bit characters, however during
the SMTP transport session the receiving system did not announce capability of receiving 8-bit SMTP (RFC 1651-1653), and as this message does not have MIME headers (RFC 2045-2049) to enable encoding change, we had very little choice.
X-Warning: We ASSUME it is less harmful to add the MIME headers, and
convert the text to Quoted-Printable, than not to do so, and to strip the message to 7-bits.. (RFC 1428 Appendix A)
X-Warning: We don't know what character set the user used, thus we had to
write these MIME-headers with our local system default value.
Quoted 5 lines · Junio C Hamano
Quoted 3 lines
This is the same git-send-email bug that we fixed recently (missing MIME-Version header). Just look for the vger "we munged your message" headers in the version you received.
Ahh. You are right. The message does have these:
Yes, it's easy for me to tell because I get his messages intact. :) Not to mention his X-Mailer mentions git-send-email 1.5.0.6.
Kristian, the fix is in git 1.5.1.5 and later, if it's not too much trouble to upgrade.
-Peff
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Kristian Høgsberg
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
From: Kristian Høgsberg <[email protected]>
Quoted 7 lines
Quoted 4 lines
A more or less straight-forward port of
git-tag.shto C.Signed-off-by Kristian Høgsberg <[email protected]>Cc Johannes Schindelin <[email protected]>I think your name in your commit message is in UTF-8 but munged your mail was mismarked as iso-8859-1.
That's odd both the email I cc'ed to my redhat.com address and the one I got on gmail.com through the list have
Content-Type: text/plain; charset=utf-8
and saving the raw message and asking /usr/bin/file, it tells me its
/home/krh/Desktop/hep: UTF-8 Unicode mail text
Quoted 10 lines
builtin-tag.c line 22
Quoted 3 lines
builtin-tag.c new file +3
-0+static int launch_editor (const char *path,const char *template, +char *buffer,size_t size) +{It would have been nicer to have this in
editor.cor somesuch, as other commands will be redone in C in the future.We could do the moving later, but the problem is that later is
conditional: "if we are lucky enough to remember that we already have this function in builtin-tag when doing so".
Yeah, true. I did write it as a generally usable "launch editor" functions, but I didn't want to move it until there was a second user. Is there anything else that git-commit that will use this, btw?
Quoted 5 lines
builtin-tag.c line 29
Quoted 1 line
builtin-tag.c new file +1
-0+ fd =open (path,O_CREAT |O_TRUNC |O_WRONLY ,0644 );I would understand an argument to use 0666 (honor umask) or 0600 (this is a temporary file and others have no business looking at it while an edit is in progress), but I cannot justify 0644.
Oh hehe, yeah, I didn't think much about the permission bits... 0666 sounds fine.
Quoted 3 lines
builtin-tag.c line 52
Quoted 1 line
builtin-tag.c new file +1
-0+ fd =open (path,O_RDONLY ,0644 );Open for reading with mode ;-)?
Even less thinking here :)
Quoted 28 lines
Quoted 9 lines
builtin-tag.c new file +9
-0+if (fd ==-1 ) +die ("could not read %s." , path); + len =read_in_full (fd, buffer, size); +if (len <0 ) +die ("failed to read '%s', %m" , path); +close (fd); + + blank_lines =1 ; +for (i =0 , j =0 ; i < len; i++) {builtin-tag.c line 90
Quoted 10 lines
builtin-tag.c new file +9
-0+ } + +if (buffer[j -1 ] !='\n' ) + buffer[j++] ='\n' ; + +unlink (path); + +return j; +}I really think this function needs to be refactored into three.
* A generic "spawn an editor with this initial seed template, return the result of editing in memory and also give exit status of the editor" function that does not take path parameter (instead perhaps mkstemp a temporary file on your own);
Quoted 6 lines
* A function that does what git-stripspace does in core;
* A function for builtin-tag to use, that calls the above two and uses the result (e.g. "did the user kill the editor? does the resulting buffer have any nonempty line?") to decide what it does.
and that last function should be useful for git-commit too, no? The reason I didn't split it up was that I don't see any use for the two parts on their own, and the functions is a total of 70 lines. And wouldn't returning 0 bytes for either an empty buffer or editor quit be sufficient? Do we need to handle the two cases differently?
Quoted 36 lines
Quoted 23 lines
builtin-tag.c new file +23
-0+static void create_tag (const unsigned char *object,const char *tag, +const char *message,int sign,unsigned char *result) +{ +enum object_type type; +char buffer[4096 ]; +int header, body, total; + + type =sha1_object_info (object,NULL ); +if (type <=0 ) +die ("bad object type." ); + + header =snprintf (buffer,sizeof buffer, +"object %s\n" +"type %s\n" +"tag %s\n" +"tagger %s\n\n" , +sha1_to_hex (object), +typename (type), + tag, +git_committer_info (1 )); + +if (message ==NULL ) + body = launch_editor(git_path("TAGMSG"), tag_template,builtin-tag.c line 244
Quoted 10 lines
builtin-tag.c new file +10
-0+ buffer + header, sizeof buffer - header); + else + body =snprintf (buffer + header,sizeof buffer - header, +"%s\n" , message); + +if (body ==0 ) +die ("no tag message?" ); + +if (header + body >sizeof buffer) +die ("tag message too big." );Two issues:
Quoted 7 lines
* It used to be a tag had limit of 8kB which was lifted some time ago; now it is limited to 4kB. Fixing this implies that the "launch editor and get results in core" function I mentioned above may need to realloc, and probably the buffer is better passed as (char *, ulong) pair as done everywhere else (although we know this is text so you can pass only a pointer and have the user run
strlen()when needed).
Oh... read_pipe() reallocs... OK. I took the limit from mktag.c and didn't realize that the buffer could get realloced. I did wonder about the xmalloc() for a fixed buffer though...
Quoted 2 lines
* I do not see any validation on the value of "tag". Do we want to allow passing "" to it? What about "my\ntag"?
I do
if (check_ref_format(ref))
die("'%s' is not a valid tag name.", tag);on the ref, which is what git-tag.sh ends up doing, and it catches the two examples you mention:
[krh@dinky git]$ ./git tag "hello
Quoted 1 line
world"
fatal: 'hello
world' is not a valid tag name.
[krh@dinky git]$ ./git tag ""
fatal: '' is not a valid tag name.
so I think it's fine.
But I think I'll leave it to Carlos to finish his builtin-tag work, and he can cherry pick the bits from my patch that work for him. This was more of a friday afternoon hacking sprint, for my part.
cheers,
Kristian
söndag 10 juni 2007 skrev Kristian Høgsberg:
Quoted 15 lines
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Kristian Høgsberg
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
From: Kristian Høgsberg <[email protected]>
Quoted 7 lines
Quoted 4 lines
A more or less straight-forward port of
git-tag.shto C.Signed-off-by Kristian Høgsberg <[email protected]>Cc Johannes Schindelin <[email protected]>I think your name in your commit message is in UTF-8 but munged your mail was mismarked as iso-8859-1.
Quoted 8 lines
That's odd both the email I cc'ed to my redhat.com address and the one I got on gmail.com through the list have
Content-Type: text/plain; charset=utf-8
and saving the raw message and asking
/usr/bin/file, it tells me its
/home/krh/Desktop/hep: UTF-8 Unicode mail text
Maybe Junio's mail server has a problem with the impliction of this header line?
"Content-Transfer-Encoding: 8bit" ?
-- robin
Quoted 12 lines · Robin Rosenberg
söndag 10 juni 2007 skrev Kristian Høgsberg:
Quoted 11 lines
Quoted 4 lines · Junio C Hamano
Kristian Høgsberg <[email protected]> writes:
...
I think your name in your commit message is in UTF-8 but munged your mail was mismarked as iso-8859-1.That's odd both the email I cc'ed to my redhat.com address and the one I got on gmail.com through the list have
Content-Type: text/plain; charset=utf-8
Quoted 7 lines
Quoted 3 lines
and saving the raw message and asking
/usr/bin/file, it tells me its
/home/krh/Desktop/hep: UTF-8 Unicode mail textMaybe Junio's mail server has a problem with the impliction of this header line?
"Content-Transfer-Encoding: 8bit" ?
The copy of Kristian's message gmane has says:
Content-Type: TEXT/PLAIN; charset=ISO-8859-1
I do not think it is just me.