From 9aa1757382002655cb72bad6a163ff430e08c962 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Mon, 11 Dec 2006 18:09:58 +0100 Subject: [PATCH 01/35] gitweb: Don't use Content-Encoding: header in git_snapshot Do not use Content-Encoding: HTTP header in git_snapshot, using instead type according to the snapshot type (compression type). Some of web browser take Content-Encoding: to be _transparent_ also for downloading, and store decompressed file (with incorrect compression suffix) on download. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 5ea3fda540..145d5b53b8 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3414,8 +3414,7 @@ sub git_snapshot { my $filename = basename($project) . "-$hash.tar.$suffix"; print $cgi->header( - -type => 'application/x-tar', - -content_encoding => $ctype, + -type => "application/$ctype", -content_disposition => 'inline; filename="' . "$filename" . '"', -status => '200 OK'); From e33fba4c5a33bce748d2c8a1c7a38b78a1fd2cda Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 10 Dec 2006 13:25:46 +0100 Subject: [PATCH 02/35] gitweb: Show target of symbolic link in "tree" view In "tree" view (git_print_tree_entry subroutine), for entries which are symbolic links, add " -> link_target" after file name (a la "ls -l"). Link target is _not_ hyperlinked. While at it, correct whitespaces (tabs are for aling, spaces are for indent) in modified git_print_tree_entry subroutine. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 42 ++++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 145d5b53b8..b706f7435c 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1989,12 +1989,31 @@ sub git_print_log ($;%) { } } +# return link target (what link points to) +sub git_get_link_target { + my $hash = shift; + my $link_target; + + # read link + open my $fd, "-|", git_cmd(), "cat-file", "blob", $hash + or return; + { + local $/; + $link_target = <$fd>; + } + close $fd + or return; + + return $link_target; +} + + # 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; + $base_key{'hash_base'} = $hash_base if defined $hash_base; # The format of a table row is: mode list link. Where mode is # the mode of the entry, list is the name of the entry, an href, @@ -2005,16 +2024,23 @@ sub git_print_tree_entry { print "" . $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, file_name=>"$basedir$t->{'name'}", %base_key), - -class => "list"}, esc_path($t->{'name'})) . "\n"; + -class => "list"}, esc_path($t->{'name'})); + if (S_ISLNK(oct $t->{'mode'})) { + my $link_target = git_get_link_target($t->{'hash'}); + if ($link_target) { + print " -> " . esc_path($link_target); + } + } + print "\n"; print ""; print $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'}, - file_name=>"$basedir$t->{'name'}", %base_key)}, - "blob"); + 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"); + file_name=>"$basedir$t->{'name'}", %base_key)}, + "blame"); } if (defined $hash_base) { print " | " . @@ -2036,8 +2062,8 @@ sub git_print_tree_entry { print "\n"; print ""; print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'}, - file_name=>"$basedir$t->{'name'}", %base_key)}, - "tree"); + file_name=>"$basedir$t->{'name'}", %base_key)}, + "tree"); if (defined $hash_base) { print " | " . $cgi->a({-href => href(action=>"history", hash_base=>$hash_base, From ca94601c8fcc4ddda4b48f05c748b3d52c54809c Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 10 Dec 2006 13:25:47 +0100 Subject: [PATCH 03/35] gitweb: Add generic git_object subroutine to display object of any type Add generic "object" view implemented in git_object subroutine, which is used to display object of any type; to be more exact it redirects to the view of correct type: "blob", "tree", "commit" or "tag". To identify object you have to provide either hash (identifier of an object), or (in the case of tree and blob objects) hash of commit object (hash_base) and path (file_name). Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index b706f7435c..d3816b8841 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -434,6 +434,7 @@ my %actions = ( "tags" => \&git_tags, "tree" => \&git_tree, "snapshot" => \&git_snapshot, + "object" => \&git_object, # those below don't need $project "opml" => \&git_opml, "project_list" => \&git_project_list, @@ -3619,6 +3620,53 @@ sub git_commit { git_footer_html(); } +sub git_object { + # object is defined by: + # - hash or hash_base alone + # - hash_base and file_name + my $type; + + # - hash or hash_base alone + if ($hash || ($hash_base && !defined $file_name)) { + my $object_id = $hash || $hash_base; + + my $git_command = git_cmd_str(); + open my $fd, "-|", "$git_command cat-file -t $object_id 2>/dev/null" + or die_error('404 Not Found', "Object does not exist"); + $type = <$fd>; + chomp $type; + close $fd + or die_error('404 Not Found', "Object does not exist"); + + # - hash_base and file_name + } elsif ($hash_base && defined $file_name) { + $file_name =~ s,/+$,,; + + system(git_cmd(), "cat-file", '-e', $hash_base) == 0 + or die_error('404 Not Found', "Base object does not exist"); + + # here errors should not hapen + open my $fd, "-|", git_cmd(), "ls-tree", $hash_base, "--", $file_name + or die_error(undef, "Open git-ls-tree failed"); + my $line = <$fd>; + close $fd; + + #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c' + unless ($line && $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t/) { + die_error('404 Not Found', "File or directory for given base does not exist"); + } + $type = $2; + $hash = $3; + } else { + die_error('404 Not Found', "Not enough information to find object"); + } + + print $cgi->redirect(-uri => href(action=>$type, -full=>1, + hash=>$hash, hash_base=>$hash_base, + file_name=>$file_name), + -status => '302 Found'); +} + sub git_blobdiff { my $format = shift || 'html'; From 3bf9d57051845cee996f73b5402a07cbeda84c88 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 10 Dec 2006 13:25:48 +0100 Subject: [PATCH 04/35] gitweb: Hyperlink target of symbolic link in "tree" view (if possible) Make symbolic link target in "tree" view into hyperlink to generic "object" view (as we don't know if the link target is file (blob) or directory (tree), and if it exist at all). Target of link is made into hyperlink when: * hash_base is provided (otherwise we cannot find hash of link target) * link is relative * in no place link goes out of root tree (top dir) Full path of symlink target from the root dir is provided in the title attribute of hyperlink. Currently symbolic link name uses ordinary file style (hidden hyperlink), while the hyperlink to symlink target uses default hyperlink style, so it is underlined while link target which is not made into hyperlink is not underlined. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 52 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index d3816b8841..d902913966 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -2008,6 +2008,48 @@ sub git_get_link_target { return $link_target; } +# given link target, and the directory (basedir) the link is in, +# return target of link relative to top directory (top tree); +# return undef if it is not possible (including absolute links). +sub normalize_link_target { + my ($link_target, $basedir, $hash_base) = @_; + + # we can normalize symlink target only if $hash_base is provided + return unless $hash_base; + + # absolute symlinks (beginning with '/') cannot be normalized + return if (substr($link_target, 0, 1) eq '/'); + + # normalize link target to path from top (root) tree (dir) + my $path; + if ($basedir) { + $path = $basedir . '/' . $link_target; + } else { + # we are in top (root) tree (dir) + $path = $link_target; + } + + # remove //, /./, and /../ + my @path_parts; + foreach my $part (split('/', $path)) { + # discard '.' and '' + next if (!$part || $part eq '.'); + # handle '..' + if ($part eq '..') { + if (@path_parts) { + pop @path_parts; + } else { + # link leads outside repository (outside top dir) + return; + } + } else { + push @path_parts, $part; + } + } + $path = join('/', @path_parts); + + return $path; +} # print tree entry (row of git_tree), but without encompassing element sub git_print_tree_entry { @@ -2029,7 +2071,15 @@ sub git_print_tree_entry { if (S_ISLNK(oct $t->{'mode'})) { my $link_target = git_get_link_target($t->{'hash'}); if ($link_target) { - print " -> " . esc_path($link_target); + my $norm_target = normalize_link_target($link_target, $basedir, $hash_base); + if (defined $norm_target) { + print " -> " . + $cgi->a({-href => href(action=>"object", hash_base=>$hash_base, + file_name=>$norm_target), + -title => $norm_target}, esc_path($link_target)); + } else { + print " -> " . esc_path($link_target); + } } } print "\n"; From bfe2191f79aa4e74eafc709ea41cc0999c9f5be5 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Sun, 10 Dec 2006 13:25:49 +0100 Subject: [PATCH 05/35] gitweb: SHA-1 in commit log message links to "object" view Instead of checking if explicit SHA-1 in commit log message is sha1 of commit and making link to "commit" view, make [fragment of] explicit SHA-1 in commit log message link to "object" view. While at it allow to hyperlink also shortened SHA-1, from 8 characters up to full SHA-1, instead of requiring full 40 characters of SHA-1. This makes the following changes: * SHA-1 of objects which no longer exists, for example in commit cherry-picked from no longer existing temporary branch, or revert of commit in rebased branch, are no longer marked as such by not being made into hyperlink (and not having default hyperlink view: being underlined among others). On the other hand it makes gitweb to not write error messages when object is not found to web serwer log; it also moves cost of getting type and SHA-1 validation to when link is clicked, and not only viewed. * SHA-1 of other objects: blobs, trees, tags are also hyperlinked and lead to appropriate view (although in the case of tags it is more natural to just use tag name). * You can put shortened SHA-1 of commit in the commit message, and it would be hyperlinked; it would be checked on clicking if abbrev is unique. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index d902913966..040ee719f0 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -828,14 +828,12 @@ sub format_log_line_html { my $line = shift; $line = esc_html($line, -nbsp=>1); - if ($line =~ m/([0-9a-fA-F]{40})/) { + if ($line =~ m/([0-9a-fA-F]{8,40})/) { my $hash_text = $1; - if (git_get_type($hash_text) eq "commit") { - my $link = - $cgi->a({-href => href(action=>"commit", hash=>$hash_text), - -class => "text"}, $hash_text); - $line =~ s/$hash_text/$link/; - } + my $link = + $cgi->a({-href => href(action=>"object", hash=>$hash_text), + -class => "text"}, $hash_text); + $line =~ s/$hash_text/$link/; } return $line; } From b11121d9e330c40f5d089636f176d089e5bb1885 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 1 Dec 2006 20:45:45 -0800 Subject: [PATCH 06/35] git-blame: show lines attributed to boundary commits differently. When blaming with revision ranges, often many lines are attributed to different commits at the boundary, but they are not interesting for the purpose of finding project history during that revision range. This outputs the lines blamed on boundary commits differently. When showing "human format" output, their SHA-1 are shown with '^' prefixed. In "porcelain format", the commit will be shown with an extra attribute line "boundary". Signed-off-by: Junio C Hamano --- builtin-blame.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/builtin-blame.c b/builtin-blame.c index dc3ffeaff8..a250724463 100644 --- a/builtin-blame.c +++ b/builtin-blame.c @@ -1090,6 +1090,11 @@ static void assign_blame(struct scoreboard *sb, struct rev_info *revs, int opt) if (!(commit->object.flags & UNINTERESTING) && !(revs->max_age != -1 && commit->date < revs->max_age)) pass_blame(sb, suspect, opt); + else { + commit->object.flags |= UNINTERESTING; + if (commit->object.parsed) + mark_parents_uninteresting(commit); + } /* Take responsibility for the remaining entries */ for (ent = sb->ent; ent; ent = ent->next) @@ -1273,6 +1278,8 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent) printf("committer-tz %s\n", ci.committer_tz); printf("filename %s\n", suspect->path); printf("summary %s\n", ci.summary); + if (suspect->commit->object.flags & UNINTERESTING) + printf("boundary\n"); } else if (suspect->commit->object.flags & MORE_THAN_ONE_PATH) printf("filename %s\n", suspect->path); @@ -1308,8 +1315,14 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt) cp = nth_line(sb, ent->lno); for (cnt = 0; cnt < ent->num_lines; cnt++) { char ch; + int length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : 8; - printf("%.*s", (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : 8, hex); + if (suspect->commit->object.flags & UNINTERESTING) { + length--; + putchar('^'); + } + + printf("%.*s", length, hex); if (opt & OUTPUT_ANNOTATE_COMPAT) printf("\t(%10s\t%10s\t%d)", ci.author, format_time(ci.author_time, ci.author_tz, From 549ab4a30703012ff3a12b5455d319216805a8db Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Fri, 15 Dec 2006 17:53:45 +0100 Subject: [PATCH 07/35] gitweb: Do not show difftree for merges in "commit" view Do not show difftree against first parent for merges (commits with more than one parent) in "commit" view, because it usually is misleading. git-show and git-whatchanged doesn't show diff for merges either. Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 040ee719f0..ebf35a1e2b 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3572,14 +3572,19 @@ sub git_commit { my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); my $parent = $co{'parent'}; + my $parents = $co{'parents'}; if (!defined $parent) { $parent = "--root"; } - open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id", - @diff_opts, $parent, $hash, "--" - or die_error(undef, "Open git-diff-tree failed"); - my @difftree = map { chomp; $_ } <$fd>; - close $fd or die_error(undef, "Reading git-diff-tree failed"); + my @difftree; + if (@$parents <= 1) { + # difftree output is not printed for merges + open my $fd, "-|", git_cmd(), "diff-tree", '-r', "--no-commit-id", + @diff_opts, $parent, $hash, "--" + or die_error(undef, "Open git-diff-tree failed"); + @difftree = map { chomp; $_ } <$fd>; + close $fd or die_error(undef, "Reading git-diff-tree failed"); + } # non-textual hash id's can be cached my $expires; @@ -3641,7 +3646,7 @@ sub git_commit { } print "" . "\n"; - my $parents = $co{'parents'}; + foreach my $par (@$parents) { print "" . "parent" . @@ -3663,7 +3668,10 @@ sub git_commit { git_print_log($co{'comment'}); print "\n"; - git_difftree_body(\@difftree, $hash, $parent); + if (@$parents <= 1) { + # do not output difftree/whatchanged for merges + git_difftree_body(\@difftree, $hash, $parent); + } git_footer_html(); } From 5fce278ef313d3b43a5df5bd0494ad23dc313d22 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Fri, 15 Dec 2006 23:49:12 +0100 Subject: [PATCH 08/35] gitweb: Add title attribute to ref marker with full ref name Add title attribute, which will be shown as popup on mouseover in graphical web browsers, with full name of ref, including part (type) removed from the name of ref itself. This is useful to see that this strange ref is StGIT ref, or it is remote branch, or it is lightweigh tag (with branch-like name). Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index ebf35a1e2b..79e518a912 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -855,7 +855,8 @@ sub format_ref_marker { $name = $ref; } - $markers .= " " . esc_html($name) . ""; + $markers .= " " . + esc_html($name) . ""; } } From c9d193dffbeaf0f106e712879c3ce3d2a4846157 Mon Sep 17 00:00:00 2001 From: Jakub Narebski Date: Fri, 15 Dec 2006 21:57:16 +0100 Subject: [PATCH 09/35] gitweb: Add "next" link to commit view Add a kind of "next" view in the bottom part of navigation bar for "commit" view, similar to what was added for "commitdiff" view in commit 151602df00b8e5c5b4a8193f59a94b85f9b5aebc 'gitweb: Add "next" link to commitdiff view' For "commit" view for single parent commit: (parent: _commit_) For "commit" view for merge (multi-parent) commit: (merge: _commit_ _commit_ ...) For "commit" view for root (parentless) commit (initial) where _link_ denotes hyperlink. SHA1 of commit is shortened to 7 characters on display. While at it, remove leftovers from commit cae1862a by Petr Baudis: 'gitweb: More per-view navigation bar links' namely the "blame" link if there exist $file_name and commit has a parent; it was added in git_commit probably by mistake. The rest of what mentioned commit added for git_commit was removed in commit 6e0e92fda893311ff5af91836e5007bf6bbd4a21 by Luben Tuikov: 'gitweb: Do not print "log" and "shortlog" redundantly in commit view' (which should have probably removed also this "blame" link removed now). Signed-off-by: Jakub Narebski Signed-off-by: Junio C Hamano --- gitweb/gitweb.perl | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 79e518a912..4059894e0b 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3572,8 +3572,34 @@ sub git_commit { my %ad = parse_date($co{'author_epoch'}, $co{'author_tz'}); my %cd = parse_date($co{'committer_epoch'}, $co{'committer_tz'}); - my $parent = $co{'parent'}; - my $parents = $co{'parents'}; + my $parent = $co{'parent'}; + my $parents = $co{'parents'}; # listref + + # we need to prepare $formats_nav before any parameter munging + my $formats_nav; + if (!defined $parent) { + # --root commitdiff + $formats_nav .= '(initial)'; + } elsif (@$parents == 1) { + # single parent commit + $formats_nav .= + '(parent: ' . + $cgi->a({-href => href(action=>"commit", + hash=>$parent)}, + esc_html(substr($parent, 0, 7))) . + ')'; + } else { + # merge commit + $formats_nav .= + '(merge: ' . + join(' ', map { + $cgi->a({-href => href(action=>"commitdiff", + hash=>$_)}, + esc_html(substr($_, 0, 7))); + } @$parents ) . + ')'; + } + if (!defined $parent) { $parent = "--root"; } @@ -3597,16 +3623,10 @@ sub git_commit { my $have_snapshot = gitweb_have_snapshot(); - my @views_nav = (); - if (defined $file_name && defined $co{'parent'}) { - push @views_nav, - $cgi->a({-href => href(action=>"blame", hash_parent=>$parent, file_name=>$file_name)}, - "blame"); - } git_header_html(undef, $expires); git_print_page_nav('commit', '', $hash, $co{'tree'}, $hash, - join (' | ', @views_nav)); + $formats_nav); if (defined $co{'parent'}) { git_print_header_div('commitdiff', esc_html($co{'title'}) . $ref, $hash); From 0667fcfb6271e9e1ea032a0e3a7d74c9d6a5fa8a Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 16 Dec 2006 15:14:14 +0100 Subject: [PATCH 10/35] add a function to rename sections in the config Given a config like this: # A config [very.interesting.section] not The command $ git repo-config --rename-section very.interesting.section bla.1 will lead to this config: # A config [bla "1"] not Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-repo-config.c | 14 ++++++++- cache.h | 1 + config.c | 64 ++++++++++++++++++++++++++++++++++++++++++ t/t1300-repo-config.sh | 48 +++++++++++++++++++++++++++++++ 4 files changed, 126 insertions(+), 1 deletion(-) diff --git a/builtin-repo-config.c b/builtin-repo-config.c index 64fbdb7b24..a38099a63d 100644 --- a/builtin-repo-config.c +++ b/builtin-repo-config.c @@ -3,7 +3,7 @@ #include static const char git_config_set_usage[] = -"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --list"; +"git-repo-config [ --global ] [ --bool | --int ] [--get | --get-all | --get-regexp | --replace-all | --add | --unset | --unset-all] name [value [value_regex]] | --rename-section old_name new_name | --list"; static char *key; static regex_t *key_regexp; @@ -148,6 +148,18 @@ int cmd_repo_config(int argc, const char **argv, const char *prefix) } else { die("$HOME not set"); } + } else if (!strcmp(argv[1], "--rename-section")) { + int ret; + if (argc != 4) + usage(git_config_set_usage); + ret = git_config_rename_section(argv[2], argv[3]); + if (ret < 0) + return ret; + if (ret == 0) { + fprintf(stderr, "No such section!\n"); + return 1; + } + return 0; } else break; argc--; diff --git a/cache.h b/cache.h index 2d3df98dc4..bfab4f9752 100644 --- a/cache.h +++ b/cache.h @@ -404,6 +404,7 @@ extern int git_config_int(const char *, const char *); extern int git_config_bool(const char *, const char *); extern int git_config_set(const char *, const char *); extern int git_config_set_multivar(const char *, const char *, const char *, int); +extern int git_config_rename_section(const char *, const char *); extern int check_repository_format_version(const char *var, const char *value); #define MAX_GITNAME (1000) diff --git a/config.c b/config.c index 1bdef44a3a..663993fefa 100644 --- a/config.c +++ b/config.c @@ -746,4 +746,68 @@ out_free: return ret; } +int git_config_rename_section(const char *old_name, const char *new_name) +{ + int ret = 0; + const char *config_filename; + struct lock_file *lock = xcalloc(sizeof(struct lock_file), 1); + int out_fd; + char buf[1024]; + + config_filename = getenv("GIT_CONFIG"); + if (!config_filename) { + config_filename = getenv("GIT_CONFIG_LOCAL"); + if (!config_filename) + config_filename = git_path("config"); + } + config_filename = xstrdup(config_filename); + out_fd = hold_lock_file_for_update(lock, config_filename, 0); + if (out_fd < 0) + return error("Could not lock config file!"); + + if (!(config_file = fopen(config_filename, "rb"))) + return error("Could not open config file!"); + + while (fgets(buf, sizeof(buf), config_file)) { + int i; + for (i = 0; buf[i] && isspace(buf[i]); i++) + ; /* do nothing */ + if (buf[i] == '[') { + /* it's a section */ + int j = 0, dot = 0; + for (i++; buf[i] && buf[i] != ']'; i++) { + if (!dot && isspace(buf[i])) { + dot = 1; + if (old_name[j++] != '.') + break; + for (i++; isspace(buf[i]); i++) + ; /* do nothing */ + if (buf[i] != '"') + break; + continue; + } + if (buf[i] == '\\' && dot) + i++; + else if (buf[i] == '"' && dot) { + for (i++; isspace(buf[i]); i++) + ; /* do_nothing */ + break; + } + if (buf[i] != old_name[j++]) + break; + } + if (buf[i] == ']') { + /* old_name matches */ + ret++; + store.baselen = strlen(new_name); + store_write_section(out_fd, new_name); + continue; + } + } + write(out_fd, buf, strlen(buf)); + } + if (close(out_fd) || commit_lock_file(lock) < 0) + return error("Cannot commit config file!"); + return ret; +} diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 16cd642610..e48a4ecdcf 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -343,5 +343,53 @@ EOF test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect' +cat > .git/config << EOF +# Hallo + #Bello +[branch "eins"] + x = 1 +[branch.eins] + y = 1 + [branch "1 234 blabl/a"] +weird +EOF + +test_expect_success "rename section" \ + "git-repo-config --rename-section branch.eins branch.zwei" + +cat > expect << EOF +# Hallo + #Bello +[branch "zwei"] + x = 1 +[branch "zwei"] + y = 1 + [branch "1 234 blabl/a"] +weird +EOF + +test_expect_success "rename succeeded" "diff -u expect .git/config" + +test_expect_failure "rename non-existing section" \ + 'git-repo-config --rename-section branch."world domination" branch.drei' + +test_expect_success "rename succeeded" "diff -u expect .git/config" + +test_expect_success "rename another section" \ + 'git-repo-config --rename-section branch."1 234 blabl/a" branch.drei' + +cat > expect << EOF +# Hallo + #Bello +[branch "zwei"] + x = 1 +[branch "zwei"] + y = 1 +[branch "drei"] +weird +EOF + +test_expect_success "rename succeeded" "diff -u expect .git/config" + test_done From dc81c58cd6b791a3db23f1d1acb5f7d38d1ff086 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 16 Dec 2006 15:15:02 +0100 Subject: [PATCH 11/35] git-branch: rename config vars branch..*, too When renaming a branch, the corresponding config section should be renamed, too. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- refs.c | 10 ++++++++++ t/t3200-branch.sh | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/refs.c b/refs.c index a02957c399..d911b9e860 100644 --- a/refs.c +++ b/refs.c @@ -867,6 +867,16 @@ int rename_ref(const char *oldref, const char *newref, const char *logmsg) goto rollback; } + if (!strncmp(oldref, "refs/heads/", 11) && + !strncmp(newref, "refs/heads/", 11)) { + char oldsection[1024], newsection[1024]; + + snprintf(oldsection, 1024, "branch.%s", oldref + 11); + snprintf(newsection, 1024, "branch.%s", newref + 11); + if (git_config_rename_section(oldsection, newsection) < 0) + return 1; + } + return 0; rollback: diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 5782c30b03..a6ea0f6a19 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -94,6 +94,8 @@ test_expect_failure \ git-branch r && git-branch -m q r/q' +git-repo-config branch.s/s.dummy Hello + test_expect_success \ 'git branch -m s/s s should work when s/t is deleted' \ 'git-branch -l s/s && @@ -104,6 +106,10 @@ test_expect_success \ git-branch -m s/s s && test -f .git/logs/refs/heads/s' +test_expect_success 'config information was renamed, too' \ + "test $(git-repo-config branch.s.dummy) = Hello && + ! git-repo-config branch.s/s/dummy" + test_expect_failure \ 'git-branch -m u v should fail when the reflog for u is a symlink' \ 'git-branch -l u && From 790fa0e297b41b9e8c98a77b58004c58408e5f7a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 16:23:02 -0800 Subject: [PATCH 12/35] update-index: make D/F conflict error a bit more verbose. When you remove a directory D that has a tracked file D/F out of the way to create a file D and try to "git update-index --add D", it used to say "cannot add" which was not very helpful. This issues an extra error message to explain the situation before the final "fatal" message. Since D/F conflicts are relatively rare event, extra verbosity would not make things too noisy. Signed-off-by: Junio C Hamano --- read-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/read-cache.c b/read-cache.c index eae4745d28..a602010a69 100644 --- a/read-cache.c +++ b/read-cache.c @@ -609,7 +609,7 @@ int add_cache_entry(struct cache_entry *ce, int option) if (!skip_df_check && check_file_directory_conflict(ce, pos, ok_to_replace)) { if (!ok_to_replace) - return -1; + return error("'%s' appears as both a file and as a directory", ce->name); pos = cache_name_pos(ce->name, ntohs(ce->ce_flags)); pos = -pos-1; } From c33ab0dd100d91d417b5ed3378acbf3310c07cec Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Dec 2006 01:09:41 -0800 Subject: [PATCH 13/35] git-add: remove conflicting entry when adding. When replacing an existing file A with a directory A that has a file A/B in it in the index, 'git add' did not succeed because it forgot to pass the allow-replace flag to add_cache_entry(). It might be safer to leave this as an error and require the user to explicitly remove the existing A first before adding A/B since it is an unusual case, but doing that automatically is much easier to use. Signed-off-by: Junio C Hamano --- read-cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/read-cache.c b/read-cache.c index a602010a69..983e68b892 100644 --- a/read-cache.c +++ b/read-cache.c @@ -358,7 +358,7 @@ int add_file_to_index(const char *path, int verbose) if (index_path(ce->sha1, path, &st, 1)) die("unable to index file %s", path); - if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD)) + if (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD|ADD_CACHE_OK_TO_REPLACE)) die("unable to add %s to index",path); if (verbose) printf("add '%s'\n", path); From 81a361be3b12f393d402c5da63191c11c18ea6a9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 16 Dec 2006 17:39:06 -0800 Subject: [PATCH 14/35] Fix check_file_directory_conflict(). When replacing an existing file A with a directory A that has a file A/B in it in the index, 'update-index --replace --add A/B' did not properly remove the file to make room for the new directory. There was a trivial logic error, most likely a cut & paste one, dating back to quite early days of git. Signed-off-by: Junio C Hamano --- read-cache.c | 2 +- t/t0000-basic.sh | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/read-cache.c b/read-cache.c index 983e68b892..b8d83ccd9f 100644 --- a/read-cache.c +++ b/read-cache.c @@ -517,7 +517,7 @@ static int has_dir_name(const struct cache_entry *ce, int pos, int ok_to_replace pos = cache_name_pos(name, ntohs(create_ce_flags(len, stage))); if (pos >= 0) { retval = -1; - if (ok_to_replace) + if (!ok_to_replace) break; remove_cache_entry_at(pos); continue; diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 3260d1d7a7..0cd1c41866 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -272,4 +272,13 @@ test_expect_success \ wc -l) && test $numparent = 1' +test_expect_success 'update-index D/F conflict' ' + mv path0 tmp && + mv path2 path0 && + mv tmp path2 && + git update-index --add --replace path2 path0/file2 && + numpath0=$(git ls-files path0 | wc -l) && + test $numpath0 = 1 +' + test_done From a7f196a74650e45ce240754e2caa483752651063 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 17 Dec 2006 03:15:14 -0500 Subject: [PATCH 15/35] Default GIT_COMMITTER_NAME to login name in recieve-pack. If GIT_COMMITTER_NAME is not available in receive-pack but reflogs are enabled we would normally die out with an error message asking the user to correct their environment settings. Now that reflogs are enabled by default in (what we guessed to be) non-bare Git repositories this may cause problems for some users who don't have their full name in the gecos field and who don't have access to the remote system to correct the problem. So rather than die()'ing out in receive-pack when we try to log a ref change and have no committer name we default to the username, as obtained from the host's password database. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- cache.h | 1 + ident.c | 15 +++++++++++++++ receive-pack.c | 2 ++ 3 files changed, 18 insertions(+) diff --git a/cache.h b/cache.h index 2d3df98dc4..b540292d66 100644 --- a/cache.h +++ b/cache.h @@ -309,6 +309,7 @@ void datestamp(char *buf, int bufsize); unsigned long approxidate(const char *); extern int setup_ident(void); +extern void ignore_missing_committer_name(); extern const char *git_author_info(int); extern const char *git_committer_info(int); diff --git a/ident.c b/ident.c index e415fd3588..d7faba6a70 100644 --- a/ident.c +++ b/ident.c @@ -221,3 +221,18 @@ const char *git_committer_info(int error_on_no_name) getenv("GIT_COMMITTER_DATE"), error_on_no_name); } + +void ignore_missing_committer_name() +{ + /* If we did not get a name from the user's gecos entry then + * git_default_name is empty; so instead load the username + * into it as a 'good enough for now' approximation of who + * this user is. + */ + if (!*git_default_name) { + struct passwd *pw = getpwuid(getuid()); + if (!pw) + die("You don't exist. Go away!"); + strlcpy(git_default_name, pw->pw_name, sizeof(git_default_name)); + } +} diff --git a/receive-pack.c b/receive-pack.c index e76d9aea31..5e5510bc3d 100644 --- a/receive-pack.c +++ b/receive-pack.c @@ -420,6 +420,8 @@ int main(int argc, char **argv) die("'%s': unable to chdir or not a git archive", dir); setup_ident(); + /* don't die if gecos is empty */ + ignore_missing_committer_name(); git_config(receive_pack_config); write_head_info(); From 38477d9e6055e3572b465ec3f8e716164111683d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Dec 2006 00:46:35 -0800 Subject: [PATCH 16/35] Fix mis-mark-up in git-merge-file.txt documentation Signed-off-by: Junio C Hamano --- Documentation/git-merge-file.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/git-merge-file.txt b/Documentation/git-merge-file.txt index 0b41d66a70..29d3faa556 100644 --- a/Documentation/git-merge-file.txt +++ b/Documentation/git-merge-file.txt @@ -1,9 +1,9 @@ git-merge-file(1) -============ +================= NAME ---- -git-merge-file - threeway file merge +git-merge-file - three-way file merge SYNOPSIS From c0e9232e43446d3bfa7844d36e64e087b8709090 Mon Sep 17 00:00:00 2001 From: Quy Tonthat Date: Mon, 18 Dec 2006 01:50:12 +1100 Subject: [PATCH 17/35] Documentation: new option -P for git-svnimport Documentation: new option -P for git-svnimport. Signed-off-by: Quy Tonthat Signed-off-by: Junio C Hamano --- Documentation/git-svnimport.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/git-svnimport.txt b/Documentation/git-svnimport.txt index b1b87c2fcd..df604e15ec 100644 --- a/Documentation/git-svnimport.txt +++ b/Documentation/git-svnimport.txt @@ -15,6 +15,7 @@ SYNOPSIS [ -b branch_subdir ] [ -T trunk_subdir ] [ -t tag_subdir ] [ -s start_chg ] [ -m ] [ -r ] [ -M regex ] [ -I ] [ -A ] + [ -P ] [ ] @@ -107,6 +108,14 @@ repository without -A. Formerly, this option controlled how many revisions to pull, due to SVN memory leaks. (These have been worked around.) +-P :: + Partial import of the SVN tree. + + By default, the whole tree on the SVN trunk (/trunk) is imported. + '-P my/proj' will import starting only from '/trunk/my/proj'. + This option is useful when you want to import one project from a + svn repo which hosts multiple projects under the same trunk. + -v:: Verbosity: let 'svnimport' report what it is doing. From ee6002aa429272871733b8fbc99a9e6df3e150f5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Dec 2006 10:33:24 -0800 Subject: [PATCH 18/35] markup fix in svnimport documentation. Signed-off-by: Junio C Hamano --- Documentation/git-svnimport.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Documentation/git-svnimport.txt b/Documentation/git-svnimport.txt index df604e15ec..2c7c7dad54 100644 --- a/Documentation/git-svnimport.txt +++ b/Documentation/git-svnimport.txt @@ -104,17 +104,17 @@ repository without -A. -l :: Specify a maximum revision number to pull. - - Formerly, this option controlled how many revisions to pull, - due to SVN memory leaks. (These have been worked around.) ++ +Formerly, this option controlled how many revisions to pull, +due to SVN memory leaks. (These have been worked around.) -P :: Partial import of the SVN tree. - - By default, the whole tree on the SVN trunk (/trunk) is imported. - '-P my/proj' will import starting only from '/trunk/my/proj'. - This option is useful when you want to import one project from a - svn repo which hosts multiple projects under the same trunk. ++ +By default, the whole tree on the SVN trunk (/trunk) is imported. +'-P my/proj' will import starting only from '/trunk/my/proj'. +This option is useful when you want to import one project from a +svn repo which hosts multiple projects under the same trunk. -v:: Verbosity: let 'svnimport' report what it is doing. From 7e3fe904ef9b1ce9cb9a3ddc03d85508bcc48df2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 14 Dec 2006 15:58:56 -0800 Subject: [PATCH 19/35] Teach show-branch how to show ref-log data. Signed-off-by: Junio C Hamano --- builtin-show-branch.c | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/builtin-show-branch.c b/builtin-show-branch.c index fb1a4000d9..a38ac34efb 100644 --- a/builtin-show-branch.c +++ b/builtin-show-branch.c @@ -6,7 +6,7 @@ #include "builtin.h" static const char show_branch_usage[] = -"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [...]"; +"git-show-branch [--sparse] [--current] [--all] [--heads] [--tags] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [...] | --reflog[=n] "; static int default_num; static int default_alloc; @@ -17,6 +17,8 @@ static const char **default_arg; #define REV_SHIFT 2 #define MAX_REVS (FLAG_BITS - REV_SHIFT) /* should not exceed bits_per_int - REV_SHIFT */ +#define DEFAULT_REFLOG 4 + static struct commit *interesting(struct commit_list *list) { while (list) { @@ -570,6 +572,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) int head_at = -1; int topics = 0; int dense = 1; + int reflog = 0; git_config(git_show_branch_config); @@ -615,6 +618,15 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) dense = 0; else if (!strcmp(arg, "--date-order")) lifo = 0; + else if (!strcmp(arg, "--reflog")) { + reflog = DEFAULT_REFLOG; + } + else if (!strncmp(arg, "--reflog=", 9)) { + char *end; + reflog = strtoul(arg + 9, &end, 10); + if (*end != '\0') + die("unrecognized reflog count '%s'", arg + 9); + } else usage(show_branch_usage); ac--; av++; @@ -622,7 +634,7 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) ac--; av++; /* Only one of these is allowed */ - if (1 < independent + merge_base + (extra != 0)) + if (1 < independent + merge_base + (extra != 0) + (!!reflog)) usage(show_branch_usage); /* If nothing is specified, show all branches by default */ @@ -631,9 +643,22 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) if (all_heads + all_tags) snarf_refs(all_heads, all_tags); - while (0 < ac) { - append_one_rev(*av); - ac--; av++; + if (reflog) { + int reflen; + if (!ac) + die("--reflog option needs one branch name"); + reflen = strlen(*av); + for (i = 0; i < reflog; i++) { + char *name = xmalloc(reflen + 20); + sprintf(name, "%s@{%d}", *av, i); + append_one_rev(name); + } + } + else { + while (0 < ac) { + append_one_rev(*av); + ac--; av++; + } } head_p = resolve_ref("HEAD", head_sha1, 1, NULL); From ed9f7c954c26ec6d517bdca3d8e4b895278d1b2b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Dec 2006 17:57:19 -0800 Subject: [PATCH 20/35] git-fetch: Avoid reading packed refs over and over again When checking which tags to fetch, the old code used to call git-show-ref --verify for each remote tag. Since reading even packed refs is not a cheap operation when there are a lot of local refs, the code became quite slow. This fixes it by teaching git-show-ref to filter out existing refs using a new mode of operation of git-show-ref. Signed-off-by: Junio C Hamano --- builtin-show-ref.c | 60 +++++++++++++++++++++++++++++++++++++++++++++- git-fetch.sh | 12 +++------- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/builtin-show-ref.c b/builtin-show-ref.c index 073979855b..b36f15eeaa 100644 --- a/builtin-show-ref.c +++ b/builtin-show-ref.c @@ -2,8 +2,9 @@ #include "refs.h" #include "object.h" #include "tag.h" +#include "path-list.h" -static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=]] [--abbrev[=]] [--tags] [--heads] [--] [pattern*]"; +static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=]] [--abbrev[=]] [--tags] [--heads] [--] [pattern*] | --filter-invalid < ref-list"; static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0, found_match = 0, verify = 0, quiet = 0, hash_only = 0, abbrev = 0; @@ -86,6 +87,59 @@ match: return 0; } +static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata) +{ + struct path_list *list = (struct path_list *)cbdata; + path_list_insert(refname, list); + return 0; +} + +/* + * read "^(?:\s)?(?:\^\{\})?$" from the standard input, + * and + * (1) strip "^{}" at the end of line if any; + * (2) ignore if match is provided and does not head-match refname; + * (3) warn if refname is not a well-formed refname and skip; + * (4) ignore if refname is a ref that exists in the local repository; + * (5) otherwise output the line. + */ +static int exclude_existing(const char *match) +{ + static struct path_list existing_refs = { NULL, 0, 0, 0 }; + char buf[1024]; + int matchlen = match ? strlen(match) : 0; + + for_each_ref(add_existing, &existing_refs); + while (fgets(buf, sizeof(buf), stdin)) { + int len = strlen(buf); + char *ref; + if (len > 0 && buf[len - 1] == '\n') + buf[--len] = '\0'; + if (!strcmp(buf + len - 3, "^{}")) { + len -= 3; + buf[len] = '\0'; + } + for (ref = buf + len; buf < ref; ref--) + if (isspace(ref[-1])) + break; + if (match) { + int reflen = buf + len - ref; + if (reflen < matchlen) + continue; + if (strncmp(ref, match, matchlen)) + continue; + } + if (check_ref_format(ref)) { + fprintf(stderr, "warning: ref '%s' ignored\n", ref); + continue; + } + if (!path_list_has_path(&existing_refs, ref)) { + printf("%s\n", buf); + } + } + return 0; +} + int cmd_show_ref(int argc, const char **argv, const char *prefix) { int i; @@ -153,6 +207,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) heads_only = 1; continue; } + if (!strcmp(arg, "--exclude-existing")) + return exclude_existing(NULL); + if (!strncmp(arg, "--exclude-existing=", 19)) + return exclude_existing(arg + 19); usage(show_ref_usage); } if (show_head) diff --git a/git-fetch.sh b/git-fetch.sh index fb35815a5f..38101a6ace 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -242,7 +242,7 @@ esac reflist=$(get_remote_refs_for_fetch "$@") if test "$tags" then - taglist=`IFS=" " && + taglist=`IFS=' ' && echo "$ls_remote_result" | while read sha1 name do @@ -438,17 +438,11 @@ case "$no_tags$tags" in *:refs/*) # effective only when we are following remote branch # using local tracking branch. - taglist=$(IFS=" " && + taglist=$(IFS=' ' && echo "$ls_remote_result" | - sed -n -e 's|^\('"$_x40"'\) \(refs/tags/.*\)^{}$|\1 \2|p' \ - -e 's|^\('"$_x40"'\) \(refs/tags/.*\)$|\1 \2|p' | + git-show-ref --exclude-existing=refs/tags/ | while read sha1 name do - git-show-ref --verify --quiet -- "$name" && continue - git-check-ref-format "$name" || { - echo >&2 "warning: tag ${name} ignored" - continue - } git-cat-file -t "$sha1" >/dev/null 2>&1 || continue echo >&2 "Auto-following $name" echo ".${name}:${name}" From 26cdd1e7c7a21b6d71ebc201fc2472a6a68f5ce4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Dec 2006 18:08:52 -0800 Subject: [PATCH 21/35] avoid accessing _all_ loose refs in git-show-ref --verify If you want to verify a ref, it is overkill to first read all loose refs into a linked list, and then check if the desired ref is there. Signed-off-by: Junio C Hamano Acked-by: Johannes Schindelin --- builtin-show-ref.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/builtin-show-ref.c b/builtin-show-ref.c index b36f15eeaa..23e0ff8fbf 100644 --- a/builtin-show-ref.c +++ b/builtin-show-ref.c @@ -213,6 +213,23 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) return exclude_existing(arg + 19); usage(show_ref_usage); } + + if (verify) { + unsigned char sha1[20]; + + while (*pattern) { + if (resolve_ref(*pattern, sha1, 1, NULL)) + printf("%s %s\n", sha1_to_hex(sha1), + *pattern); + else if (!quiet) + die("'%s' - not a valid ref", *pattern); + else + return 1; + pattern++; + } + return 0; + } + if (show_head) head_ref(show_ref, NULL); for_each_ref(show_ref, NULL); From dd9142993c0954e2fd325431235bc7556189a01c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Dec 2006 18:53:24 -0800 Subject: [PATCH 22/35] show-ref: fix --quiet --verify Signed-off-by: Junio C Hamano --- builtin-show-ref.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/builtin-show-ref.c b/builtin-show-ref.c index 23e0ff8fbf..0fd606f392 100644 --- a/builtin-show-ref.c +++ b/builtin-show-ref.c @@ -218,9 +218,11 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) unsigned char sha1[20]; while (*pattern) { - if (resolve_ref(*pattern, sha1, 1, NULL)) - printf("%s %s\n", sha1_to_hex(sha1), - *pattern); + if (resolve_ref(*pattern, sha1, 1, NULL)) { + if (!quiet) + printf("%s %s\n", + sha1_to_hex(sha1), *pattern); + } else if (!quiet) die("'%s' - not a valid ref", *pattern); else From 64fe031a7a78894955af217335b46059a36a582d Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 17 Dec 2006 19:27:49 -0800 Subject: [PATCH 23/35] show-ref: fix --verify --hash=length An earlier optimization for --verify broke a lot of stuff because it did not take interaction with other flags into account. This also fixes an unrelated argument parsing error; --hash=8 should mean the same as "--hash --abbrev=8". Signed-off-by: Junio C Hamano --- builtin-show-ref.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/builtin-show-ref.c b/builtin-show-ref.c index 0fd606f392..296070628c 100644 --- a/builtin-show-ref.c +++ b/builtin-show-ref.c @@ -10,6 +10,15 @@ static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0, found_match = 0, verify = 0, quiet = 0, hash_only = 0, abbrev = 0; static const char **pattern; +static void show_one(const char *refname, const unsigned char *sha1) +{ + const char *hex = find_unique_abbrev(sha1, abbrev); + if (hash_only) + printf("%s\n", hex); + else + printf("%s %s\n", hex, refname); +} + static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata) { struct object *obj; @@ -58,11 +67,7 @@ match: if (quiet) return 0; - hex = find_unique_abbrev(sha1, abbrev); - if (hash_only) - printf("%s\n", hex); - else - printf("%s %s\n", hex, refname); + show_one(refname, sha1); if (!deref_tags) return 0; @@ -175,13 +180,13 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) if (!strncmp(arg, "--hash=", 7) || (!strncmp(arg, "--abbrev", 8) && (arg[8] == '=' || arg[8] == '\0'))) { - if (arg[3] != 'h' && !arg[8]) + if (arg[2] != 'h' && !arg[8]) /* --abbrev only */ abbrev = DEFAULT_ABBREV; else { /* --hash= or --abbrev= */ char *end; - if (arg[3] == 'h') { + if (arg[2] == 'h') { hash_only = 1; arg += 7; } @@ -218,10 +223,10 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix) unsigned char sha1[20]; while (*pattern) { - if (resolve_ref(*pattern, sha1, 1, NULL)) { + if (!strncmp(*pattern, "refs/", 5) && + resolve_ref(*pattern, sha1, 1, NULL)) { if (!quiet) - printf("%s %s\n", - sha1_to_hex(sha1), *pattern); + show_one(*pattern, sha1); } else if (!quiet) die("'%s' - not a valid ref", *pattern); From ff7f22f36e2931db7683121f20ee2e03bd426096 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Mon, 18 Dec 2006 02:26:42 -0500 Subject: [PATCH 24/35] vim syntax: follow recent changes to commit template This patch changes the syntax highlighting to correctly match the new text of the commit message introduced by 82dca84871637ac9812c0dec27f56d07cfba524c Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/vim/syntax/gitcommit.vim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/vim/syntax/gitcommit.vim b/contrib/vim/syntax/gitcommit.vim index a9de09fa2f..d911efbb4b 100644 --- a/contrib/vim/syntax/gitcommit.vim +++ b/contrib/vim/syntax/gitcommit.vim @@ -1,7 +1,7 @@ syn region gitLine start=/^#/ end=/$/ -syn region gitCommit start=/^# Updated but not checked in:$/ end=/^#$/ contains=gitHead,gitCommitFile +syn region gitCommit start=/^# Added but not yet committed:$/ end=/^#$/ contains=gitHead,gitCommitFile syn region gitHead contained start=/^# (.*)/ end=/^#$/ -syn region gitChanged start=/^# Changed but not updated:/ end=/^#$/ contains=gitHead,gitChangedFile +syn region gitChanged start=/^# Changed but not added:/ end=/^#$/ contains=gitHead,gitChangedFile syn region gitUntracked start=/^# Untracked files:/ end=/^#$/ contains=gitHead,gitUntrackedFile syn match gitCommitFile contained /^#\t.*/hs=s+2 From 0c7a97fafdaf7911183807019dbbb4d8c5079c4e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Dec 2006 12:13:46 -0800 Subject: [PATCH 25/35] parse-remote::expand_refs_wildcard() Work around dash incompatibility by not using "${name%'^{}'}". Noticed by Jeff King; dash seems to mistake the closing brace inside the single quote as the terminating brace for parameter expansion. Signed-off-by: Junio C Hamano --- git-parse-remote.sh | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/git-parse-remote.sh b/git-parse-remote.sh index 6ae534bf89..bc881cc5f9 100755 --- a/git-parse-remote.sh +++ b/git-parse-remote.sh @@ -111,16 +111,14 @@ expand_refs_wildcard () { local_force= test "z$lref" = "z$ref" || local_force='+' echo "$ls_remote_result" | + sed -e '/\^{}$/d' | ( IFS=' ' while read sha1 name do + # ignore the ones that do not start with $from mapped=${name#"$from"} - if test "z$name" != "z${name%'^{}'}" || - test "z$name" = "z$mapped" - then - continue - fi + test "z$name" = "z$mapped" && continue echo "${local_force}${name}:${to}${mapped}" done ) From d8285af4810f655e28a0ae0e71a28a920bb6871f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Dec 2006 13:33:47 -0800 Subject: [PATCH 26/35] show-ref: fix --exclude-existing Do not falsely document --filter-invalid which does not even exist. Also make sure the line is long enough to have ^{} suffix before checking for it. Pointed out by Dscho. Signed-off-by: Junio C Hamano --- builtin-show-ref.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/builtin-show-ref.c b/builtin-show-ref.c index 296070628c..853f13f6ae 100644 --- a/builtin-show-ref.c +++ b/builtin-show-ref.c @@ -4,7 +4,7 @@ #include "tag.h" #include "path-list.h" -static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=]] [--abbrev[=]] [--tags] [--heads] [--] [pattern*] | --filter-invalid < ref-list"; +static const char show_ref_usage[] = "git show-ref [-q|--quiet] [--verify] [-h|--head] [-d|--dereference] [-s|--hash[=]] [--abbrev[=]] [--tags] [--heads] [--] [pattern*] < ref-list"; static int deref_tags = 0, show_head = 0, tags_only = 0, heads_only = 0, found_match = 0, verify = 0, quiet = 0, hash_only = 0, abbrev = 0; @@ -116,11 +116,12 @@ static int exclude_existing(const char *match) for_each_ref(add_existing, &existing_refs); while (fgets(buf, sizeof(buf), stdin)) { - int len = strlen(buf); char *ref; + int len = strlen(buf); + if (len > 0 && buf[len - 1] == '\n') buf[--len] = '\0'; - if (!strcmp(buf + len - 3, "^{}")) { + if (3 <= len && !strcmp(buf + len - 3, "^{}")) { len -= 3; buf[len] = '\0'; } From e1bb1d31ea7b5a2a3f20508e5643e8fc9ee5f0fd Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Dec 2006 14:18:54 -0800 Subject: [PATCH 27/35] racy-git: documentation updates. We've removed the workaround for runtime penalty that did not exist in practice some time ago, but the technical paper that proposed that change still said "we probably should do so". Signed-off-by: Junio C Hamano --- Documentation/technical/racy-git.txt | 38 +++++++++++++++------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/Documentation/technical/racy-git.txt b/Documentation/technical/racy-git.txt index 7597d04142..5030d9f2f8 100644 --- a/Documentation/technical/racy-git.txt +++ b/Documentation/technical/racy-git.txt @@ -4,7 +4,7 @@ Use of index and Racy git problem Background ---------- -The index is one of the most important data structure in git. +The index is one of the most important data structures in git. It represents a virtual working tree state by recording list of paths and their object names and serves as a staging area to write out the next tree object to be committed. The state is @@ -16,7 +16,7 @@ virtual working tree state in the index and the files in the working tree. The most obvious case is when the user asks `git diff` (or its low level implementation, `git diff-files`) or `git-ls-files --modified`. In addition, git internally checks -if the files in the working tree is different from what are +if the files in the working tree are different from what are recorded in the index to avoid stomping on local changes in them during patch application, switching branches, and merging. @@ -24,9 +24,9 @@ In order to speed up this comparison between the files in the working tree and the index entries, the index entries record the information obtained from the filesystem via `lstat(2)` system call when they were last updated. When checking if they differ, -git first runs `lstat(2)` on the files and compare the result +git first runs `lstat(2)` on the files and compares the result with this information (this is what was originally done by the -`ce_match_stat()` function, which the current code does in +`ce_match_stat()` function, but the current code does it in `ce_match_stat_basic()` function). If some of these "cached stat information" fields do not match, git can tell that the files are modified without even looking at their contents. @@ -53,8 +53,9 @@ Racy git There is one slight problem with the optimization based on the cached stat information. Consider this sequence: + : modify 'foo' $ git update-index 'foo' - : modify 'foo' in-place without changing its size + : modify 'foo' again, in-place, without changing its size The first `update-index` computes the object name of the contents of file `foo` and updates the index entry for `foo` @@ -62,7 +63,8 @@ along with the `struct stat` information. If the modification that follows it happens very fast so that the file's `st_mtime` timestamp does not change, after this sequence, the cached stat information the index entry records still exactly match what you -can obtain from the filesystem, but the file `foo` is modified. +would see in the filesystem, even though the file `foo` is now +different. This way, git can incorrectly think files in the working tree are unmodified even though they actually are. This is called the "racy git" problem (discovered by Pasky), and the entries @@ -87,7 +89,7 @@ the stat information from updated paths, `st_mtime` timestamp of it is usually the same as or newer than any of the paths the index contains. And no matter how quick the modification that follows `git update-index foo` finishes, the resulting -`st_mtime` timestamp on `foo` cannot get the timestamp earlier +`st_mtime` timestamp on `foo` cannot get a value earlier than the index file. Therefore, index entries that can be racily clean are limited to the ones that have the same timestamp as the index file itself. @@ -111,7 +113,7 @@ value, and falsely clean entry `foo` would not be caught by the timestamp comparison check done with the former logic anymore. The latter makes sure that the cached stat information for `foo` would never match with the file in the working tree, so later -checks by `ce_match_stat_basic()` would report the index entry +checks by `ce_match_stat_basic()` would report that the index entry does not match the file and git does not have to fall back on more expensive `ce_modified_check_fs()`. @@ -155,17 +157,16 @@ of the cached stat information. Avoiding runtime penalty ------------------------ -In order to avoid the above runtime penalty, the recent "master" -branch (post 1.4.2) has a code that makes sure the index file -gets timestamp newer than the youngest files in the index when +In order to avoid the above runtime penalty, post 1.4.2 git used +to have a code that made sure the index file +got timestamp newer than the youngest files in the index when there are many young files with the same timestamp as the resulting index file would otherwise would have by waiting before finishing writing the index file out. -I suspect that in practice the situation where many paths in the -index are all racily clean is quite rare. The only code paths -that can record recent timestamp for large number of paths I -know of are: +I suspected that in practice the situation where many paths in the +index are all racily clean was quite rare. The only code paths +that can record recent timestamp for large number of paths are: . Initial `git add .` of a large project. @@ -188,6 +189,7 @@ youngest file in the working tree. This means that in these cases there actually will not be any racily clean entry in the resulting index. -So in summary I think we should not worry about avoiding the -runtime penalty and get rid of the "wait before finishing -writing" code out. +Based on this discussion, the current code does not use the +"workaround" to avoid the runtime penalty that does not exist in +practice anymore. This was done with commit 0fc82cff on Aug 15, +2006. From 57b73150c4f1dbc26474a0031f433fb34db1c13f Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 18 Dec 2006 16:06:50 -0500 Subject: [PATCH 28/35] make patch_delta() error cases a bit more verbose It is especially important to distinguish between a malloc() failure from all the other cases. An out of memory condition is much less worrisome than a compatibility/corruption problem. Also make test-delta compilable again. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- Makefile | 4 ++-- patch-delta.c | 13 ++++++------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 05cfe45b10..8919dabc78 100644 --- a/Makefile +++ b/Makefile @@ -796,8 +796,8 @@ test: all test-date$X: test-date.c date.o ctype.o $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) test-date.c date.o ctype.o -test-delta$X: test-delta.c diff-delta.o patch-delta.o - $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^ +test-delta$X: test-delta.o diff-delta.o patch-delta.o $(GITLIBS) + $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS) $(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS) diff --git a/patch-delta.c b/patch-delta.c index e3a1d425ee..ed9db81fa8 100644 --- a/patch-delta.c +++ b/patch-delta.c @@ -9,8 +9,7 @@ * published by the Free Software Foundation. */ -#include -#include +#include "git-compat-util.h" #include "delta.h" void *patch_delta(const void *src_buf, unsigned long src_size, @@ -34,9 +33,7 @@ void *patch_delta(const void *src_buf, unsigned long src_size, /* now the result size */ size = get_delta_hdr_size(&data, top); - dst_buf = malloc(size + 1); - if (!dst_buf) - return NULL; + dst_buf = xmalloc(size + 1); dst_buf[size] = 0; out = dst_buf; @@ -55,13 +52,13 @@ void *patch_delta(const void *src_buf, unsigned long src_size, if (cp_off + cp_size < cp_size || cp_off + cp_size > src_size || cp_size > size) - goto bad; + break; memcpy(out, (char *) src_buf + cp_off, cp_size); out += cp_size; size -= cp_size; } else if (cmd) { if (cmd > size) - goto bad; + break; memcpy(out, data, cmd); out += cmd; data += cmd; @@ -72,12 +69,14 @@ void *patch_delta(const void *src_buf, unsigned long src_size, * extensions. In the mean time we must fail when * encountering them (might be data corruption). */ + error("unexpected delta opcode 0"); goto bad; } } /* sanity check */ if (data != top || size != 0) { + error("delta replay has gone wild"); bad: free(dst_buf); return NULL; From b3d9899324af174ff123498b5c7ded3749aac2bc Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 18 Dec 2006 15:16:58 -0500 Subject: [PATCH 29/35] make git a bit less cryptic on fetch errors The remote server might not want to tell why it doesn't like us for security reasons, but let's make the client report such error in a bit less confusing way. The remote failure remains a mystery, but the local message might be a bit less so. [jc: with a gentle wording updates from Andy Parkins] Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- git-fetch.sh | 2 +- git-ls-remote.sh | 2 +- pkt-line.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/git-fetch.sh b/git-fetch.sh index 38101a6ace..ffbd44f0e1 100755 --- a/git-fetch.sh +++ b/git-fetch.sh @@ -96,7 +96,7 @@ fi # Global that is reused later ls_remote_result=$(git ls-remote $upload_pack "$remote") || - die "Cannot find the reflist at $remote" + die "Cannot get the repository state from $remote" append_fetch_head () { head_="$1" diff --git a/git-ls-remote.sh b/git-ls-remote.sh index 0f88953f29..03b624ef33 100755 --- a/git-ls-remote.sh +++ b/git-ls-remote.sh @@ -94,7 +94,7 @@ while read sha1 path do case "$sha1" in failed) - die "Failed to find remote refs" + exit 1 ;; esac case "$path" in refs/heads/*) diff --git a/pkt-line.c b/pkt-line.c index c1e81f976f..b4cb7e2756 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -72,7 +72,7 @@ static void safe_read(int fd, void *buffer, unsigned size) if (ret < 0) die("read error (%s)", strerror(errno)); if (!ret) - die("unexpected EOF"); + die("The remote end hung up unexpectedly"); n += ret; } } From 38c594d3300b7640532a3716adf5a0778021542c Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Mon, 18 Dec 2006 10:48:33 -0500 Subject: [PATCH 30/35] Add documentation for show-branch --topics Add a quick paragraph explaining the --topics option for show-branch. The explanation is an abbreviated version of the commit message from d320a5437f8304cf9ea3ee1898e49d643e005738. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- Documentation/git-show-branch.txt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt index a2445a48fc..948ff10e6c 100644 --- a/Documentation/git-show-branch.txt +++ b/Documentation/git-show-branch.txt @@ -10,7 +10,7 @@ SYNOPSIS [verse] 'git-show-branch' [--all] [--heads] [--tags] [--topo-order] [--current] [--more= | --list | --independent | --merge-base] - [--no-name | --sha1-name] [ | ]... + [--no-name | --sha1-name] [--topics] [ | ]... DESCRIPTION ----------- @@ -86,6 +86,14 @@ OPTIONS of "master"), name them with the unique prefix of their object names. +--topics:: + Shows only commits that are NOT on the first branch given. + This helps track topic branches by hiding any commit that + is already in the main line of development. When given + "git show-branch --topics master topic1 topic2", this + will show the revisions given by "git rev-list {caret}master + topic1 topic2" + Note that --more, --list, --independent and --merge-base options are mutually exclusive. From 910c00c8ca4d998edb318cc232c03ec855cfa161 Mon Sep 17 00:00:00 2001 From: "Aneesh Kumar K.V" Date: Thu, 7 Dec 2006 12:06:55 +0530 Subject: [PATCH 31/35] Add config example with respect to branch Update config.txt with example with respect to branch config variable. This give a better idea regarding how branch names are expected. Signed-off-by: Aneesh Kumar K.V Signed-off-by: Junio C Hamano --- Documentation/config.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index ceac54b024..22482d6a94 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -31,6 +31,11 @@ Example external = "/usr/local/bin/gnu-diff -u" renames = true + [branch "devel"] + remote = origin + merge = refs/heads/devel + + Variables ~~~~~~~~~ From 8336afa563fbeff35e531396273065161181f04c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Dec 2006 16:20:53 -0800 Subject: [PATCH 32/35] rerere: fix breakage of resolving. commit e2b70087 botched the RCS merge to git-merge-file conversion. There is no command called "git merge-file" (yes, we are using safer variant of Perl's system(3)). Signed-off-by: Junio C Hamano --- git-rerere.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-rerere.perl b/git-rerere.perl index fdd6854896..4f692091e7 100755 --- a/git-rerere.perl +++ b/git-rerere.perl @@ -154,7 +154,7 @@ sub find_conflict { sub merge { my ($name, $path) = @_; record_preimage($path, "$rr_dir/$name/thisimage"); - unless (system('git merge-file', map { "$rr_dir/$name/${_}image" } + unless (system('git', 'merge-file', map { "$rr_dir/$name/${_}image" } qw(this pre post))) { my $in; open $in, "<$rr_dir/$name/thisimage" or From 74d20040cafdced657efbf49795183d209a3a07b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 18 Dec 2006 15:27:43 -0800 Subject: [PATCH 33/35] fix testsuite: make sure they use templates freshly built from the source The initial t/trash repository for testing was created properly but over time we gained many tests that create secondary test repositories with init-db or clone and they were not careful enough. This fixes it. Signed-off-by: Junio C Hamano --- t/t4116-apply-reverse.sh | 4 ++-- t/t5300-pack-object.sh | 6 +++--- t/t5400-send-pack.sh | 2 +- t/t5500-fetch-pack.sh | 2 +- t/t5510-fetch.sh | 8 ++++---- t/t5520-pull.sh | 2 +- t/t5600-clone-fail-cleanup.sh | 6 +++--- t/t5700-clone-reference.sh | 4 ++-- t/t5710-info-alternate.sh | 14 +++++++------- t/t7001-mv.sh | 4 ++-- t/test-lib.sh | 10 ++++++++++ 11 files changed, 36 insertions(+), 26 deletions(-) diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index 74f5c2a575..a79c77af39 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -50,12 +50,12 @@ test_expect_success 'setup separate repository lacking postimage' ' git tar-tree initial initial | tar xf - && ( - cd initial && git init-db && git add . + cd initial && git_init_db && git add . ) && git tar-tree second second | tar xf - && ( - cd second && git init-db && git add . + cd second && git_init_db && git add . ) ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index de45ac4e0f..8a8152b257 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -44,7 +44,7 @@ test_expect_success \ 'unpack without delta' \ "GIT_OBJECT_DIRECTORY=.git2/objects && export GIT_OBJECT_DIRECTORY && - git-init-db && + git_init_db && git-unpack-objects -n > log2.txt + git_init_db 2>> log2.txt ) add A1 diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index a11ab0ad41..e2e8c894f9 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -15,12 +15,12 @@ test_expect_success setup ' git commit -a -m original' test_expect_success "clone and setup child repos" ' - git clone . one && + git_clone . one && cd one && echo >file updated by one && git commit -a -m "updated by one" && cd .. && - git clone . two && + git_clone . two && cd two && git repo-config branch.master.remote one && { @@ -28,7 +28,7 @@ test_expect_success "clone and setup child repos" ' echo "Pull: refs/heads/master:refs/heads/one" } >.git/remotes/one cd .. && - git clone . three && + git_clone . three && cd three && git repo-config branch.master.remote two && git repo-config branch.master.merge refs/heads/one && @@ -74,7 +74,7 @@ test_expect_success 'fetch following tags' ' mkdir four && cd four && - git init-db && + git_init_db && git fetch .. :track && git show-ref --verify refs/tags/anno && diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index f841574573..66ef92f41f 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -17,7 +17,7 @@ test_expect_success setup ' test_expect_success 'pulling into void' ' mkdir cloned && cd cloned && - git init-db && + git_init_db && git pull .. ' diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh index 041be04f5c..1913a12d71 100755 --- a/t/t5600-clone-fail-cleanup.sh +++ b/t/t5600-clone-fail-cleanup.sh @@ -13,7 +13,7 @@ remove the directory before attempting a clone again.' test_expect_failure \ 'clone of non-existent source should fail' \ - 'git-clone foo bar' + 'git_clone foo bar' test_expect_failure \ 'failed clone should not leave a directory' \ @@ -29,11 +29,11 @@ test_create_repo foo # current path not to the target dir test_expect_failure \ 'clone of non-existent (relative to $PWD) source should fail' \ - 'git-clone ../foo baz' + 'git_clone ../foo baz' test_expect_success \ 'clone should work now that source exists' \ - 'git-clone foo bar' + 'git_clone foo bar' test_expect_success \ 'successfull clone must leave the directory' \ diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index dd9caad1c2..52dab2d484 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -17,7 +17,7 @@ git commit -m initial' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git clone A B && cd B && +'git_clone A B && cd B && echo second > file2 && git add file2 && git commit -m addition && @@ -27,7 +27,7 @@ git prune' cd "$base_dir" test_expect_success 'cloning with reference' \ -'git clone -l -s --reference B A C' +'git_clone -l -s --reference B A C' cd "$base_dir" diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh index b9f6d96363..3c43554c69 100755 --- a/t/t5710-info-alternate.sh +++ b/t/t5710-info-alternate.sh @@ -34,7 +34,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git clone -l -s A B && cd B && +'git_clone -l -s A B && cd B && echo "foo bar" > file2 && git add file2 && git commit -m "next commit" file2 && @@ -44,7 +44,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing third repository' \ -'git clone -l -s B C && cd C && +'git_clone -l -s B C && cd C && echo "Goodbye, cruel world" > file3 && git add file3 && git commit -m "one more" file3 && @@ -54,11 +54,11 @@ git prune' cd "$base_dir" test_expect_failure 'creating too deep nesting' \ -'git clone -l -s C D && -git clone -l -s D E && -git clone -l -s E F && -git clone -l -s F G && -git clone -l -s G H && +'git_clone -l -s C D && +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' diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 2f4ff82e14..ae597e80dd 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -88,7 +88,7 @@ test_expect_success \ test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA && - git init-db && + git_init_db && mkdir -p papers/unsorted papers/all-papers partA && echo a > papers/unsorted/Thesis.pdf && echo b > partA/outline.txt && @@ -109,7 +109,7 @@ rm -fr papers partA path? test_expect_success "Sergey Vlasov's test case" ' rm -fr .git && - git init-db && + git_init_db && mkdir ab && date >ab.c && date >ab/d && diff --git a/t/test-lib.sh b/t/test-lib.sh index ac7be769b4..7e9149751e 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -182,6 +182,16 @@ test_create_repo () { cd "$owd" } +# Many tests do init-db and clone but they must be told about the freshly +# built templates. +git_init_db () { + git init-db --template="$GIT_EXEC_PATH/templates/blt/" "$@" +} + +git_clone () { + git clone --template="$GIT_EXEC_PATH/templates/blt/" "$@" +} + test_done () { trap - exit case "$test_failure" in From 171e800b374c98dd703e906bd9955b2b0410cabe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 19 Dec 2006 01:14:35 -0800 Subject: [PATCH 34/35] Revert "fix testsuite: make sure they use templates freshly built from the source" This reverts commit 74d20040cafdced657efbf49795183d209a3a07b. Version from Johannes to introduce GIT_TEMPLATE_DIR is simpler, although I unconsciously stayed away from introducing yet another environment variable. --- t/t4116-apply-reverse.sh | 4 ++-- t/t5300-pack-object.sh | 6 +++--- t/t5400-send-pack.sh | 2 +- t/t5500-fetch-pack.sh | 2 +- t/t5510-fetch.sh | 8 ++++---- t/t5520-pull.sh | 2 +- t/t5600-clone-fail-cleanup.sh | 6 +++--- t/t5700-clone-reference.sh | 4 ++-- t/t5710-info-alternate.sh | 14 +++++++------- t/t7001-mv.sh | 4 ++-- t/test-lib.sh | 10 ---------- 11 files changed, 26 insertions(+), 36 deletions(-) diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index a79c77af39..74f5c2a575 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -50,12 +50,12 @@ test_expect_success 'setup separate repository lacking postimage' ' git tar-tree initial initial | tar xf - && ( - cd initial && git_init_db && git add . + cd initial && git init-db && git add . ) && git tar-tree second second | tar xf - && ( - cd second && git_init_db && git add . + cd second && git init-db && git add . ) ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 8a8152b257..de45ac4e0f 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -44,7 +44,7 @@ test_expect_success \ 'unpack without delta' \ "GIT_OBJECT_DIRECTORY=.git2/objects && export GIT_OBJECT_DIRECTORY && - git_init_db && + git-init-db && git-unpack-objects -n > log2.txt + git-init-db 2>> log2.txt ) add A1 diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index e2e8c894f9..a11ab0ad41 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -15,12 +15,12 @@ test_expect_success setup ' git commit -a -m original' test_expect_success "clone and setup child repos" ' - git_clone . one && + git clone . one && cd one && echo >file updated by one && git commit -a -m "updated by one" && cd .. && - git_clone . two && + git clone . two && cd two && git repo-config branch.master.remote one && { @@ -28,7 +28,7 @@ test_expect_success "clone and setup child repos" ' echo "Pull: refs/heads/master:refs/heads/one" } >.git/remotes/one cd .. && - git_clone . three && + git clone . three && cd three && git repo-config branch.master.remote two && git repo-config branch.master.merge refs/heads/one && @@ -74,7 +74,7 @@ test_expect_success 'fetch following tags' ' mkdir four && cd four && - git_init_db && + git init-db && git fetch .. :track && git show-ref --verify refs/tags/anno && diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 66ef92f41f..f841574573 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -17,7 +17,7 @@ test_expect_success setup ' test_expect_success 'pulling into void' ' mkdir cloned && cd cloned && - git_init_db && + git init-db && git pull .. ' diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh index 1913a12d71..041be04f5c 100755 --- a/t/t5600-clone-fail-cleanup.sh +++ b/t/t5600-clone-fail-cleanup.sh @@ -13,7 +13,7 @@ remove the directory before attempting a clone again.' test_expect_failure \ 'clone of non-existent source should fail' \ - 'git_clone foo bar' + 'git-clone foo bar' test_expect_failure \ 'failed clone should not leave a directory' \ @@ -29,11 +29,11 @@ test_create_repo foo # current path not to the target dir test_expect_failure \ 'clone of non-existent (relative to $PWD) source should fail' \ - 'git_clone ../foo baz' + 'git-clone ../foo baz' test_expect_success \ 'clone should work now that source exists' \ - 'git_clone foo bar' + 'git-clone foo bar' test_expect_success \ 'successfull clone must leave the directory' \ diff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh index 52dab2d484..dd9caad1c2 100755 --- a/t/t5700-clone-reference.sh +++ b/t/t5700-clone-reference.sh @@ -17,7 +17,7 @@ git commit -m initial' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git_clone A B && cd B && +'git clone A B && cd B && echo second > file2 && git add file2 && git commit -m addition && @@ -27,7 +27,7 @@ git prune' cd "$base_dir" test_expect_success 'cloning with reference' \ -'git_clone -l -s --reference B A C' +'git clone -l -s --reference B A C' cd "$base_dir" diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh index 3c43554c69..b9f6d96363 100755 --- a/t/t5710-info-alternate.sh +++ b/t/t5710-info-alternate.sh @@ -34,7 +34,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing second repository' \ -'git_clone -l -s A B && cd B && +'git clone -l -s A B && cd B && echo "foo bar" > file2 && git add file2 && git commit -m "next commit" file2 && @@ -44,7 +44,7 @@ git prune' cd "$base_dir" test_expect_success 'preparing third repository' \ -'git_clone -l -s B C && cd C && +'git clone -l -s B C && cd C && echo "Goodbye, cruel world" > file3 && git add file3 && git commit -m "one more" file3 && @@ -54,11 +54,11 @@ git prune' cd "$base_dir" test_expect_failure 'creating too deep nesting' \ -'git_clone -l -s C D && -git_clone -l -s D E && -git_clone -l -s E F && -git_clone -l -s F G && -git_clone -l -s G H && +'git clone -l -s C D && +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' diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index ae597e80dd..2f4ff82e14 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -88,7 +88,7 @@ test_expect_success \ test_expect_success "Michael Cassar's test case" ' rm -fr .git papers partA && - git_init_db && + git init-db && mkdir -p papers/unsorted papers/all-papers partA && echo a > papers/unsorted/Thesis.pdf && echo b > partA/outline.txt && @@ -109,7 +109,7 @@ rm -fr papers partA path? test_expect_success "Sergey Vlasov's test case" ' rm -fr .git && - git_init_db && + git init-db && mkdir ab && date >ab.c && date >ab/d && diff --git a/t/test-lib.sh b/t/test-lib.sh index 7e9149751e..ac7be769b4 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -182,16 +182,6 @@ test_create_repo () { cd "$owd" } -# Many tests do init-db and clone but they must be told about the freshly -# built templates. -git_init_db () { - git init-db --template="$GIT_EXEC_PATH/templates/blt/" "$@" -} - -git_clone () { - git clone --template="$GIT_EXEC_PATH/templates/blt/" "$@" -} - test_done () { trap - exit case "$test_failure" in From 8683a45d66967b0969516a2b72cdbf136c2064a2 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Tue, 19 Dec 2006 09:18:09 +0100 Subject: [PATCH 35/35] Introduce GIT_TEMPLATE_DIR Instead of passing --template explicitely to init-db and clone, you can just set the environment variable GIT_TEMPLATE_DIR. Also make use of it in the tests, to make sure that the templates are copied. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-init-db.c | 7 +++++-- t/test-lib.sh | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/builtin-init-db.c b/builtin-init-db.c index 1d7d15e8d5..c8ed5c2a0b 100644 --- a/builtin-init-db.c +++ b/builtin-init-db.c @@ -124,8 +124,11 @@ static void copy_templates(const char *git_dir, int len, const char *template_di int template_len; DIR *dir; - if (!template_dir) - template_dir = DEFAULT_GIT_TEMPLATE_DIR; + if (!template_dir) { + template_dir = getenv("GIT_TEMPLATE_DIR"); + if (!template_dir) + template_dir = DEFAULT_GIT_TEMPLATE_DIR; + } strcpy(template_path, template_dir); template_len = strlen(template_path); if (template_path[template_len-1] != '/') { diff --git a/t/test-lib.sh b/t/test-lib.sh index ac7be769b4..f0f9cd6be0 100755 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -208,8 +208,9 @@ test_done () { # t/ subdirectory and are run in trash subdirectory. PATH=$(pwd)/..:$PATH GIT_EXEC_PATH=$(pwd)/.. +GIT_TEMPLATE_DIR=$(pwd)/../templates/blt HOME=$(pwd)/trash -export PATH GIT_EXEC_PATH HOME +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR HOME GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git export GITPERLLIB