git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 9/9] git-svn: Make fetch ~1.7x faster

From
EWEric Wong <normalperson@yhbt.net>
Date
Oct 24, 2007, 06:34 UTC
Message-ID
<20071024063401.GB10916@soma>
In-Reply-To
<1193118397-4696-10-git-send-email-aroben@apple.com>
Adam Roben <aroben@apple.com> wrote:
> We were spending a lot of time forking/execing git-cat-file and
> git-hash-object. We now use command_bidi_pipe to keep one instance of each
> running and feed it input on stdin.

Nice job! I just got access to a very fast SVN repository for a project I'm working on (not working on git-svn itself, unfortunately).

A few comments and small nitpicks below:
> Signed-off-by: Adam Roben <aroben@apple.com>
> ---
>  git-svn.perl |   94 ++++++++++++++++++++++++++++++++++++++++++++-------------
>  1 files changed, 72 insertions(+), 22 deletions(-)
> +package Git::Commands;

Can this be a separate file, or a part of Git.pm? I'm sure other scripts can eventually use this and I've been meaning to split git-svn.perl into separate files so it's easier to follow.

> +use vars qw/$_cat_blob_pid $_cat_blob_in $_cat_blob_out $_cat_blob_ctx $_cat_blob_separator
> +	    $_hash_object_pid $_hash_object_in $_hash_object_out $_hash_object_ctx/;

I have trouble following long lines, and most of the git code also wraps at 80-columns. Dead-tree publishers got this concept right a long time ago :)

Show 8 quoted lines
> +use strict;
> +use warnings;
> +use File::Temp qw/tempfile/;
> +use Git qw/command_bidi_pipe command_close_bidi_pipe/;
> +
> +sub _open_cat_blob_if_needed {
> +	return if defined($_cat_blob_pid);
> +	$_cat_blob_separator = "--------------GITCATFILESEPARATOR-----------";

Brian brought this up already, but yes, having pre-defined separators instead of explicitly-specified sizes makes it all too easy for a malicious user to commit code that will break things for git-svn users.

Show 8 quoted lines
> +sub hash_object {
> +	my (undef, $fh) = @_;
> +
> +	my ($tmp_fh, $tmp_filename) = tempfile(UNLINK => 1);
> +	while (my $line = <$fh>) {
> +		print $tmp_fh $line;
> +	}
> +	close($tmp_fh);

Related to the above. It's better to sysread()/syswrite() or read()/print() in a loop with a predefined buffer size rather than to use a readline() since you could be dealing with files with very long lines or binaries with no newline characters in them at all.

> +	_open_hash_object_if_needed();
> +	print $_hash_object_out $tmp_filename . "\n";
Minor, but
	print $_hash_object_out $tmp_filename, "\n";
avoids creating a new string.
-- 
Eric Wong
Previous: Johannes SixtNext: Adam Roben
Message 12 of 24 in “Make git-svn fetch ~1.7x faster”
  1. 0/9 Make git-svn fetch ~1.7x fasterAdam Roben, Oct 23, 2007
  2. 1/9 Add tests for git cat-fileAdam Roben, Oct 23, 2007
  3. 2/9 git-cat-file: Small refactor of cmd_cat_fileAdam Roben, Oct 23, 2007
  4. 3/9 git-cat-file: Make option parsing a little more flexibleAdam Roben, Oct 23, 2007
  5. 4/9 git-cat-file: Add --stdin optionAdam Roben, Oct 23, 2007
  6. 5/9 git-cat-file: Add --separator optionAdam Roben, Oct 23, 2007
  7. 6/9 Add tests for git hash-objectAdam Roben, Oct 23, 2007
  8. 7/9 git-hash-object: Add --stdin-paths optionAdam Roben, Oct 23, 2007
  9. 8/9 Git.pm: Add command_bidi_pipe and command_close_bidi_pipeAdam Roben, Oct 23, 2007
  10. 9/9 git-svn: Make fetch ~1.7x fasterAdam Roben, Oct 23, 2007
  11. Johannes SixtOct 23, 2007
  12. Eric WongOct 24, 2007
  13. Adam RobenOct 24, 2007
  14. Shawn O. PearceOct 23, 2007
  15. Adam RobenOct 23, 2007
  16. Shawn O. PearceOct 23, 2007
  17. Eric WongOct 24, 2007
  18. Johannes SixtOct 23, 2007
  19. Brian DowningOct 24, 2007
  20. Adam RobenOct 24, 2007
  21. Johannes SixtOct 23, 2007
  22. Mike HommeyOct 23, 2007
  23. Adam RobenOct 23, 2007
  24. Sam VilainOct 24, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.