From 9e848013968959bd4de5d407c2ee91cb960c53bb Mon Sep 17 00:00:00 2001 From: Matthias Kestenholz Date: Tue, 29 Aug 2006 11:12:14 +0200 Subject: [PATCH 01/13] Check if pack directory exists prior to descending into it This fixes the following warning: git-repack: line 42: cd: .git/objects/pack: No such file or directory This happens only, when git-repack -a is run without any packs in the repository. Signed-off-by: Matthias Kestenholz Signed-off-by: Junio C Hamano --- git-repack.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-repack.sh b/git-repack.sh index 9da92fb061..584a7323ac 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -38,7 +38,7 @@ case ",$all_into_one," in pack_objects= # Redundancy check in all-into-one case is trivial. - existing=`cd "$PACKDIR" && \ + existing=`test -d "$PACKDIR" && cd "$PACKDIR" && \ find . -type f \( -name '*.pack' -o -name '*.idx' \) -print` ;; esac From 071fa89e25855a746728b835359eb263c7c7ee7f Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 29 Aug 2006 11:47:30 -0700 Subject: [PATCH 02/13] git-fsck-objects: lacking default references should not be fatal The comment added says it all: if we have lost all references in a git archive, git-fsck-objects should still work, so instead of dying it should just notify the user about that condition. This change was triggered by me just doing a "git-init-db" and then populating that empty git archive with a pack/index file to look at it. Having git-fsck-objects not work just because I didn't have any references handy was rather irritating, since part of the reason for running git-fsck-objects in the first place was to _find_ the missing references. However, "--unreachable" really doesn't make sense in that situation, and we want to turn it off to protect anybody who uses the old "git prune" shell-script (rather than the modern built-in). The old pruning script used to remove all objects that were reported as unreachable, and without any refs, that obviously means everything - not worth it. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- fsck-objects.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/fsck-objects.c b/fsck-objects.c index ae0ec8d039..24286de15d 100644 --- a/fsck-objects.c +++ b/fsck-objects.c @@ -425,8 +425,23 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1) static void get_default_heads(void) { for_each_ref(fsck_handle_ref); - if (!default_refs) - die("No default references"); + + /* + * Not having any default heads isn't really fatal, but + * it does mean that "--unreachable" no longer makes any + * sense (since in this case everything will obviously + * be unreachable by definition. + * + * Showing dangling objects is valid, though (as those + * dangling objects are likely lost heads). + * + * So we just print a warning about it, and clear the + * "show_unreachable" flag. + */ + if (!default_refs) { + error("No default references"); + show_unreachable = 0; + } } static void fsck_object_dir(const char *path) From c9b0597d3d3168e29f68b0e82fa755ee165f6b72 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 29 Aug 2006 12:50:29 +0200 Subject: [PATCH 03/13] unpack-objects: remove unused variable "eof" Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-unpack-objects.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/builtin-unpack-objects.c b/builtin-unpack-objects.c index ca0ebc2585..0c180b53a3 100644 --- a/builtin-unpack-objects.c +++ b/builtin-unpack-objects.c @@ -15,7 +15,7 @@ static const char unpack_usage[] = "git-unpack-objects [-n] [-q] < pack-file"; /* We always read in 4kB chunks. */ static unsigned char buffer[4096]; -static unsigned long offset, len, eof; +static unsigned long offset, len; static SHA_CTX ctx; /* @@ -26,8 +26,6 @@ static void * fill(int min) { if (min <= len) return buffer + offset; - if (eof) - die("unable to fill input"); if (min > sizeof(buffer)) die("cannot fill %d bytes", min); if (offset) { From 104ff34a742672b360b1da2b7d7668a14da551c2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 29 Aug 2006 12:51:14 +0200 Subject: [PATCH 04/13] Makefile: fix typo We checked NO_SETENV instead of NO_UNSETENV to decide if unsetenv is available. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index a608476405..05bd77f967 100644 --- a/Makefile +++ b/Makefile @@ -496,7 +496,7 @@ ifdef NO_SETENV COMPAT_CFLAGS += -DNO_SETENV COMPAT_OBJS += compat/setenv.o endif -ifdef NO_SETENV +ifdef NO_UNSETENV COMPAT_CFLAGS += -DNO_UNSETENV COMPAT_OBJS += compat/unsetenv.o endif From 28f5c70b859e02e6b688bf35605678680c08045b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 29 Aug 2006 13:02:35 +0200 Subject: [PATCH 05/13] Remove uneeded #include Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- peek-remote.c | 1 - receive-pack.c | 1 - 2 files changed, 2 deletions(-) diff --git a/peek-remote.c b/peek-remote.c index 2b30980b04..87f1543fec 100644 --- a/peek-remote.c +++ b/peek-remote.c @@ -1,7 +1,6 @@ #include "cache.h" #include "refs.h" #include "pkt-line.h" -#include static const char peek_remote_usage[] = "git-peek-remote [--exec=upload-pack] [host:]directory"; diff --git a/receive-pack.c b/receive-pack.c index 201531626c..78f75da5ca 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -2,7 +2,6 @@ #include "refs.h" #include "pkt-line.h" #include "run-command.h" -#include static const char receive_pack_usage[] = "git-receive-pack "; From fc1c75ec74c372670f01f22c68193156a445728a Mon Sep 17 00:00:00 2001 From: Franck Bui-Huu Date: Tue, 29 Aug 2006 13:37:06 +0200 Subject: [PATCH 06/13] log-tree.c: cleanup a bit append_signoff() This patch clean up append_signoff() by moving specific code that looks up for "^[-A-Za-z]+: [^@]+@" pattern into a function. It also stops the primary search when the cursor oversteps 'buf + at' limit. This patch changes slightly append_signoff() behaviour too. If we detect any Signed-off-by pattern during the primary search, we needn't to do a pattern research after. Signed-off-by: Franck Bui-Huu Signed-off-by: Junio C Hamano --- log-tree.c | 116 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 66 insertions(+), 50 deletions(-) diff --git a/log-tree.c b/log-tree.c index 54cdaa4d81..fbe139920a 100644 --- a/log-tree.c +++ b/log-tree.c @@ -12,10 +12,58 @@ static void show_parents(struct commit *commit, int abbrev) } } +/* + * Search for "^[-A-Za-z]+: [^@]+@" pattern. It usually matches + * Signed-off-by: and Acked-by: lines. + */ +static int detect_any_signoff(char *letter, int size) +{ + char ch, *cp; + int seen_colon = 0; + int seen_at = 0; + int seen_name = 0; + int seen_head = 0; + + cp = letter + size; + while (letter <= --cp && (ch = *cp) == '\n') + continue; + + while (letter <= cp) { + ch = *cp--; + if (ch == '\n') + break; + + if (!seen_at) { + if (ch == '@') + seen_at = 1; + continue; + } + if (!seen_colon) { + if (ch == '@') + return 0; + else if (ch == ':') + seen_colon = 1; + else + seen_name = 1; + continue; + } + if (('A' <= ch && ch <= 'Z') || + ('a' <= ch && ch <= 'z') || + ch == '-') { + seen_head = 1; + continue; + } + /* no empty last line doesn't match */ + return 0; + } + return seen_head && seen_name; +} + static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) { - int signoff_len = strlen(signoff); static const char signed_off_by[] = "Signed-off-by: "; + int signoff_len = strlen(signoff); + int has_signoff = 0; char *cp = buf; /* Do we have enough space to add it? */ @@ -23,58 +71,26 @@ static int append_signoff(char *buf, int buf_sz, int at, const char *signoff) return at; /* First see if we already have the sign-off by the signer */ - while (1) { - cp = strstr(cp, signed_off_by); - if (!cp) - break; + while ((cp = strstr(cp, signed_off_by))) { + + has_signoff = 1; + cp += strlen(signed_off_by); - if ((cp + signoff_len < buf + at) && - !strncmp(cp, signoff, signoff_len) && - isspace(cp[signoff_len])) - return at; /* we already have him */ + if (cp + signoff_len >= buf + at) + break; + if (strncmp(cp, signoff, signoff_len)) + continue; + if (!isspace(cp[signoff_len])) + continue; + /* we already have him */ + return at; } - /* Does the last line already end with "^[-A-Za-z]+: [^@]+@"? - * If not, add a blank line to separate the message from - * the run of Signed-off-by: and Acked-by: lines. - */ - { - char ch; - int seen_colon, seen_at, seen_name, seen_head, not_signoff; - seen_colon = 0; - seen_at = 0; - seen_name = 0; - seen_head = 0; - not_signoff = 0; - cp = buf + at; - while (buf <= --cp && (ch = *cp) == '\n') - ; - while (!not_signoff && buf <= cp && (ch = *cp--) != '\n') { - if (!seen_at) { - if (ch == '@') - seen_at = 1; - continue; - } - if (!seen_colon) { - if (ch == '@') - not_signoff = 1; - else if (ch == ':') - seen_colon = 1; - else - seen_name = 1; - continue; - } - if (('A' <= ch && ch <= 'Z') || - ('a' <= ch && ch <= 'z') || - ch == '-') { - seen_head = 1; - continue; - } - not_signoff = 1; - } - if (not_signoff || !seen_head || !seen_name) - buf[at++] = '\n'; - } + if (!has_signoff) + has_signoff = detect_any_signoff(buf, at); + + if (!has_signoff) + buf[at++] = '\n'; strcpy(buf + at, signed_off_by); at += strlen(signed_off_by); From 3a36bc846949df8a7fb0ad9b2fc8ffe294cdca7c Mon Sep 17 00:00:00 2001 From: Dennis Stosberg Date: Thu, 31 Aug 2006 21:32:45 +0200 Subject: [PATCH 07/13] gitweb: Remove forgotten call to git_to_hash On Aug 27th, Jakub Narebski sent a patch which removed the git_to_hash() function and this call to it. The patch did not apply cleanly and had to be applied manually. Removing the last chunk has obviously been forgotten. See: commit 0aea33762b1262d11fb43eda9f3fc152b5622cca and message <200608272345.26722.jnareb@gmail.com> Signed-off-by: Dennis Stosberg Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 9324d71ebe..68f40bda8f 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -2778,10 +2778,6 @@ sub git_blobdiff { @difftree or die_error('404 Not Found', "Blob diff not found"); - } elsif (defined $hash) { # try to find filename from $hash - if ($hash !~ /[0-9a-fA-F]{40}/) { - $hash = git_to_hash($hash); - } } elsif (defined $hash && $hash =~ /[0-9a-fA-F]{40}/) { # try to find filename from $hash From 4b5dc988c0db1e7ce5ba41c09a1e75cbc71c3f35 Mon Sep 17 00:00:00 2001 From: Dennis Stosberg Date: Tue, 29 Aug 2006 09:19:02 +0200 Subject: [PATCH 08/13] use do() instead of require() to include configuration When run under mod_perl, require() will read and execute the configuration file on the first invocation only. On every subsequent invocation, all configuration variables will be reset to their default values. do() reads and executes the configuration file unconditionally. Signed-off-by: Dennis Stosberg Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 68f40bda8f..7922c3ce54 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -152,7 +152,7 @@ sub feature_snapshot { our @diff_opts = ('-M'); # taken from git_commit our $GITWEB_CONFIG = $ENV{'GITWEB_CONFIG'} || "++GITWEB_CONFIG++"; -require $GITWEB_CONFIG if -e $GITWEB_CONFIG; +do $GITWEB_CONFIG if -e $GITWEB_CONFIG; # version of the core git binary our $git_version = qx($GIT --version) =~ m/git version (.*)$/ ? $1 : "unknown"; From cb849b46ac68feea716a45fd1de99cfdd71123d0 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 31 Aug 2006 00:32:15 +0200 Subject: [PATCH 09/13] gitweb: Move git-ls-tree output parsing to parse_ls_tree_line Add new subroutine parse_ls_tree_line and use it in git_tree. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 62 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 7922c3ce54..758032af64 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1034,6 +1034,27 @@ sub parse_difftree_raw_line { return wantarray ? %res : \%res; } +# parse line of git-ls-tree output +sub parse_ls_tree_line ($;%) { + my $line = shift; + my %opts = @_; + my %res; + + #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' + $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; + + $res{'mode'} = $1; + $res{'type'} = $2; + $res{'hash'} = $3; + if ($opts{'-z'}) { + $res{'name'} = $4; + } else { + $res{'name'} = unquote($4); + } + + return wantarray ? %res : \%res; +} + ## ...................................................................... ## parse to array of hashes functions @@ -2512,51 +2533,54 @@ sub git_tree { print "\n"; my $alternate = 0; foreach my $line (@entries) { - #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' - $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/; - my $t_mode = $1; - my $t_type = $2; - my $t_hash = $3; - my $t_name = validate_input($4); + my %t = parse_ls_tree_line($line, -z => 1); + if ($alternate) { print "\n"; } else { print "\n"; } $alternate ^= 1; - print "\n"; - if ($t_type eq "blob") { + + print "\n"; + if ($t{'type'} eq "blob") { print "\n" . "\n"; - } elsif ($t_type eq "tree") { + } elsif ($t{'type'} eq "tree") { print "\n" . "\n"; } From fa702003e4f63ecdc71d16b51efc02f33fe7931f Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 31 Aug 2006 00:35:07 +0200 Subject: [PATCH 10/13] gitweb: Separate printing of git_tree row into git_print_tree_entry This is preparation for "tree blame" (similar to what ViewVC shows) output, i.e. for each entry give commit where it was changed. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 103 ++++++++++++++++++++++++++------------------- 1 file changed, 59 insertions(+), 44 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 758032af64..7f6bdaa951 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1475,6 +1475,62 @@ sub git_print_simplified_log { -remove_title => $remove_title); } +# print tree entry (row of git_tree), but without encompassing element +sub git_print_tree_entry { + my ($t, $basedir, $hash_base, $have_blame) = @_; + + my %base_key = (); + $base_key{hash_base} = $hash_base if defined $hash_base; + + print "\n"; + if ($t->{'type'} eq "blob") { + print "\n" . + "\n"; + + } elsif ($t->{'type'} eq "tree") { + print "\n" . + "\n"; + } +} + ## ...................................................................... ## functions printing large fragments of HTML @@ -2513,14 +2569,13 @@ sub git_tree { my $refs = git_get_references(); my $ref = format_ref_marker($refs, $hash_base); git_header_html(); - my %base_key = (); my $base = ""; my $have_blame = gitweb_check_feature('blame'); if (defined $hash_base && (my %co = parse_commit($hash_base))) { - $base_key{hash_base} = $hash_base; git_print_page_nav('tree','', $hash_base); git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base); } else { + undef $hash_base; print "
\n"; print "

\n"; print "
$hash
\n"; @@ -2542,48 +2597,8 @@ sub git_tree { } $alternate ^= 1; - print "\n"; - if ($t{'type'} eq "blob") { - print "\n" . - "\n"; - } elsif ($t{'type'} eq "tree") { - print "\n" . - "\n"; - } + git_print_tree_entry(\%t, $base, $hash_base, $have_blame); + print "\n"; } print "
" . mode_str($t_mode) . "" . mode_str($t{'mode'}) . "" . - $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key), - -class => "list"}, esc_html($t_name)) . + $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'}, + file_name=>"$base$t{'name'}", %base_key), + -class => "list"}, esc_html($t{'name'})) . "" . - $cgi->a({-href => href(action=>"blob", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, + $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'}, + file_name=>"$base$t{'name'}", %base_key)}, "blob"); if ($have_blame) { print " | " . - $cgi->a({-href => href(action=>"blame", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, + $cgi->a({-href => href(action=>"blame", hash=>$t{'hash'}, + file_name=>"$base$t{'name'}", %base_key)}, "blame"); } print " | " . $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, - hash=>$t_hash, file_name=>"$base$t_name")}, + hash=>$t{'hash'}, file_name=>"$base$t{'name'}")}, "history") . " | " . $cgi->a({-href => href(action=>"blob_plain", - hash=>$t_hash, file_name=>"$base$t_name")}, + hash=>$t{'hash'}, file_name=>"$base$t{'name'}")}, "raw") . "" . - $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, - esc_html($t_name)) . + $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'}, + file_name=>"$base$t{'name'}", %base_key)}, + esc_html($t{'name'})) . "" . - $cgi->a({-href => href(action=>"tree", hash=>$t_hash, file_name=>"$base$t_name", %base_key)}, + $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'}, + file_name=>"$base$t{'name'}", %base_key)}, "tree") . " | " . - $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, file_name=>"$base$t_name")}, + $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, + file_name=>"$base$t{'name'}")}, "history") . "
" . mode_str($t->{'mode'}) . "" . + $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, + file_name=>"$basedir$t->{'name'}", %base_key), + -class => "list"}, esc_html($t->{'name'})) . + "" . + $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, + file_name=>"$basedir$t->{'name'}", %base_key)}, + "blob"); + if ($have_blame) { + print " | " . + $cgi->a({-href => href(action=>"blame", hash=>$t->{'hash'}, + file_name=>"$basedir$t->{'name'}", %base_key)}, + "blame"); + } + if (defined $hash_base) { + print " | " . + $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, + hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")}, + "history"); + } + print " | " . + $cgi->a({-href => href(action=>"blob_plain", + hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}")}, + "raw") . + "" . + $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, + file_name=>"$basedir$t->{'name'}", %base_key)}, + esc_html($t->{'name'})) . + "" . + $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, + file_name=>"$basedir$t->{'name'}", %base_key)}, + "tree"); + if (defined $hash_base) { + print " | " . + $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, + file_name=>"$basedir$t->{'name'}")}, + "history"); + } + print "" . mode_str($t{'mode'}) . "" . - $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'}, - file_name=>"$base$t{'name'}", %base_key), - -class => "list"}, esc_html($t{'name'})) . - "" . - $cgi->a({-href => href(action=>"blob", hash=>$t{'hash'}, - file_name=>"$base$t{'name'}", %base_key)}, - "blob"); - if ($have_blame) { - print " | " . - $cgi->a({-href => href(action=>"blame", hash=>$t{'hash'}, - file_name=>"$base$t{'name'}", %base_key)}, - "blame"); - } - print " | " . - $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, - hash=>$t{'hash'}, file_name=>"$base$t{'name'}")}, - "history") . - " | " . - $cgi->a({-href => href(action=>"blob_plain", - hash=>$t{'hash'}, file_name=>"$base$t{'name'}")}, - "raw") . - "" . - $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'}, - file_name=>"$base$t{'name'}", %base_key)}, - esc_html($t{'name'})) . - "" . - $cgi->a({-href => href(action=>"tree", hash=>$t{'hash'}, - file_name=>"$base$t{'name'}", %base_key)}, - "tree") . - " | " . - $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, - file_name=>"$base$t{'name'}")}, - "history") . - "
\n" . From 0edcb37d6707c8c9b566bcbb51a2d70275bd30da Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Thu, 31 Aug 2006 00:36:04 +0200 Subject: [PATCH 11/13] gitweb: Extend parse_difftree_raw_line to save commit info Extend parse_difftree_raw_line to save commit info from when git-diff-tree is given only one , for example when fed from git-rev-list using --stdin option. git-diff-tree outputs a line with the commit ID when applicable. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 7f6bdaa951..0984e85623 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1027,9 +1027,9 @@ sub parse_difftree_raw_line { } } # 'c512b523472485aef4fff9e57b229d9d243c967f' - #elsif ($line =~ m/^([0-9a-fA-F]{40})$/) { - # $res{'commit'} = $1; - #} + elsif ($line =~ m/^([0-9a-fA-F]{40})$/) { + $res{'commit'} = $1; + } return wantarray ? %res : \%res; } From 2c6d22df9f8a975c88fc9a93c4db8bb0bd116b74 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 31 Aug 2006 14:14:20 -0700 Subject: [PATCH 12/13] t5710: fix two thinkos. The intention of the test seems to be to build a long chain of clones that locally borrow objects from their parents and see the system give up dereferencing long chains. There were two problems: (1) it did not test the right repository; (2) it did not build a chain long enough to trigger the limitation. I do not think it is a good test to make sure the limitation the current implementation happens to have still exists, but that is a topic at a totally different level. At least this fixes the broken test. Signed-off-by: Junio C Hamano --- t/t5710-info-alternate.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh index 2e1b48a89b..b9f6d96363 100755 --- a/t/t5710-info-alternate.sh +++ b/t/t5710-info-alternate.sh @@ -58,6 +58,8 @@ test_expect_failure 'creating too deep nesting' \ git clone -l -s D E && git clone -l -s E F && git clone -l -s F G && +git clone -l -s G H && +cd H && test_valid_repo' cd "$base_dir" From 7cf67205ca68a157c6ffdb4e5a4ff231217c0871 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Thu, 31 Aug 2006 08:42:11 +0200 Subject: [PATCH 13/13] Trace into open fd and refactor tracing code. Now if GIT_TRACE is set to an integer value greater than 1 and lower than 10, we interpret this as an open fd value and we trace into it. Note that this behavior is not compatible with the previous one. We also trace whole messages using one write(2) call to make sure messages from processes do net get mixed up in the middle. It's now possible to run the tests like this: GIT_TRACE=9 make test 9>/var/tmp/trace.log Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- Makefile | 2 +- cache.h | 6 +++ exec_cmd.c | 18 +------ git.c | 25 ++-------- imap-send.c | 25 ---------- quote.c | 32 +++++++++++++ quote.h | 1 + t/test-lib.sh | 1 - trace.c | 125 +++++++++++++++++++++++++++++++++++++++++++++++++ write_or_die.c | 25 ++++++++++ 10 files changed, 196 insertions(+), 64 deletions(-) create mode 100644 trace.c diff --git a/Makefile b/Makefile index 05bd77f967..a639cdfcfb 100644 --- a/Makefile +++ b/Makefile @@ -249,7 +249,7 @@ LIB_OBJS = \ server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \ tag.o tree.o usage.o config.o environment.o ctype.o copy.o \ fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \ - write_or_die.o \ + write_or_die.o trace.o \ alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS) BUILTIN_OBJS = \ diff --git a/cache.h b/cache.h index 03d9dd0488..f532b46515 100644 --- a/cache.h +++ b/cache.h @@ -398,6 +398,7 @@ extern char git_commit_encoding[MAX_ENCODING_LENGTH]; extern int copy_fd(int ifd, int ofd); extern void write_or_die(int fd, const void *buf, size_t count); +extern int write_or_whine(int fd, const void *buf, size_t count, const char *msg); /* Finish off pack transfer receiving end */ extern int receive_unpack_pack(int fd[2], const char *me, int quiet, int); @@ -423,4 +424,9 @@ extern struct commit *alloc_commit_node(void); extern struct tag *alloc_tag_node(void); extern void alloc_report(void); +/* trace.c */ +extern int nfvasprintf(char **str, const char *fmt, va_list va); +extern void trace_printf(const char *format, ...); +extern void trace_argv_printf(const char **argv, int count, const char *format, ...); + #endif /* CACHE_H */ diff --git a/exec_cmd.c b/exec_cmd.c index e30936d72c..5d6a1247b4 100644 --- a/exec_cmd.c +++ b/exec_cmd.c @@ -97,26 +97,12 @@ int execv_git_cmd(const char **argv) tmp = argv[0]; argv[0] = git_command; - if (getenv("GIT_TRACE")) { - const char **p = argv; - fputs("trace: exec:", stderr); - while (*p) { - fputc(' ', stderr); - sq_quote_print(stderr, *p); - ++p; - } - putc('\n', stderr); - fflush(stderr); - } + trace_argv_printf(argv, -1, "trace: exec:"); /* execve() can only ever return if it fails */ execve(git_command, (char **)argv, environ); - if (getenv("GIT_TRACE")) { - fprintf(stderr, "trace: exec failed: %s\n", - strerror(errno)); - fflush(stderr); - } + trace_printf("trace: exec failed: %s\n", strerror(errno)); argv[0] = tmp; } diff --git a/git.c b/git.c index bd07289d71..0c8cfa8d34 100644 --- a/git.c +++ b/git.c @@ -179,17 +179,9 @@ static int handle_alias(int *argcp, const char ***argv) if (!strcmp(alias_command, new_argv[0])) die("recursive alias: %s", alias_command); - if (getenv("GIT_TRACE")) { - int i; - fprintf(stderr, "trace: alias expansion: %s =>", - alias_command); - for (i = 0; i < count; ++i) { - fputc(' ', stderr); - sq_quote_print(stderr, new_argv[i]); - } - fputc('\n', stderr); - fflush(stderr); - } + trace_argv_printf(new_argv, count, + "trace: alias expansion: %s =>", + alias_command); new_argv = xrealloc(new_argv, sizeof(char*) * (count + *argcp + 1)); @@ -292,16 +284,7 @@ static void handle_internal_command(int argc, const char **argv, char **envp) prefix = setup_git_directory(); if (p->option & USE_PAGER) setup_pager(); - if (getenv("GIT_TRACE")) { - int j; - fprintf(stderr, "trace: built-in: git"); - for (j = 0; j < argc; ++j) { - fputc(' ', stderr); - sq_quote_print(stderr, argv[j]); - } - putc('\n', stderr); - fflush(stderr); - } + trace_argv_printf(argv, argc, "trace: built-in: git"); exit(p->fn(argc, argv, prefix)); } diff --git a/imap-send.c b/imap-send.c index 65c71c602d..6a52dbdca4 100644 --- a/imap-send.c +++ b/imap-send.c @@ -110,7 +110,6 @@ static char *next_arg( char ** ); static void free_generic_messages( message_t * ); -static int nfvasprintf( char **str, const char *fmt, va_list va ); static int nfsnprintf( char *buf, int blen, const char *fmt, ... ); @@ -371,21 +370,6 @@ free_generic_messages( message_t *msgs ) } } -static int -git_vasprintf( char **strp, const char *fmt, va_list ap ) -{ - int len; - char tmp[1024]; - - if ((len = vsnprintf( tmp, sizeof(tmp), fmt, ap )) < 0 || !(*strp = xmalloc( len + 1 ))) - return -1; - if (len >= (int)sizeof(tmp)) - vsprintf( *strp, fmt, ap ); - else - memcpy( *strp, tmp, len + 1 ); - return len; -} - static int nfsnprintf( char *buf, int blen, const char *fmt, ... ) { @@ -399,15 +383,6 @@ nfsnprintf( char *buf, int blen, const char *fmt, ... ) return ret; } -static int -nfvasprintf( char **str, const char *fmt, va_list va ) -{ - int ret = git_vasprintf( str, fmt, va ); - if (ret < 0) - die( "Fatal: Out of memory\n"); - return ret; -} - static struct { unsigned char i, j, s[256]; } rs; diff --git a/quote.c b/quote.c index e220dcc280..a38786c177 100644 --- a/quote.c +++ b/quote.c @@ -74,6 +74,38 @@ char *sq_quote(const char *src) return buf; } +char *sq_quote_argv(const char** argv, int count) +{ + char *buf, *to; + int i; + size_t len = 0; + + /* Count argv if needed. */ + if (count < 0) { + for (count = 0; argv[count]; count++) + ; /* just counting */ + } + + /* Special case: no argv. */ + if (!count) + return xcalloc(1,1); + + /* Get destination buffer length. */ + for (i = 0; i < count; i++) + len += sq_quote_buf(NULL, 0, argv[i]) + 1; + + /* Alloc destination buffer. */ + to = buf = xmalloc(len + 1); + + /* Copy into destination buffer. */ + for (i = 0; i < count; ++i) { + *to++ = ' '; + to += sq_quote_buf(to, len, argv[i]); + } + + return buf; +} + char *sq_dequote(char *arg) { char *dst = arg; diff --git a/quote.h b/quote.h index fc5481e78a..a6c4611c25 100644 --- a/quote.h +++ b/quote.h @@ -31,6 +31,7 @@ extern char *sq_quote(const char *src); extern void sq_quote_print(FILE *stream, const char *src); extern size_t sq_quote_buf(char *dst, size_t n, const char *src); +extern char *sq_quote_argv(const char** argv, int count); /* This unwraps what sq_quote() produces in place, but returns * NULL if the input does not look like what sq_quote would have diff --git a/t/test-lib.sh b/t/test-lib.sh index 470a909891..b0d7990a66 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -28,7 +28,6 @@ unset GIT_DIR unset GIT_EXTERNAL_DIFF unset GIT_INDEX_FILE unset GIT_OBJECT_DIRECTORY -unset GIT_TRACE unset SHA1_FILE_DIRECTORIES unset SHA1_FILE_DIRECTORY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME diff --git a/trace.c b/trace.c new file mode 100644 index 0000000000..90847c3fd8 --- /dev/null +++ b/trace.c @@ -0,0 +1,125 @@ +/* + * GIT - The information manager from hell + * + * Copyright (C) 2000-2002 Michael R. Elkins + * Copyright (C) 2002-2004 Oswald Buddenhagen + * Copyright (C) 2004 Theodore Y. Ts'o + * Copyright (C) 2006 Mike McCormack + * Copyright (C) 2006 Christian Couder + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "cache.h" +#include "quote.h" + +/* Stolen from "imap-send.c". */ +static int git_vasprintf(char **strp, const char *fmt, va_list ap) +{ + int len; + char tmp[1024]; + + if ((len = vsnprintf(tmp, sizeof(tmp), fmt, ap)) < 0 || + !(*strp = xmalloc(len + 1))) + return -1; + if (len >= (int)sizeof(tmp)) + vsprintf(*strp, fmt, ap); + else + memcpy(*strp, tmp, len + 1); + return len; +} + +/* Stolen from "imap-send.c". */ +int nfvasprintf(char **str, const char *fmt, va_list va) +{ + int ret = git_vasprintf(str, fmt, va); + if (ret < 0) + die("Fatal: Out of memory\n"); + return ret; +} + +/* Get a trace file descriptor from GIT_TRACE env variable. */ +static int get_trace_fd() +{ + char *trace = getenv("GIT_TRACE"); + + if (!trace || !strcmp(trace, "0") || !strcasecmp(trace," false")) + return 0; + if (!strcmp(trace, "1") || !strcasecmp(trace, "true")) + return STDERR_FILENO; + if (strlen(trace) == 1 && isdigit(*trace)) + return atoi(trace); + + fprintf(stderr, "What does '%s' for GIT_TRACE means ?\n", trace); + fprintf(stderr, "Defaulting to tracing on stderr...\n"); + return STDERR_FILENO; +} + +static const char err_msg[] = "Could not trace into fd given by " + "GIT_TRACE environment variable"; + +void trace_printf(const char *format, ...) +{ + char *trace_str; + va_list rest; + int fd = get_trace_fd(); + + if (!fd) + return; + + va_start(rest, format); + nfvasprintf(&trace_str, format, rest); + va_end(rest); + + write_or_whine(fd, trace_str, strlen(trace_str), err_msg); + + free(trace_str); +} + +void trace_argv_printf(const char **argv, int count, const char *format, ...) +{ + char *argv_str, *format_str, *trace_str; + size_t argv_len, format_len, trace_len; + va_list rest; + int fd = get_trace_fd(); + + if (!fd) + return; + + /* Get the argv string. */ + argv_str = sq_quote_argv(argv, count); + argv_len = strlen(argv_str); + + /* Get the formated string. */ + va_start(rest, format); + nfvasprintf(&format_str, format, rest); + va_end(rest); + + /* Allocate buffer for trace string. */ + format_len = strlen(format_str); + trace_len = argv_len + format_len + 1; /* + 1 for \n */ + trace_str = xmalloc(trace_len + 1); + + /* Copy everything into the trace string. */ + strncpy(trace_str, format_str, format_len); + strncpy(trace_str + format_len, argv_str, argv_len); + strcpy(trace_str + trace_len - 1, "\n"); + + write_or_whine(fd, trace_str, trace_len, err_msg); + + free(argv_str); + free(format_str); + free(trace_str); +} diff --git a/write_or_die.c b/write_or_die.c index ab4cb8a69c..bfe4eeb649 100644 --- a/write_or_die.c +++ b/write_or_die.c @@ -18,3 +18,28 @@ void write_or_die(int fd, const void *buf, size_t count) p += written; } } + +int write_or_whine(int fd, const void *buf, size_t count, const char *msg) +{ + const char *p = buf; + ssize_t written; + + while (count > 0) { + written = xwrite(fd, p, count); + if (written == 0) { + fprintf(stderr, "%s: disk full?\n", msg); + return 0; + } + else if (written < 0) { + if (errno == EPIPE) + exit(0); + fprintf(stderr, "%s: write error (%s)\n", + msg, strerror(errno)); + return 0; + } + count -= written; + p += written; + } + + return 1; +}