From 776398709dee4050fc194fec45c5818ba9b01afe Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 1 Sep 2007 23:53:47 -0700 Subject: [PATCH 01/94] Keep last used delta base in the delta window This is based on Martin Koegler's idea to keep the object that was successfully used as the base of the delta when it is about to fall off the edge of the window. Instead of doing so only for the objects at the edge of the window, this makes the window a lru eviction mechanism. If an entry is used as a base, it is moved to the last of the queue to be evicted. This is a quick-and-dirty implementation, as it keeps the original implementation of the data structure used for the window. This originally was done as an array, not as an array of pointers, because it was meant to be used as a cyclic FIFO buffer and a plain array avoids an extra pointer indirection, while its FIFOness eant that we are not "moving" the entries like this patch does. The runtime from three versions were comparable. It seems to make the resulting chain even shorter, which can only be good. (stock "master") 15782196 bytes chain length = 1: 2972 objects chain length = 2: 2651 objects chain length = 3: 2369 objects chain length = 4: 2121 objects chain length = 5: 1877 objects ... chain length = 46: 490 objects chain length = 47: 515 objects chain length = 48: 527 objects chain length = 49: 570 objects chain length = 50: 408 objects (with your patch) 15745736 bytes (0.23% smaller) chain length = 1: 3137 objects chain length = 2: 2688 objects chain length = 3: 2322 objects chain length = 4: 2146 objects chain length = 5: 1824 objects ... chain length = 46: 503 objects chain length = 47: 509 objects chain length = 48: 536 objects chain length = 49: 588 objects chain length = 50: 357 objects (with this patch) 15612086 bytes (1.08% smaller) chain length = 1: 4831 objects chain length = 2: 3811 objects chain length = 3: 2964 objects chain length = 4: 2352 objects chain length = 5: 1944 objects ... chain length = 46: 327 objects chain length = 47: 353 objects chain length = 48: 304 objects chain length = 49: 298 objects chain length = 50: 135 objects [jc: this is with code simplification follow-up from Nico] Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 12509faa77..e64e3a03a0 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1460,7 +1460,7 @@ static void find_deltas(struct object_entry **list, int window, int depth) do { struct object_entry *entry = list[--i]; struct unpacked *n = array + idx; - int j; + int j, best_base = -1; if (!entry->preferred_base) processed++; @@ -1505,6 +1505,7 @@ static void find_deltas(struct object_entry **list, int window, int depth) j = window; while (--j > 0) { + int ret; uint32_t other_idx = idx + j; struct unpacked *m; if (other_idx >= window) @@ -1512,8 +1513,11 @@ static void find_deltas(struct object_entry **list, int window, int depth) m = array + other_idx; if (!m->entry) break; - if (try_delta(n, m, max_depth) < 0) + ret = try_delta(n, m, max_depth); + if (ret < 0) break; + else if (ret > 0) + best_base = other_idx; } /* if we made n a delta, and if n is already at max @@ -1523,6 +1527,23 @@ static void find_deltas(struct object_entry **list, int window, int depth) if (entry->delta && depth <= n->depth) continue; + /* + * Move the best delta base up in the window, after the + * currently deltified object, to keep it longer. It will + * be the first base object to be attempted next. + */ + if (entry->delta) { + struct unpacked swap = array[best_base]; + int dist = (window + idx - best_base) % window; + int dst = best_base; + while (dist--) { + int src = (dst + 1) % window; + array[dst] = array[src]; + dst = src; + } + array[dst] = swap; + } + next: idx++; if (count + 1 < window) From 38944390220425cc3c4208dd31172397e7f18e8c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 2 Sep 2007 21:10:14 +0100 Subject: [PATCH 02/94] Teach "git remote" a mirror mode When using the "--mirror" option to "git remote add", the refs will not be stored in the refs/remotes/ namespace, but in the same location as on the remote side. This option probably only makes sense in a bare repository. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- Documentation/git-remote.txt | 6 +++++- git-remote.perl | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Documentation/git-remote.txt b/Documentation/git-remote.txt index 61a6022ce8..94b9f17772 100644 --- a/Documentation/git-remote.txt +++ b/Documentation/git-remote.txt @@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git-remote' -'git-remote' add [-t ] [-m ] [-f] +'git-remote' add [-t ] [-m ] [-f] [--mirror] 'git-remote' show 'git-remote' prune 'git-remote' update [group] @@ -45,6 +45,10 @@ multiple branches without grabbing all branches. With `-m ` option, `$GIT_DIR/remotes//HEAD` is set up to point at remote's `` branch instead of whatever branch the `HEAD` at the remote repository actually points at. ++ +In mirror mode, enabled with `--mirror`, the refs will not be stored +in the 'refs/remotes/' namespace, but in 'refs/heads/'. This option +only makes sense in bare repositories. 'show':: diff --git a/git-remote.perl b/git-remote.perl index 01cf480221..f6f283ea4f 100755 --- a/git-remote.perl +++ b/git-remote.perl @@ -278,7 +278,9 @@ sub add_remote { for (@$track) { $git->command('config', '--add', "remote.$name.fetch", - "+refs/heads/$_:refs/remotes/$name/$_"); + $opts->{'mirror'} ? + "+refs/$_:refs/$_" : + "+refs/heads/$_:refs/remotes/$name/$_"); } if ($opts->{'fetch'}) { $git->command('fetch', $name); @@ -409,6 +411,10 @@ elsif ($ARGV[0] eq 'add') { shift @ARGV; next; } + if ($opt eq '--mirror') { + $opts{'mirror'} = 1; + next; + } add_usage(); } if (@ARGV != 3) { From fec60a261d9375d1f129313bb68036fbd2a5175c Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 3 Sep 2007 17:51:43 +0100 Subject: [PATCH 03/94] verify-tag: also grok CR/LFs in the tag signature On some people's favorite platform, gpg outputs signatures with CR/LF line endings. So verify-tag has to play nice with them. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-verify-tag.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-verify-tag.c b/builtin-verify-tag.c index dfcfcd0455..cc4c55d7ee 100644 --- a/builtin-verify-tag.c +++ b/builtin-verify-tag.c @@ -35,7 +35,7 @@ static int run_gpg_verify(const char *buf, unsigned long size, int verbose) /* find the length without signature */ len = 0; - while (len < size && prefixcmp(buf + len, PGP_SIGNATURE "\n")) { + while (len < size && prefixcmp(buf + len, PGP_SIGNATURE)) { eol = memchr(buf + len, '\n', size - len); len += eol ? eol - (buf + len) + 1 : size - len; } From 6e4ba05c7fee0d0140e2057b63f5ca4eea9a6053 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 2 Sep 2007 15:19:07 -0400 Subject: [PATCH 04/94] git-gui: Correct starting of git-remote to handle -w option Current versions of git-remote apparently are passing the -w option to Perl as part of the shbang line: #!/usr/bin/perl -w this caused a problem in git-gui and gave the user a Tcl error with the message: "git-remote not supported: #!/usr/bin/perl -w". The fix for this is to treat the shbang line as a Tcl list and look at the first element only for guessing the executable name. Once we know the executable name we use the remaining elements (if any exist) as arguments to the executable, before the script filename. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index fa30ccc5d6..e495046c3b 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -261,7 +261,7 @@ proc _git_cmd {name} { set s [gets $f] close $f - switch -glob -- $s { + switch -glob -- [lindex $s 0] { #!*sh { set i sh } #!*perl { set i perl } #!*python { set i python } @@ -275,7 +275,7 @@ proc _git_cmd {name} { if {$interp eq {}} { error "git-$name requires $i (not in PATH)" } - set v [list $interp $p] + set v [concat [list $interp] [lrange $s 1 end] [list $p]] } else { # Assume it is builtin to git somehow and we # aren't actually able to see a file for it. From 881d8f24cab5bf4e0fa71b17a3ab82e27b2e8ed7 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 2 Sep 2007 15:30:26 -0400 Subject: [PATCH 05/94] git-gui: Fix detaching current branch during checkout If the user tried to detach their HEAD while keeping the working directory on the same commit we actually did not completely do a detach operation internally. The problem was caused by git-gui not forcing the HEAD symbolic ref to be updated to a SHA-1 hash when we were not switching revisions. Now we update the HEAD ref if we aren't currently detached or the hashes don't match. Signed-off-by: Shawn O. Pearce --- lib/checkout_op.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/checkout_op.tcl b/lib/checkout_op.tcl index 170f737f61..76f04f2854 100644 --- a/lib/checkout_op.tcl +++ b/lib/checkout_op.tcl @@ -396,7 +396,7 @@ method _after_readtree {} { set is_detached 0 } } else { - if {$new_hash ne $HEAD} { + if {!$is_detached || $new_hash ne $HEAD} { append log " to $new_expr" if {[catch { _detach_HEAD $log $new_hash From 047d94d505c9837a60c28e121de65471dadce74b Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 2 Sep 2007 15:38:04 -0400 Subject: [PATCH 06/94] git-gui: Properly set the state of "Stage/Unstage Hunk" action Today I found yet another way for the "Stage Hunk" and "Unstage Hunk" context menu actions to leave the wrong state enabled in the UI. The problem this time was that I connected the state determination to the value of $::current_diff_side (the side the diff is from). When the user was last looking at a diff from the index side and unstages everything the diff panel goes empty, but the action stayed enabled as we always assumed unstaging was a valid action. This change moves the logic for determining when the action is enabled away from the individual side selection, as they really are two unrelated concepts. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index e495046c3b..44977aa212 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -2441,20 +2441,17 @@ proc popup_diff_menu {ctxm x y X Y} { set ::cursorX $x set ::cursorY $y if {$::ui_index eq $::current_diff_side} { - set s normal set l "Unstage Hunk From Commit" } else { - if {$current_diff_path eq {} - || ![info exists file_states($current_diff_path)] - || {_O} eq [lindex $file_states($current_diff_path) 0]} { - set s disabled - } else { - set s normal - } set l "Stage Hunk For Commit" } - if {$::is_3way_diff} { + if {$::is_3way_diff + || $current_diff_path eq {} + || ![info exists file_states($current_diff_path)] + || {_O} eq [lindex $file_states($current_diff_path) 0]} { set s disabled + } else { + set s normal } $ctxm entryconf $::ui_diff_applyhunk -state $s -label $l tk_popup $ctxm $X $Y From 05b4df31537a653eaa30d2c6f53e05d7a12d1bc8 Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Wed, 5 Sep 2007 11:35:29 +0200 Subject: [PATCH 07/94] git-svn: add support for --first-parent When git-svn uses git-log to find embedded 'git-svn-id'-lines in commit messages, it can get confused when local history contains merges with other git-svn branches. But if --first-parent is supplied to git-log, working_head_info() will only see 'branch-local' commits and thus the first commit containing a 'git-svn-id' line should refer to the correct subversion branch. Signed-off-by: Lars Hjemli Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/git-svn.txt | 10 ++++++++++ git-svn.perl | 17 +++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index be2e34eb8f..42d7b82a37 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -317,6 +317,16 @@ This is only used with the 'dcommit' command. Print out the series of git arguments that would show which diffs would be committed to SVN. +--first-parent:: + +This is only used with the 'dcommit', 'rebase', 'log', 'find-rev' and +'show-ignore' commands. + +These commands tries to detect the upstream subversion branch by means of +the embedded 'git-svn-id' line in commit messages. When --first-parent is +specified, git-svn only follows the first parent of each commit, effectively +ignoring commits brought into the current branch through merge-operations. + -- ADVANCED OPTIONS diff --git a/git-svn.perl b/git-svn.perl index d3c8cd0b8e..d21eb7fa9e 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -59,7 +59,7 @@ my ($_stdin, $_help, $_edit, $_template, $_shared, $_version, $_fetch_all, $_no_rebase, $_merge, $_strategy, $_dry_run, $_local, - $_prefix, $_no_checkout, $_verbose); + $_prefix, $_no_checkout, $_verbose, $_first_parent); $Git::SVN::_follow_parent = 1; my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username, 'config-dir=s' => \$Git::SVN::Ra::config_dir, @@ -119,12 +119,15 @@ my %cmd = ( 'dry-run|n' => \$_dry_run, 'fetch-all|all' => \$_fetch_all, 'no-rebase' => \$_no_rebase, + 'first-parent' => \$_first_parent, %cmt_opts, %fc_opts } ], 'set-tree' => [ \&cmd_set_tree, "Set an SVN repository to a git tree-ish", { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ], 'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings", - { 'revision|r=i' => \$_revision } ], + { 'revision|r=i' => \$_revision, + 'first-parent' => \$_first_parent + } ], 'multi-fetch' => [ \&cmd_multi_fetch, "Deprecated alias for $0 fetch --all", { 'revision|r=s' => \$_revision, %fc_opts } ], @@ -145,15 +148,19 @@ my %cmd = ( 'authors-file|A=s' => \$_authors, 'color' => \$Git::SVN::Log::color, 'pager=s' => \$Git::SVN::Log::pager, + 'first-parent' => \$_first_parent } ], 'find-rev' => [ \&cmd_find_rev, "Translate between SVN revision numbers and tree-ish", - { } ], + { + 'first-parent' => \$_first_parent + } ], 'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory", { 'merge|m|M' => \$_merge, 'verbose|v' => \$_verbose, 'strategy|s=s' => \$_strategy, 'local|l' => \$_local, 'fetch-all|all' => \$_fetch_all, + 'first-parent' => \$_first_parent, %fc_opts } ], 'commit-diff' => [ \&cmd_commit_diff, 'Commit a diff between two trees', @@ -811,7 +818,9 @@ sub cmt_metadata { sub working_head_info { my ($head, $refs) = @_; - my ($fh, $ctx) = command_output_pipe('log', '--no-color', $head); + my @args = ('log', '--no-color'); + push @args, '--first-parent' if $_first_parent; + my ($fh, $ctx) = command_output_pipe(@args, $head); my $hash; my %max; while (<$fh>) { From 75d3985319f2eb40008e9fe6454880ecc620a0de Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 6 Sep 2007 02:13:08 -0400 Subject: [PATCH 08/94] straighten the list of objects to deltify Not all objects are subject to deltification, so avoid carrying those along, and provide the real count to progress display. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 77 +++++++++++++++++++++++------------------- 1 file changed, 42 insertions(+), 35 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index e64e3a03a0..b1c64bec3e 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1313,12 +1313,6 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, if (trg_entry->type != src_entry->type) return -1; - /* We do not compute delta to *create* objects we are not - * going to pack. - */ - if (trg_entry->preferred_base) - return -1; - /* * We do not bother to try a delta that we discarded * on an earlier try, but only when reusing delta data. @@ -1443,43 +1437,24 @@ static void free_unpacked(struct unpacked *n) n->depth = 0; } -static void find_deltas(struct object_entry **list, int window, int depth) +static void find_deltas(struct object_entry **list, unsigned list_size, + unsigned nr_deltas, int window, int depth) { - uint32_t i = nr_objects, idx = 0, count = 0, processed = 0; + uint32_t i = list_size, idx = 0, count = 0, processed = 0; unsigned int array_size = window * sizeof(struct unpacked); struct unpacked *array; int max_depth; - if (!nr_objects) - return; array = xmalloc(array_size); memset(array, 0, array_size); if (progress) - start_progress(&progress_state, "Deltifying %u objects...", "", nr_result); + start_progress(&progress_state, "Deltifying %u objects...", "", nr_deltas); do { struct object_entry *entry = list[--i]; struct unpacked *n = array + idx; int j, best_base = -1; - if (!entry->preferred_base) - processed++; - - if (progress) - display_progress(&progress_state, processed); - - if (entry->delta) - /* This happens if we decided to reuse existing - * delta from a pack. "!no_reuse_delta &&" is implied. - */ - continue; - - if (entry->size < 50) - continue; - - if (entry->no_try_delta) - continue; - free_unpacked(n); n->entry = entry; @@ -1491,6 +1466,15 @@ static void find_deltas(struct object_entry **list, int window, int depth) count--; } + /* We do not compute delta to *create* objects we are not + * going to pack. + */ + if (entry->preferred_base) + goto next; + + if (progress) + display_progress(&progress_state, ++processed); + /* * If the current object is at pack edge, take the depth the * objects that depend on the current object into account @@ -1565,18 +1549,41 @@ static void find_deltas(struct object_entry **list, int window, int depth) static void prepare_pack(int window, int depth) { struct object_entry **delta_list; - uint32_t i; + uint32_t i, n, nr_deltas; get_object_details(); - if (!window || !depth) + if (!nr_objects || !window || !depth) return; delta_list = xmalloc(nr_objects * sizeof(*delta_list)); - for (i = 0; i < nr_objects; i++) - delta_list[i] = objects + i; - qsort(delta_list, nr_objects, sizeof(*delta_list), type_size_sort); - find_deltas(delta_list, window+1, depth); + nr_deltas = n = 0; + + for (i = 0; i < nr_objects; i++) { + struct object_entry *entry = objects + i; + + if (entry->delta) + /* This happens if we decided to reuse existing + * delta from a pack. "!no_reuse_delta &&" is implied. + */ + continue; + + if (entry->size < 50) + continue; + + if (entry->no_try_delta) + continue; + + if (!entry->preferred_base) + nr_deltas++; + + delta_list[n++] = entry; + } + + if (nr_deltas) { + qsort(delta_list, n, sizeof(*delta_list), type_size_sort); + find_deltas(delta_list, n, nr_deltas, window+1, depth); + } free(delta_list); } From ef0316fcd996c1679fef37ae2a53bef403c77356 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 6 Sep 2007 02:13:09 -0400 Subject: [PATCH 09/94] localize window memory usage accounting This is to help threadification of delta searching. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b1c64bec3e..b8495bf924 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -78,7 +78,6 @@ static unsigned long delta_cache_size = 0; static unsigned long max_delta_cache_size = 0; static unsigned long cache_max_small_delta_size = 1000; -static unsigned long window_memory_usage = 0; static unsigned long window_memory_limit = 0; /* @@ -1300,7 +1299,7 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size, * one. */ static int try_delta(struct unpacked *trg, struct unpacked *src, - unsigned max_depth) + unsigned max_depth, unsigned long *mem_usage) { struct object_entry *trg_entry = trg->entry; struct object_entry *src_entry = src->entry; @@ -1356,7 +1355,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, if (sz != trg_size) die("object %s inconsistent object length (%lu vs %lu)", sha1_to_hex(trg_entry->idx.sha1), sz, trg_size); - window_memory_usage += sz; + *mem_usage += sz; } if (!src->data) { src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz); @@ -1366,7 +1365,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, if (sz != src_size) die("object %s inconsistent object length (%lu vs %lu)", sha1_to_hex(src_entry->idx.sha1), sz, src_size); - window_memory_usage += sz; + *mem_usage += sz; } if (!src->index) { src->index = create_delta_index(src->data, src_size); @@ -1376,7 +1375,7 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, warning("suboptimal pack - out of memory"); return 0; } - window_memory_usage += sizeof_delta_index(src->index); + *mem_usage += sizeof_delta_index(src->index); } delta_buf = create_delta(src->index, trg->data, trg_size, &delta_size, max_size); @@ -1423,18 +1422,19 @@ static unsigned int check_delta_limit(struct object_entry *me, unsigned int n) return m; } -static void free_unpacked(struct unpacked *n) +static unsigned long free_unpacked(struct unpacked *n) { - window_memory_usage -= sizeof_delta_index(n->index); + unsigned long freed_mem = sizeof_delta_index(n->index); free_delta_index(n->index); n->index = NULL; if (n->data) { + freed_mem += n->entry->size; free(n->data); n->data = NULL; - window_memory_usage -= n->entry->size; } n->entry = NULL; n->depth = 0; + return freed_mem; } static void find_deltas(struct object_entry **list, unsigned list_size, @@ -1443,7 +1443,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size, uint32_t i = list_size, idx = 0, count = 0, processed = 0; unsigned int array_size = window * sizeof(struct unpacked); struct unpacked *array; - int max_depth; + unsigned long mem_usage = 0; array = xmalloc(array_size); memset(array, 0, array_size); @@ -1453,16 +1453,16 @@ static void find_deltas(struct object_entry **list, unsigned list_size, do { struct object_entry *entry = list[--i]; struct unpacked *n = array + idx; - int j, best_base = -1; + int j, max_depth, best_base = -1; - free_unpacked(n); + mem_usage -= free_unpacked(n); n->entry = entry; while (window_memory_limit && - window_memory_usage > window_memory_limit && + mem_usage > window_memory_limit && count > 1) { uint32_t tail = (idx + window - count) % window; - free_unpacked(array + tail); + mem_usage -= free_unpacked(array + tail); count--; } @@ -1497,7 +1497,7 @@ static void find_deltas(struct object_entry **list, unsigned list_size, m = array + other_idx; if (!m->entry) break; - ret = try_delta(n, m, max_depth); + ret = try_delta(n, m, max_depth, &mem_usage); if (ret < 0) break; else if (ret > 0) From e334977dfad575cd8ac1a9e5f8e73fe4d018cec0 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 6 Sep 2007 02:13:10 -0400 Subject: [PATCH 10/94] rearrange delta search progress reporting This is to help threadification of the delta search code, with a bonus consistency check. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b8495bf924..9d565925e7 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1438,17 +1438,15 @@ static unsigned long free_unpacked(struct unpacked *n) } static void find_deltas(struct object_entry **list, unsigned list_size, - unsigned nr_deltas, int window, int depth) + int window, int depth, unsigned *processed) { - uint32_t i = list_size, idx = 0, count = 0, processed = 0; + uint32_t i = list_size, idx = 0, count = 0; unsigned int array_size = window * sizeof(struct unpacked); struct unpacked *array; unsigned long mem_usage = 0; array = xmalloc(array_size); memset(array, 0, array_size); - if (progress) - start_progress(&progress_state, "Deltifying %u objects...", "", nr_deltas); do { struct object_entry *entry = list[--i]; @@ -1472,8 +1470,9 @@ static void find_deltas(struct object_entry **list, unsigned list_size, if (entry->preferred_base) goto next; + (*processed)++; if (progress) - display_progress(&progress_state, ++processed); + display_progress(&progress_state, *processed); /* * If the current object is at pack edge, take the depth the @@ -1536,9 +1535,6 @@ static void find_deltas(struct object_entry **list, unsigned list_size, idx = 0; } while (i > 0); - if (progress) - stop_progress(&progress_state); - for (i = 0; i < window; ++i) { free_delta_index(array[i].index); free(array[i].data); @@ -1581,8 +1577,17 @@ static void prepare_pack(int window, int depth) } if (nr_deltas) { + unsigned nr_done = 0; + if (progress) + start_progress(&progress_state, + "Deltifying %u objects...", "", + nr_deltas); qsort(delta_list, n, sizeof(*delta_list), type_size_sort); - find_deltas(delta_list, n, nr_deltas, window+1, depth); + find_deltas(delta_list, n, window+1, depth, &nr_done); + if (progress) + stop_progress(&progress_state); + if (nr_done != nr_deltas) + die("inconsistency with delta count"); } free(delta_list); } From 8ecce684a38f7cea084abe9eef80bda04d7c77be Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Thu, 6 Sep 2007 02:13:11 -0400 Subject: [PATCH 11/94] basic threaded delta search this is still rough, hence it is disabled by default. You need to compile with "make THREADED_DELTA_SEARCH=1 ..." at the moment. Threading is done on different portions of the object list to be deltified. This is currently done by spliting the list into n parts and then a thread is spawned for each of them. A better method would consist of spliting the list into more smaller parts and have the n threads pick the next part available. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- Makefile | 8 ++++ builtin-pack-objects.c | 83 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 51af531c9a..a92fb31695 100644 --- a/Makefile +++ b/Makefile @@ -122,6 +122,9 @@ all:: # If not set it defaults to the bare 'wish'. If it is set to the empty # string then NO_TCLTK will be forced (this is used by configure script). # +# Define THREADED_DELTA_SEARCH if you have pthreads and wish to exploit +# parallel delta searching when packing objects. +# GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE @$(SHELL_PATH) ./GIT-VERSION-GEN @@ -662,6 +665,11 @@ ifdef NO_HSTRERROR COMPAT_OBJS += compat/hstrerror.o endif +ifdef THREADED_DELTA_SEARCH + BASIC_CFLAGS += -DTHREADED_DELTA_SEARCH + EXTLIBS += -lpthread +endif + ifeq ($(TCLTK_PATH),) NO_TCLTK=NoThanks endif diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 9d565925e7..1bcee23ca1 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -15,6 +15,10 @@ #include "list-objects.h" #include "progress.h" +#ifdef THREADED_DELTA_SEARCH +#include +#endif + static const char pack_usage[] = "\ git-pack-objects [{ -q | --progress | --all-progress }] \n\ [--max-pack-size=N] [--local] [--incremental] \n\ @@ -1290,6 +1294,25 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size, return 0; } +#ifdef THREADED_DELTA_SEARCH + +static pthread_mutex_t read_mutex = PTHREAD_MUTEX_INITIALIZER; +#define read_lock() pthread_mutex_lock(&read_mutex) +#define read_unlock() pthread_mutex_unlock(&read_mutex) + +static pthread_mutex_t progress_mutex = PTHREAD_MUTEX_INITIALIZER; +#define progress_lock() pthread_mutex_lock(&progress_mutex) +#define progress_unlock() pthread_mutex_unlock(&progress_mutex) + +#else + +#define read_lock() 0 +#define read_unlock() 0 +#define progress_lock() 0 +#define progress_unlock() 0 + +#endif + /* * We search for deltas _backwards_ in a list sorted by type and * by size, so that we see progressively smaller and smaller files. @@ -1348,7 +1371,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, /* Load data if not already done */ if (!trg->data) { + read_lock(); trg->data = read_sha1_file(trg_entry->idx.sha1, &type, &sz); + read_unlock(); if (!trg->data) die("object %s cannot be read", sha1_to_hex(trg_entry->idx.sha1)); @@ -1358,7 +1383,9 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, *mem_usage += sz; } if (!src->data) { + read_lock(); src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz); + read_unlock(); if (!src->data) die("object %s cannot be read", sha1_to_hex(src_entry->idx.sha1)); @@ -1470,9 +1497,11 @@ static void find_deltas(struct object_entry **list, unsigned list_size, if (entry->preferred_base) goto next; + progress_lock(); (*processed)++; if (progress) display_progress(&progress_state, *processed); + progress_unlock(); /* * If the current object is at pack edge, take the depth the @@ -1542,6 +1571,58 @@ static void find_deltas(struct object_entry **list, unsigned list_size, free(array); } +#ifdef THREADED_DELTA_SEARCH + +struct thread_params { + pthread_t thread; + struct object_entry **list; + unsigned list_size; + int window; + int depth; + unsigned *processed; +}; + +static void *threaded_find_deltas(void *arg) +{ + struct thread_params *p = arg; + if (p->list_size) + find_deltas(p->list, p->list_size, + p->window, p->depth, p->processed); + return NULL; +} + +#define NR_THREADS 8 + +static void ll_find_deltas(struct object_entry **list, unsigned list_size, + int window, int depth, unsigned *processed) +{ + struct thread_params p[NR_THREADS]; + int i, ret; + + for (i = 0; i < NR_THREADS; i++) { + unsigned sublist_size = list_size / (NR_THREADS - i); + p[i].list = list; + p[i].list_size = sublist_size; + p[i].window = window; + p[i].depth = depth; + p[i].processed = processed; + ret = pthread_create(&p[i].thread, NULL, + threaded_find_deltas, &p[i]); + if (ret) + die("unable to create thread: %s", strerror(ret)); + list += sublist_size; + list_size -= sublist_size; + } + + for (i = 0; i < NR_THREADS; i++) { + pthread_join(p[i].thread, NULL); + } +} + +#else +#define ll_find_deltas find_deltas +#endif + static void prepare_pack(int window, int depth) { struct object_entry **delta_list; @@ -1583,7 +1664,7 @@ static void prepare_pack(int window, int depth) "Deltifying %u objects...", "", nr_deltas); qsort(delta_list, n, sizeof(*delta_list), type_size_sort); - find_deltas(delta_list, n, window+1, depth, &nr_done); + ll_find_deltas(delta_list, n, window+1, depth, &nr_done); if (progress) stop_progress(&progress_state); if (nr_done != nr_deltas) From 4dbfe2e9bdfdde2d3257194573cee0d41471592b Mon Sep 17 00:00:00 2001 From: Lars Hjemli Date: Fri, 7 Sep 2007 02:00:08 +0200 Subject: [PATCH 12/94] git-svn: always use --first-parent This makes git-svn unconditionally invoke git-log with --first-parent when it is trying to discover its upstream subversion branch and collecting the commit ids which should be pushed to it with dcommit. The reason for always using --first-parent is to make git-svn behave in a predictable way when the ancestry chain contains merges with other git-svn branches. Since git-svn now always uses 'git-log --first-parent' there is no longer any need for the --first-parent option to git-svn, so this is removed. Signed-off-by: Lars Hjemli Acked-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/git-svn.txt | 10 ---------- git-svn.perl | 17 +++++------------ 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index 42d7b82a37..be2e34eb8f 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -317,16 +317,6 @@ This is only used with the 'dcommit' command. Print out the series of git arguments that would show which diffs would be committed to SVN. ---first-parent:: - -This is only used with the 'dcommit', 'rebase', 'log', 'find-rev' and -'show-ignore' commands. - -These commands tries to detect the upstream subversion branch by means of -the embedded 'git-svn-id' line in commit messages. When --first-parent is -specified, git-svn only follows the first parent of each commit, effectively -ignoring commits brought into the current branch through merge-operations. - -- ADVANCED OPTIONS diff --git a/git-svn.perl b/git-svn.perl index d21eb7fa9e..badcd33c2c 100755 --- a/git-svn.perl +++ b/git-svn.perl @@ -59,7 +59,7 @@ my ($_stdin, $_help, $_edit, $_template, $_shared, $_version, $_fetch_all, $_no_rebase, $_merge, $_strategy, $_dry_run, $_local, - $_prefix, $_no_checkout, $_verbose, $_first_parent); + $_prefix, $_no_checkout, $_verbose); $Git::SVN::_follow_parent = 1; my %remote_opts = ( 'username=s' => \$Git::SVN::Prompt::_username, 'config-dir=s' => \$Git::SVN::Ra::config_dir, @@ -119,14 +119,12 @@ my %cmd = ( 'dry-run|n' => \$_dry_run, 'fetch-all|all' => \$_fetch_all, 'no-rebase' => \$_no_rebase, - 'first-parent' => \$_first_parent, %cmt_opts, %fc_opts } ], 'set-tree' => [ \&cmd_set_tree, "Set an SVN repository to a git tree-ish", { 'stdin|' => \$_stdin, %cmt_opts, %fc_opts, } ], 'show-ignore' => [ \&cmd_show_ignore, "Show svn:ignore listings", - { 'revision|r=i' => \$_revision, - 'first-parent' => \$_first_parent + { 'revision|r=i' => \$_revision } ], 'multi-fetch' => [ \&cmd_multi_fetch, "Deprecated alias for $0 fetch --all", @@ -147,20 +145,16 @@ my %cmd = ( 'non-recursive' => \$Git::SVN::Log::non_recursive, 'authors-file|A=s' => \$_authors, 'color' => \$Git::SVN::Log::color, - 'pager=s' => \$Git::SVN::Log::pager, - 'first-parent' => \$_first_parent + 'pager=s' => \$Git::SVN::Log::pager } ], 'find-rev' => [ \&cmd_find_rev, "Translate between SVN revision numbers and tree-ish", - { - 'first-parent' => \$_first_parent - } ], + {} ], 'rebase' => [ \&cmd_rebase, "Fetch and rebase your working directory", { 'merge|m|M' => \$_merge, 'verbose|v' => \$_verbose, 'strategy|s=s' => \$_strategy, 'local|l' => \$_local, 'fetch-all|all' => \$_fetch_all, - 'first-parent' => \$_first_parent, %fc_opts } ], 'commit-diff' => [ \&cmd_commit_diff, 'Commit a diff between two trees', @@ -818,8 +812,7 @@ sub cmt_metadata { sub working_head_info { my ($head, $refs) = @_; - my @args = ('log', '--no-color'); - push @args, '--first-parent' if $_first_parent; + my @args = ('log', '--no-color', '--first-parent'); my ($fh, $ctx) = command_output_pipe(@args, $head); my $hash; my %max; From 0b883ab30c869c4f22a19e49aedc1604d335cd91 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Fri, 7 Sep 2007 17:16:59 +0000 Subject: [PATCH 13/94] git-gui: lib/index.tcl: handle files with % in the filename properly Steps to reproduce the bug: $ mkdir repo && cd repo && git init Initialized empty Git repository in .git/ $ touch 'foo%3Fsuite' $ git-gui Then click on the 'foo%3Fsuite' icon to include it in a changeset, a popup comes with: 'Error: bad field specifier "F"' Vincent Danjean noticed the problem and also suggested the fix, reported through http://bugs.debian.org/441167 Signed-off-by: Gerrit Pape Signed-off-by: Shawn O. Pearce --- lib/index.tcl | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/index.tcl b/lib/index.tcl index f47f9290c8..cbbce13a77 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -13,7 +13,8 @@ proc update_indexinfo {msg pathList after} { if {$batch > 25} {set batch 25} ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ 0.0] @@ -68,7 +69,8 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} { } ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ [expr {100.0 * $update_index_cp / $totalCnt}]] @@ -86,7 +88,8 @@ proc update_index {msg pathList after} { if {$batch > 25} {set batch 25} ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ 0.0] @@ -145,7 +148,8 @@ proc write_update_index {fd pathList totalCnt batch msg after} { } ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ [expr {100.0 * $update_index_cp / $totalCnt}]] @@ -163,7 +167,8 @@ proc checkout_index {msg pathList after} { if {$batch > 25} {set batch 25} ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg $update_index_cp \ $totalCnt \ 0.0] @@ -218,7 +223,8 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} { } ui_status [format \ - "$msg... %i/%i files (%.2f%%)" \ + "%s... %i/%i files (%.2f%%)" \ + $msg \ $update_index_cp \ $totalCnt \ [expr {100.0 * $update_index_cp / $totalCnt}]] From cff93397ab185898fd93b6a260cc6f3068c4ac30 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 8 Sep 2007 23:47:00 -0400 Subject: [PATCH 14/94] git-gui: Disable Tk send in all git-gui sessions The Tk designers blessed us with the "send" command, which on X11 will allow anyone who can connect to your X server to evaluate any Tcl code they desire within any running Tk process. This is just plain nuts. If git-gui wants someone running Tcl code within it then would ask someone to supply that Tcl code to it; waiting for someone to drop any random Tcl code into us is not fantastic idea. By renaming send to the empty name the procedure will be removed from the global namespace and Tk will stop responding to random Tcl evaluation requests sent through the X server. Since there is no facility to filter these requests it is unlikely that we will ever consider enabling this command. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index 44977aa212..6d676097a6 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -42,6 +42,8 @@ if {[catch {package require Tcl 8.4} err] exit 1 } +rename send {} ; # What an evil concept... + ###################################################################### ## ## enable verbose loading? From c63fe3b2dc90120a4bdba7194f92efc2f3c342ed Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sat, 8 Sep 2007 23:05:43 -0400 Subject: [PATCH 15/94] git-gui: Avoid use of libdir in Makefile Dmitry V. Levin pointed out that on GNU linux libdir is often used in Makefiles to mean "/usr/lib" or "/usr/lib64", a directory that is meant to hold platform-specific binary files. Using a different libdir meaning here in git-gui's Makefile breaks idomatic expressions like rpm specifile "make libdir=%_libdir". Originally I asked that the git.git Makefile undefine libdir before it calls git-gui's own Makefile but it turns out this is very hard to do, if not impossible. Renaming our libdir to gg_libdir resolves this case with a minimum amount of fuss on our part. Signed-off-by: Shawn O. Pearce --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 1bac6fed46..f11cf26760 100644 --- a/Makefile +++ b/Makefile @@ -76,8 +76,8 @@ SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) TCL_PATH_SQ = $(subst ','\'',$(TCL_PATH)) TCLTK_PATH_SQ = $(subst ','\'',$(TCLTK_PATH)) -libdir ?= $(sharedir)/git-gui/lib -libdir_SQ = $(subst ','\'',$(libdir)) +gg_libdir ?= $(sharedir)/git-gui/lib +libdir_SQ = $(subst ','\'',$(gg_libdir)) exedir = $(dir $(gitexecdir))share/git-gui/lib exedir_SQ = $(subst ','\'',$(exedir)) @@ -126,7 +126,7 @@ TRACK_VARS = \ $(subst ','\'',TCL_PATH='$(TCL_PATH_SQ)') \ $(subst ','\'',TCLTK_PATH='$(TCLTK_PATH_SQ)') \ $(subst ','\'',gitexecdir='$(gitexecdir_SQ)') \ - $(subst ','\'',libdir='$(libdir_SQ)') \ + $(subst ','\'',gg_libdir='$(libdir_SQ)') \ #end TRACK_VARS GIT-GUI-VARS: .FORCE-GIT-GUI-VARS From 2d19f8e921a1cdc562783814747819b0d5a12641 Mon Sep 17 00:00:00 2001 From: Michele Ballabio Date: Sun, 9 Sep 2007 21:04:45 +0200 Subject: [PATCH 16/94] git-gui: show unstaged symlinks in diff viewer git-gui has a minor problem with regards to symlinks that point to directories. git init mkdir realdir ln -s realdir linkdir git gui Now clicking on file names in the "unstaged changes" window, there's a problem coming from the "linkdir" symlink: git-gui complains with error reading "file4": illegal operation on a directory ...even though git-gui can add that same symlink to the index just fine. This patch fix this by adding a check. [sp: Minor fix to use {link} instead of "link" in condition and to only open the path if it is not a symlink.] Signed-off-by: Michele Ballabio Signed-off-by: Shawn O. Pearce --- lib/diff.tcl | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/diff.tcl b/lib/diff.tcl index e09e1257e1..9eeff2ed35 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -85,11 +85,16 @@ proc show_diff {path w {lno {}}} { if {$m eq {_O}} { set max_sz [expr {128 * 1024}] if {[catch { - set fd [open $path r] - fconfigure $fd -eofchar {} - set content [read $fd $max_sz] - close $fd - set sz [file size $path] + if {[file type $path] == {link}} { + set content [file readlink $path] + set sz [string length $content] + } else { + set fd [open $path r] + fconfigure $fd -eofchar {} + set content [read $fd $max_sz] + close $fd + set sz [file size $path] + } } err ]} { set diff_active 0 unlock_index From 4ed1a190d09c7d6a248038edb11addda77af7550 Mon Sep 17 00:00:00 2001 From: Michele Ballabio Date: Sun, 9 Sep 2007 21:09:07 +0200 Subject: [PATCH 17/94] git-gui: handle "deleted symlink" diff marker Signed-off-by: Michele Ballabio Signed-off-by: Shawn O. Pearce --- lib/diff.tcl | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/diff.tcl b/lib/diff.tcl index 9eeff2ed35..a1d5e523d2 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -203,6 +203,7 @@ proc read_diff {fd} { if {[string match {mode *} $line] || [string match {new file *} $line] || [string match {deleted file *} $line] + || [string match {deleted symlink} $line] || [string match {Binary files * and * differ} $line] || $line eq {\ No newline at end of file} || [regexp {^\* Unmerged path } $line]} { From d2100860fd67dec6474157697888caaa0a0f51d0 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 8 Sep 2007 23:17:44 +0200 Subject: [PATCH 18/94] diff-delta.c: pack the index structure In normal use cases, the performance wins are not overly impressive: we get something like 5-10% due to the slightly better locality of memory accesses using the packed structure. However, since the data structure for index entries saves 33% of memory on 32-bit platforms and 40% on 64-bit platforms, the behavior when memory gets limited should be nicer. This is a rather well-contained change. One obvious improvement would be sorting the elements in one bucket according to their hash, then using binary probing to find the elements with the right hash value. As it stands, the output should be strictly the same as previously unless one uses the option for limiting the amount of used memory, in which case the created packs might be better. Signed-off-by: David Kastrup Acked-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- diff-delta.c | 74 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/diff-delta.c b/diff-delta.c index 0dde2f2dc0..7f8a60de18 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -115,7 +115,11 @@ static const unsigned int U[256] = { struct index_entry { const unsigned char *ptr; unsigned int val; - struct index_entry *next; +}; + +struct unpacked_index_entry { + struct index_entry entry; + struct unpacked_index_entry *next; }; struct delta_index { @@ -131,7 +135,8 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) unsigned int i, hsize, hmask, entries, prev_val, *hash_count; const unsigned char *data, *buffer = buf; struct delta_index *index; - struct index_entry *entry, **hash; + struct unpacked_index_entry *entry, **hash; + struct index_entry *packed_entry, **packed_hash; void *mem; unsigned long memsize; @@ -148,28 +153,21 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) hmask = hsize - 1; /* allocate lookup index */ - memsize = sizeof(*index) + - sizeof(*hash) * hsize + + memsize = sizeof(*hash) * hsize + sizeof(*entry) * entries; mem = malloc(memsize); if (!mem) return NULL; - index = mem; - mem = index + 1; hash = mem; mem = hash + hsize; entry = mem; - index->memsize = memsize; - index->src_buf = buf; - index->src_size = bufsize; - index->hash_mask = hmask; memset(hash, 0, hsize * sizeof(*hash)); /* allocate an array to count hash entries */ hash_count = calloc(hsize, sizeof(*hash_count)); if (!hash_count) { - free(index); + free(hash); return NULL; } @@ -183,12 +181,13 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) val = ((val << 8) | data[i]) ^ T[val >> RABIN_SHIFT]; if (val == prev_val) { /* keep the lowest of consecutive identical blocks */ - entry[-1].ptr = data + RABIN_WINDOW; + entry[-1].entry.ptr = data + RABIN_WINDOW; + --entries; } else { prev_val = val; i = val & hmask; - entry->ptr = data + RABIN_WINDOW; - entry->val = val; + entry->entry.ptr = data + RABIN_WINDOW; + entry->entry.val = val; entry->next = hash[i]; hash[i] = entry++; hash_count[i]++; @@ -212,16 +211,59 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) continue; entry = hash[i]; do { - struct index_entry *keep = entry; + struct unpacked_index_entry *keep = entry; int skip = hash_count[i] / HASH_LIMIT; do { + --entries; entry = entry->next; } while(--skip && entry); + ++entries; keep->next = entry; } while(entry); } free(hash_count); + /* Now create the packed index in array form rather than + * linked lists */ + + memsize = sizeof(*index) + + sizeof(*packed_hash) * (hsize+1) + + sizeof(*packed_entry) * entries; + + mem = malloc(memsize); + + if (!mem) { + free(hash); + return NULL; + } + + index = mem; + index->memsize = memsize; + index->src_buf = buf; + index->src_size = bufsize; + index->hash_mask = hmask; + + mem = index + 1; + packed_hash = mem; + mem = packed_hash + (hsize+1); + packed_entry = mem; + + /* Coalesce all entries belonging to one linked list into + * consecutive array entries */ + + for (i = 0; i < hsize; i++) { + packed_hash[i] = packed_entry; + for (entry = hash[i]; entry; entry = entry->next) + *packed_entry++ = entry->entry; + } + + /* Sentinel value to indicate the length of the last hash + * bucket */ + + packed_hash[hsize] = packed_entry; + assert(packed_entry - (struct index_entry *)mem == entries); + free(hash); + return index; } @@ -302,7 +344,7 @@ create_delta(const struct delta_index *index, val ^= U[data[-RABIN_WINDOW]]; val = ((val << 8) | *data) ^ T[val >> RABIN_SHIFT]; i = val & index->hash_mask; - for (entry = index->hash[i]; entry; entry = entry->next) { + for (entry = index->hash[i]; entry < index->hash[i+1]; entry++) { const unsigned char *ref = entry->ptr; const unsigned char *src = data; unsigned int ref_size = ref_top - ref; From 02e665ce491296245f474dafdc02d47a6c8afa86 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Sat, 8 Sep 2007 23:25:55 +0200 Subject: [PATCH 19/94] diff-delta.c: Rationalize culling of hash buckets The previous hash bucket culling resulted in a somewhat unpredictable number of hash bucket entries in the order of magnitude of HASH_LIMIT. Replace this with a Bresenham-like algorithm leaving us with exactly HASH_LIMIT entries by uniform culling. Signed-off-by: David Kastrup Acked-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- diff-delta.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/diff-delta.c b/diff-delta.c index 7f8a60de18..9e440a9299 100644 --- a/diff-delta.c +++ b/diff-delta.c @@ -207,19 +207,40 @@ struct delta_index * create_delta_index(const void *buf, unsigned long bufsize) * the reference buffer. */ for (i = 0; i < hsize; i++) { - if (hash_count[i] < HASH_LIMIT) + int acc; + + if (hash_count[i] <= HASH_LIMIT) continue; + + entries -= hash_count[i] - HASH_LIMIT; + /* We leave exactly HASH_LIMIT entries in the bucket */ + entry = hash[i]; + acc = 0; do { - struct unpacked_index_entry *keep = entry; - int skip = hash_count[i] / HASH_LIMIT; - do { - --entries; - entry = entry->next; - } while(--skip && entry); - ++entries; - keep->next = entry; - } while(entry); + acc += hash_count[i] - HASH_LIMIT; + if (acc > 0) { + struct unpacked_index_entry *keep = entry; + do { + entry = entry->next; + acc -= HASH_LIMIT; + } while (acc > 0); + keep->next = entry->next; + } + entry = entry->next; + } while (entry); + + /* Assume that this loop is gone through exactly + * HASH_LIMIT times and is entered and left with + * acc==0. So the first statement in the loop + * contributes (hash_count[i]-HASH_LIMIT)*HASH_LIMIT + * to the accumulator, and the inner loop consequently + * is run (hash_count[i]-HASH_LIMIT) times, removing + * one element from the list each time. Since acc + * balances out to 0 at the final run, the inner loop + * body can't be left with entry==NULL. So we indeed + * encounter entry==NULL in the outer loop only. + */ } free(hash_count); From 3b9dfde3d636aeb961318d41b3ab59f72414d010 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 9 Sep 2007 20:13:10 -0400 Subject: [PATCH 20/94] git-gui: Assume untracked directories are Git submodules If `git ls-files --others` returned us the name of a directory then it is because Git has decided that this directory itself contains a valid Git repository and its files shouldn't be listed as untracked for this repository. In such a case we should label the object as a Git repository and not just as a directory. Signed-off-by: Shawn O. Pearce --- lib/diff.tcl | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/diff.tcl b/lib/diff.tcl index a1d5e523d2..694834ab7a 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -84,17 +84,30 @@ proc show_diff {path w {lno {}}} { # if {$m eq {_O}} { set max_sz [expr {128 * 1024}] + set type unknown if {[catch { - if {[file type $path] == {link}} { + set type [file type $path] + switch -- $type { + directory { + set type submodule + set content {} + set sz 0 + } + link { set content [file readlink $path] set sz [string length $content] - } else { + } + file { set fd [open $path r] fconfigure $fd -eofchar {} set content [read $fd $max_sz] close $fd set sz [file size $path] } + default { + error "'$type' not supported" + } + } } err ]} { set diff_active 0 unlock_index @@ -103,7 +116,9 @@ proc show_diff {path w {lno {}}} { return } $ui_diff conf -state normal - if {![catch {set type [exec file $path]}]} { + if {$type eq {submodule}} { + $ui_diff insert end "* Git Repository (subproject)\n" d_@ + } elseif {![catch {set type [exec file $path]}]} { set n [string length $path] if {[string equal -length $n $path $type]} { set type [string range $type $n end] From 8938410189315979255c1dfcc3c0b7a4bf9953e5 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 9 Sep 2007 20:38:05 -0400 Subject: [PATCH 21/94] git-gui: Trim trailing slashes from untracked submodule names Oddly enough `git ls-files --others` supplies us the name of an untracked submodule by including the trailing slash but that same git version will not accept the name with a trailing slash through `git update-index --stdin`. Stripping off that final slash character before loading it into our file lists allows git-gui to stage changes to submodules just like any other file. This change should give git-gui users some basic submodule support, but it is strictly at the plumbing level as we do not actually know about calling the git-submodule porcelain that is a recent addition to git 1.5.3. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/git-gui.sh b/git-gui.sh index 6d676097a6..26eb5ac309 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -1010,7 +1010,11 @@ proc read_ls_others {fd after} { set pck [split $buf_rlo "\0"] set buf_rlo [lindex $pck end] foreach p [lrange $pck 0 end-1] { - merge_state [encoding convertfrom $p] ?O + set p [encoding convertfrom $p] + if {[string index $p end] eq {/}} { + set p [string range $p 0 end-1] + } + merge_state $p ?O } rescan_done $fd buf_rlo $after } From c2a33679a726aeb75529540c2b295f21023ddbc7 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 10 Sep 2007 00:06:09 -0400 Subject: [PATCH 22/94] threaded delta search: refine work allocation With this, each thread get repeatedly assigned the next available chunk of objects to process until the whole list is done. The idea is to have reasonably small chunks so that all CPUs remain busy with a minimum number of threads for as long as there is data to process. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 59 ++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 14 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 1bcee23ca1..60141196df 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1582,27 +1582,42 @@ struct thread_params { unsigned *processed; }; +static pthread_mutex_t data_request = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t data_ready = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t data_provider = PTHREAD_MUTEX_INITIALIZER; +static struct thread_params *data_requester; + static void *threaded_find_deltas(void *arg) { - struct thread_params *p = arg; - if (p->list_size) - find_deltas(p->list, p->list_size, - p->window, p->depth, p->processed); - return NULL; + struct thread_params *me = arg; + + for (;;) { + pthread_mutex_lock(&data_request); + data_requester = me; + pthread_mutex_unlock(&data_provider); + pthread_mutex_lock(&data_ready); + + if (!me->list_size) + return NULL; + + find_deltas(me->list, me->list_size, + me->window, me->depth, me->processed); + } } -#define NR_THREADS 8 +#define NR_THREADS 4 static void ll_find_deltas(struct object_entry **list, unsigned list_size, int window, int depth, unsigned *processed) { struct thread_params p[NR_THREADS]; int i, ret; + unsigned chunk_size; + + pthread_mutex_lock(&data_provider); + pthread_mutex_lock(&data_ready); for (i = 0; i < NR_THREADS; i++) { - unsigned sublist_size = list_size / (NR_THREADS - i); - p[i].list = list; - p[i].list_size = sublist_size; p[i].window = window; p[i].depth = depth; p[i].processed = processed; @@ -1610,13 +1625,29 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, threaded_find_deltas, &p[i]); if (ret) die("unable to create thread: %s", strerror(ret)); - list += sublist_size; - list_size -= sublist_size; } - for (i = 0; i < NR_THREADS; i++) { - pthread_join(p[i].thread, NULL); - } + /* this should be auto-tuned somehow */ + chunk_size = window * 1000; + + do { + unsigned sublist_size = chunk_size; + if (sublist_size > list_size) + sublist_size = list_size; + + pthread_mutex_lock(&data_provider); + data_requester->list = list; + data_requester->list_size = sublist_size; + pthread_mutex_unlock(&data_ready); + + list += sublist_size; + list_size -= sublist_size; + if (!sublist_size) { + pthread_join(data_requester->thread, NULL); + i--; + } + pthread_mutex_unlock(&data_request); + } while (i); } #else From 59921b4b3f24b19e2593085ee27d5e1f2448c6bb Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 10 Sep 2007 00:06:10 -0400 Subject: [PATCH 23/94] threaded delta search: better chunck split point Try to keep object with the same name hash together. Suggested by Martin Koegler. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 60141196df..b13558ee7e 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1635,6 +1635,11 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size, if (sublist_size > list_size) sublist_size = list_size; + /* try to split chunks on "path" boundaries */ + while (sublist_size < list_size && list[sublist_size]->hash && + list[sublist_size]->hash == list[sublist_size-1]->hash) + sublist_size++; + pthread_mutex_lock(&data_provider); data_requester->list = list; data_requester->list_size = sublist_size; From 367f4a4343d467ac76641362b102bc86da5cb584 Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 10 Sep 2007 00:06:11 -0400 Subject: [PATCH 24/94] threaded delta search: specify number of threads at run time This adds a --threads= parameter to 'git pack-objects' with documentation. Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- Documentation/git-pack-objects.txt | 8 ++++++++ builtin-pack-objects.c | 26 +++++++++++++++++++++----- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/Documentation/git-pack-objects.txt b/Documentation/git-pack-objects.txt index 6f17cff24a..f9b97956e3 100644 --- a/Documentation/git-pack-objects.txt +++ b/Documentation/git-pack-objects.txt @@ -173,6 +173,14 @@ base-name:: length, this option typically shrinks the resulting packfile by 3-5 per-cent. +--threads=:: + Specifies the number of threads to spawn when searching for best + delta matches. This requires that pack-objects be compiled with + pthreads otherwise this option is ignored with a warning. + This is meant to reduce packing time on multiprocessor machines. + The required amount of memory for the delta search window is + however multiplied by the number of threads. + --index-version=[,]:: This is intended to be used by the test suite only. It allows to force the version for the generated pack index, and to force diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b13558ee7e..42698d2948 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -24,7 +24,7 @@ git-pack-objects [{ -q | --progress | --all-progress }] \n\ [--max-pack-size=N] [--local] [--incremental] \n\ [--window=N] [--window-memory=N] [--depth=N] \n\ [--no-reuse-delta] [--no-reuse-object] [--delta-base-offset] \n\ - [--non-empty] [--revs [--unpacked | --all]*] [--reflog] \n\ + [--threads=N] [--non-empty] [--revs [--unpacked | --all]*] [--reflog] \n\ [--stdout | base-name] [ 1) + warning("no threads support, ignoring %s", k); +#endif + return 0; + } return git_default_config(k, v); } From 63c4024ff080430004967fa27b8af8fe243e2ea3 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Tue, 11 Sep 2007 13:37:45 -0400 Subject: [PATCH 27/94] git-gui: Don't delete send on Windows as it doesn't exist The Windows port of Tk does not have the send command so we cannot delete it from our global namespace, but the Mac OS X and X11 ports do have it. Switching this delete attempt into a catch makes send go away, or stay away. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-gui.sh b/git-gui.sh index 26eb5ac309..e221d5b511 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -42,7 +42,7 @@ if {[catch {package require Tcl 8.4} err] exit 1 } -rename send {} ; # What an evil concept... +catch {rename send {}} ; # What an evil concept... ###################################################################### ## From 060fe5718455828b2ce5721d26be6399d782e415 Mon Sep 17 00:00:00 2001 From: Ramsay Jones Date: Tue, 11 Sep 2007 19:16:51 +0100 Subject: [PATCH 28/94] Fix a test failure (t9500-*.sh) on cygwin On filesystems where it is appropriate to set core.filemode to false, test 29 ("commitdiff(0): mode change") fails when git-commit does not notice a file (execute) permission change. A fix requires noting the new file execute permission in the index with a "git update-index --chmod=+x", prior to the commit. Add a function (note_chmod) which implements this idea, and insert a call in each test that modifies the x permission. Signed-off-by: Ramsay Jones Signed-off-by: Junio C Hamano --- t/t9500-gitweb-standalone-no-errors.sh | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh index fa32598b0c..642b836d64 100755 --- a/t/t9500-gitweb-standalone-no-errors.sh +++ b/t/t9500-gitweb-standalone-no-errors.sh @@ -58,6 +58,14 @@ gitweb_run () { # gitweb.log is left for debugging } +safe_chmod () { + chmod "$1" "$2" && + if [ "$(git config --get core.filemode)" = false ] + then + git update-index --chmod="$1" "$2" + fi +} + . ./test-lib.sh perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || { @@ -229,7 +237,7 @@ test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): mode change' \ - 'chmod a+x new_file && + 'safe_chmod +x new_file && git commit -a -m "Mode changed." && gitweb_run "p=.git;a=commitdiff"' test_debug 'cat gitweb.log' @@ -268,7 +276,7 @@ test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): mode change and modified' \ 'echo "New line" >> file2 && - chmod a+x file2 && + safe_chmod +x file2 && git commit -a -m "Mode change and modification." && gitweb_run "p=.git;a=commitdiff"' test_debug 'cat gitweb.log' @@ -295,7 +303,7 @@ test_expect_success \ 'commitdiff(0): renamed, mode change and modified' \ 'git mv file3 file2 && echo "Propter nomen suum." >> file2 && - chmod a+x file2 && + safe_chmod +x file2 && git commit -a -m "File rename, mode change and modification." && gitweb_run "p=.git;a=commitdiff"' test_debug 'cat gitweb.log' @@ -412,10 +420,10 @@ test_expect_success \ git add 03-new && git mv 04-rename-from 04-rename-to && echo "Changed" >> 04-rename-to && - chmod a+x 05-mode-change && + safe_chmod +x 05-mode-change && rm -f 06-file-or-symlink && ln -s 01-change 06-file-or-symlink && echo "Changed and have mode changed" > 07-change-mode-change && - chmod a+x 07-change-mode-change && + safe_chmod +x 07-change-mode-change && git commit -a -m "Large commit" && git checkout master' From 3803bceae84fe122eccb49e3096abead508cde8f Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Wed, 12 Sep 2007 07:53:45 +0200 Subject: [PATCH 29/94] git-send-email.perl: Add angle brackets to In-Reply-To if necessary Although message-id by defintion should have surrounding angle brackets, there is no point forcing people to type them in. Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- git-send-email.perl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-send-email.perl b/git-send-email.perl index e0b7d1245e..195fe6f70a 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -317,7 +317,8 @@ if ($thread && !defined $initial_reply_to && $prompting) { } while (!defined $_); $initial_reply_to = $_; - $initial_reply_to =~ s/(^\s+|\s+$)//g; + $initial_reply_to =~ s/^\s+?\s+$/>/; } if (!$smtp_server) { From 4fb5fd5d301ee53882a3c2ed717c5a9fd6dc0506 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 12 Sep 2007 20:14:22 +0400 Subject: [PATCH 30/94] git-commit: Disallow amend if it is going to produce an empty non-merge commit Right now one can amend the last non-merge commit using a dirty index and in the process maybe cause the last commit to have the same tree as its parent. In such a case one would want to discard the last commit instead of amending it. This reverts commit 8588452ceb78b1da17652ba03f9942ef740e07ea. Signed-off-by: Dmitry V. Levin Signed-off-by: Junio C Hamano --- git-commit.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-commit.sh b/git-commit.sh index 1d04f1ff31..41538f16e5 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -554,7 +554,7 @@ else # we need to check if there is anything to commit run_status >/dev/null fi -if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" -a -z "$amend" ] +if [ "$?" != "0" -a ! -f "$GIT_DIR/MERGE_HEAD" ] then rm -f "$GIT_DIR/COMMIT_EDITMSG" "$GIT_DIR/SQUASH_MSG" use_status_color=t From 6143fa2c9cc74023bab3279764cd6158b1227359 Mon Sep 17 00:00:00 2001 From: Jean-Luc Herren Date: Wed, 12 Sep 2007 20:45:03 +0200 Subject: [PATCH 31/94] stash: end index commit log with a newline There was no newline at the end of the index commit message, putting the shell prompt at its end after a 'git cat-file commit $id'. This is similar to what was fixed in 843103d69388a5c74ed99753e1c162a66835b04d. Signed-off-by: Jean-Luc Herren Signed-off-by: Junio C Hamano --- git-stash.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-stash.sh b/git-stash.sh index 30425ce6df..7ba61625ba 100755 --- a/git-stash.sh +++ b/git-stash.sh @@ -57,7 +57,7 @@ save_stash () { # state of the index i_tree=$(git write-tree) && - i_commit=$(printf 'index on %s' "$msg" | + i_commit=$(printf 'index on %s\n' "$msg" | git commit-tree $i_tree -p $b_commit) || die "Cannot save the current index state" From 3c70183918d97eda06ae847cd7432fd23257caea Mon Sep 17 00:00:00 2001 From: Nicolas Pitre Date: Mon, 10 Sep 2007 11:10:11 -0400 Subject: [PATCH 32/94] threaded delta search: proper locking for cache accounting Signed-off-by: Nicolas Pitre Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index e091bcbda9..b126fc8e72 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1301,6 +1301,10 @@ static pthread_mutex_t read_mutex = PTHREAD_MUTEX_INITIALIZER; #define read_lock() pthread_mutex_lock(&read_mutex) #define read_unlock() pthread_mutex_unlock(&read_mutex) +static pthread_mutex_t cache_mutex = PTHREAD_MUTEX_INITIALIZER; +#define cache_lock() pthread_mutex_lock(&cache_mutex) +#define cache_unlock() pthread_mutex_unlock(&cache_mutex) + static pthread_mutex_t progress_mutex = PTHREAD_MUTEX_INITIALIZER; #define progress_lock() pthread_mutex_lock(&progress_mutex) #define progress_unlock() pthread_mutex_unlock(&progress_mutex) @@ -1309,6 +1313,8 @@ static pthread_mutex_t progress_mutex = PTHREAD_MUTEX_INITIALIZER; #define read_lock() 0 #define read_unlock() 0 +#define cache_lock() 0 +#define cache_unlock() 0 #define progress_lock() 0 #define progress_unlock() 0 @@ -1423,17 +1429,27 @@ static int try_delta(struct unpacked *trg, struct unpacked *src, trg_entry->delta_size = delta_size; trg->depth = src->depth + 1; + /* + * Handle memory allocation outside of the cache + * accounting lock. Compiler will optimize the strangeness + * away when THREADED_DELTA_SEARCH is not defined. + */ + if (trg_entry->delta_data) + free(trg_entry->delta_data); + cache_lock(); if (trg_entry->delta_data) { delta_cache_size -= trg_entry->delta_size; - free(trg_entry->delta_data); trg_entry->delta_data = NULL; } - if (delta_cacheable(src_size, trg_size, delta_size)) { - trg_entry->delta_data = xrealloc(delta_buf, delta_size); delta_cache_size += trg_entry->delta_size; - } else + cache_unlock(); + trg_entry->delta_data = xrealloc(delta_buf, delta_size); + } else { + cache_unlock(); free(delta_buf); + } + return 1; } From a2f22dbfa3a1039e5c6a9968d2421f1e9716515a Mon Sep 17 00:00:00 2001 From: Robert Boone Date: Mon, 10 Sep 2007 11:43:35 -0500 Subject: [PATCH 33/94] Define NO_MEMMEM of FreeBSD as it lacks the function Signed-off-by: Junio C Hamano --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 61053aed56..78cdaa155b 100644 --- a/Makefile +++ b/Makefile @@ -442,6 +442,7 @@ ifeq ($(uname_O),Cygwin) endif ifeq ($(uname_S),FreeBSD) NEEDS_LIBICONV = YesPlease + NO_MEMMEM = YesPlease BASIC_CFLAGS += -I/usr/local/include BASIC_LDFLAGS += -L/usr/local/lib endif From 359048d6ec296757266887a8ced5a927b97b94c1 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Tue, 11 Sep 2007 03:09:52 +0200 Subject: [PATCH 34/94] Add tests for documented features of "git reset". This adds the new file t/t7102-reset.sh following the text and examples in "Documentation/git-reset.txt" in order to check the behaviour of the upcoming "builtin-reset.c", and be able to compare it with the original "git-reset.sh". Signed-off-by: Carlos Rica Signed-off-by: Junio C Hamano --- t/t7102-reset.sh | 389 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 389 insertions(+) create mode 100755 t/t7102-reset.sh diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh new file mode 100755 index 0000000000..2cad4db127 --- /dev/null +++ b/t/t7102-reset.sh @@ -0,0 +1,389 @@ +#!/bin/sh +# +# Copyright (c) 2007 Carlos Rica +# + +test_description='git-reset + +Documented tests for git-reset' + +. ./test-lib.sh + +test_expect_success 'creating initial files and commits' ' + test_tick && + echo "1st file" >first && + git add first && + git commit -m "create 1st file" && + + echo "2nd file" >second && + git add second && + git commit -m "create 2nd file" && + + echo "2nd line 1st file" >>first && + git commit -a -m "modify 1st file" && + + git rm first && + git mv second secondfile && + git commit -a -m "remove 1st and rename 2nd" && + + echo "1st line 2nd file" >secondfile && + echo "2nd line 2nd file" >>secondfile && + git commit -a -m "modify 2nd file" +' +# git log --pretty=oneline # to see those SHA1 involved + +check_changes () { + test "$(git rev-parse HEAD)" = "$1" && + git diff | git diff .diff_expect - && + git diff --cached | git diff .cached_expect - && + for FILE in * + do + echo $FILE':' + cat $FILE || return + done | git diff .cat_expect - +} + +>.diff_expect +>.cached_expect +cat >.cat_expect <>secondfile && + git commit -a -m "change in branch1" && + + git checkout branch2 && + echo "3rd line in branch2" >>secondfile && + git commit -a -m "change in branch2" && + + ! git merge branch1 && + ! git reset --soft && + + printf "1st line 2nd file\n2nd line 2nd file\n3rd line" >secondfile && + git commit -a -m "the change in branch2" && + + git checkout master && + git branch -D branch1 branch2 && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc +' + +test_expect_success \ + 'trying to do reset --soft with pending checkout merge should fail' ' + git branch branch3 && + git branch branch4 && + + git checkout branch3 && + echo "3rd line in branch3" >>secondfile && + git commit -a -m "line in branch3" && + + git checkout branch4 && + echo "3rd line in branch4" >>secondfile && + + git checkout -m branch3 && + ! git reset --soft && + + printf "1st line 2nd file\n2nd line 2nd file\n3rd line" >secondfile && + git commit -a -m "the line in branch3" && + + git checkout master && + git branch -D branch3 branch4 && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc +' + +test_expect_success \ + 'resetting to HEAD with no changes should succeed and do nothing' ' + git reset --hard && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc + git reset --hard HEAD && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc + git reset --soft && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc + git reset --soft HEAD && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc + git reset --mixed && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc + git reset --mixed HEAD && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc + git reset && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc + git reset HEAD && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc +' + +>.diff_expect +cat >.cached_expect <.cat_expect <.diff_expect +>.cached_expect +cat >.cat_expect <>secondfile && + git commit -a -C ORIG_HEAD && + check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d && + test "$(git rev-parse ORIG_HEAD)" = \ + 3ec39651e7f44ea531a5de18a9fa791c0fd370fc +' + +>.diff_expect +>.cached_expect +cat >.cat_expect <.diff_expect +cat >.cached_expect <.cat_expect <secondfile && + echo "2nd line 2nd file" >>secondfile && + git add secondfile && + check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e +' + +cat >.diff_expect <.cached_expect +cat >.cat_expect <.diff_expect +>.cached_expect +cat >.cat_expect <secondfile && + echo "2nd line 2nd file" >>secondfile && + git commit -a -m "modify 2nd file" && + check_changes 3ec39651e7f44ea531a5de18a9fa791c0fd370fc +' + +>.diff_expect +>.cached_expect +cat >.cat_expect <>secondfile && + git commit -a -m "change in branch1" && + + git checkout branch2 && + echo "3rd line in branch2" >>secondfile && + git commit -a -m "change in branch2" && + + ! git pull . branch1 && + git reset --hard && + check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb +' + +>.diff_expect +>.cached_expect +cat >.cat_expect < expect << EOF +diff --git a/file1 b/file1 +index d00491f..7ed6ff8 100644 +--- a/file1 ++++ b/file1 +@@ -1 +1 @@ +-1 ++5 +diff --git a/file2 b/file2 +deleted file mode 100644 +index 0cfbf08..0000000 +--- a/file2 ++++ /dev/null +@@ -1 +0,0 @@ +-2 +EOF +cat > cached_expect << EOF +diff --git a/file4 b/file4 +new file mode 100644 +index 0000000..b8626c4 +--- /dev/null ++++ b/file4 +@@ -0,0 +1 @@ ++4 +EOF +test_expect_success 'test --mixed ' ' + echo 1 > file1 && + echo 2 > file2 && + git add file1 file2 && + test_tick && + git commit -m files && + git rm file2 && + echo 3 > file3 && + echo 4 > file4 && + echo 5 > file1 && + git add file1 file3 file4 && + ! git reset HEAD -- file1 file2 file3 && + git diff > output && + git diff output expect && + git diff --cached > output && + git diff output cached_expect +' + +test_done From 6640f88165f77edcc266a2c0c56fb017dc613198 Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Tue, 11 Sep 2007 05:17:28 +0200 Subject: [PATCH 35/94] Move make_cache_entry() from merge-recursive.c into read-cache.c The function make_cache_entry() is too useful to be hidden away in merge-recursive. So move it to libgit.a (exposing it via cache.h). Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- cache.h | 1 + merge-recursive.c | 24 ------------------------ read-cache.c | 25 +++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/cache.h b/cache.h index 493983cbae..8246500166 100644 --- a/cache.h +++ b/cache.h @@ -264,6 +264,7 @@ extern struct cache_entry *refresh_cache_entry(struct cache_entry *ce, int reall extern int remove_index_entry_at(struct index_state *, int pos); extern int remove_file_from_index(struct index_state *, const char *path); extern int add_file_to_index(struct index_state *, const char *path, int verbose); +extern struct cache_entry *make_cache_entry(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh); extern int ce_same_name(struct cache_entry *a, struct cache_entry *b); extern int ie_match_stat(struct index_state *, struct cache_entry *, struct stat *, int); extern int ie_modified(struct index_state *, struct cache_entry *, struct stat *, int); diff --git a/merge-recursive.c b/merge-recursive.c index 16f6a0f98b..19d5f3b287 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -171,30 +171,6 @@ static void output_commit_title(struct commit *commit) } } -static struct cache_entry *make_cache_entry(unsigned int mode, - const unsigned char *sha1, const char *path, int stage, int refresh) -{ - int size, len; - struct cache_entry *ce; - - if (!verify_path(path)) - return NULL; - - len = strlen(path); - size = cache_entry_size(len); - ce = xcalloc(1, size); - - hashcpy(ce->sha1, sha1); - memcpy(ce->name, path, len); - ce->ce_flags = create_ce_flags(len, stage); - ce->ce_mode = create_ce_mode(mode); - - if (refresh) - return refresh_cache_entry(ce, 0); - - return ce; -} - static int add_cacheinfo(unsigned int mode, const unsigned char *sha1, const char *path, int stage, int refresh, int options) { diff --git a/read-cache.c b/read-cache.c index 8b1c94e0e3..536f4d0875 100644 --- a/read-cache.c +++ b/read-cache.c @@ -434,6 +434,31 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose) return 0; } +struct cache_entry *make_cache_entry(unsigned int mode, + const unsigned char *sha1, const char *path, int stage, + int refresh) +{ + int size, len; + struct cache_entry *ce; + + if (!verify_path(path)) + return NULL; + + len = strlen(path); + size = cache_entry_size(len); + ce = xcalloc(1, size); + + hashcpy(ce->sha1, sha1); + memcpy(ce->name, path, len); + ce->ce_flags = create_ce_flags(len, stage); + ce->ce_mode = create_ce_mode(mode); + + if (refresh) + return refresh_cache_entry(ce, 0); + + return ce; +} + int ce_same_name(struct cache_entry *a, struct cache_entry *b) { int len = ce_namelen(a); From 0e5a7faa3a903cf7a0a66c81e20a76b91f17faab Mon Sep 17 00:00:00 2001 From: Carlos Rica Date: Tue, 11 Sep 2007 05:19:34 +0200 Subject: [PATCH 36/94] Make "git reset" a builtin. This replaces the script "git-reset.sh" with "builtin-reset.c". A few git commands used in the script are called from the builtin also: "ls-files" to check for unmerged files, "read-tree" for resetting the index file in "mixed" and "hard" resets, and "update-index" to refresh at the end in the "mixed" reset and also for the option that gets selected paths into the index. The reset option with paths was implemented by Johannes Schindelin. Since the option that gets selected paths into the index is not a "reset" like the others because it does not change the HEAD at all, now the command is showing a warning when the "--mixed" option is supplied for that purpose. The following table shows the behaviour of "git reset" for the different supported options, where X means "changing" the HEAD, index or working tree: reset: --soft --mixed --hard -- HEAD X X X - index - X X X files - - X - Signed-off-by: Carlos Rica Signed-off-by: Junio C Hamano --- Makefile | 3 +- builtin-reset.c | 279 ++++++++++++++++++ builtin.h | 1 + git-reset.sh => contrib/examples/git-reset.sh | 0 git.c | 1 + 5 files changed, 283 insertions(+), 1 deletion(-) create mode 100644 builtin-reset.c rename git-reset.sh => contrib/examples/git-reset.sh (100%) diff --git a/Makefile b/Makefile index 78cdaa155b..e6740fc392 100644 --- a/Makefile +++ b/Makefile @@ -208,7 +208,7 @@ SCRIPT_SH = \ git-ls-remote.sh \ git-merge-one-file.sh git-mergetool.sh git-parse-remote.sh \ git-pull.sh git-rebase.sh git-rebase--interactive.sh \ - git-repack.sh git-request-pull.sh git-reset.sh \ + git-repack.sh git-request-pull.sh \ git-sh-setup.sh \ git-am.sh \ git-merge.sh git-merge-stupid.sh git-merge-octopus.sh \ @@ -355,6 +355,7 @@ BUILTIN_OBJS = \ builtin-reflog.o \ builtin-config.o \ builtin-rerere.o \ + builtin-reset.o \ builtin-rev-list.o \ builtin-rev-parse.o \ builtin-revert.o \ diff --git a/builtin-reset.c b/builtin-reset.c new file mode 100644 index 0000000000..99d5c082a6 --- /dev/null +++ b/builtin-reset.c @@ -0,0 +1,279 @@ +/* + * "git reset" builtin command + * + * Copyright (c) 2007 Carlos Rica + * + * Based on git-reset.sh, which is + * + * Copyright (c) 2005, 2006 Linus Torvalds and Junio C Hamano + */ +#include "cache.h" +#include "tag.h" +#include "object.h" +#include "commit.h" +#include "run-command.h" +#include "refs.h" +#include "diff.h" +#include "diffcore.h" +#include "tree.h" + +static const char builtin_reset_usage[] = +"git-reset [--mixed | --soft | --hard] [] [ [--] ...]"; + +static char *args_to_str(const char **argv) +{ + char *buf = NULL; + unsigned long len, space = 0, nr = 0; + + for (; *argv; argv++) { + len = strlen(*argv); + ALLOC_GROW(buf, nr + 1 + len, space); + if (nr) + buf[nr++] = ' '; + memcpy(buf + nr, *argv, len); + nr += len; + } + ALLOC_GROW(buf, nr + 1, space); + buf[nr] = '\0'; + + return buf; +} + +static inline int is_merge(void) +{ + return !access(git_path("MERGE_HEAD"), F_OK); +} + +static int unmerged_files(void) +{ + char b; + ssize_t len; + struct child_process cmd; + const char *argv_ls_files[] = {"ls-files", "--unmerged", NULL}; + + memset(&cmd, 0, sizeof(cmd)); + cmd.argv = argv_ls_files; + cmd.git_cmd = 1; + cmd.out = -1; + + if (start_command(&cmd)) + die("Could not run sub-command: git ls-files"); + + len = xread(cmd.out, &b, 1); + if (len < 0) + die("Could not read output from git ls-files: %s", + strerror(errno)); + finish_command(&cmd); + + return len; +} + +static int reset_index_file(const unsigned char *sha1, int is_hard_reset) +{ + int i = 0; + const char *args[6]; + + args[i++] = "read-tree"; + args[i++] = "-v"; + args[i++] = "--reset"; + if (is_hard_reset) + args[i++] = "-u"; + args[i++] = sha1_to_hex(sha1); + args[i] = NULL; + + return run_command_v_opt(args, RUN_GIT_CMD); +} + +static void print_new_head_line(struct commit *commit) +{ + const char *hex, *dots = "...", *body; + + hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); + if (!hex) { + hex = sha1_to_hex(commit->object.sha1); + dots = ""; + } + printf("HEAD is now at %s%s", hex, dots); + body = strstr(commit->buffer, "\n\n"); + if (body) { + const char *eol; + size_t len; + body += 2; + eol = strchr(body, '\n'); + len = eol ? eol - body : strlen(body); + printf(" %.*s\n", (int) len, body); + } + else + printf("\n"); +} + +static int update_index_refresh(void) +{ + const char *argv_update_index[] = {"update-index", "--refresh", NULL}; + return run_command_v_opt(argv_update_index, RUN_GIT_CMD); +} + +static void update_index_from_diff(struct diff_queue_struct *q, + struct diff_options *opt, void *data) +{ + int i; + + /* do_diff_cache() mangled the index */ + discard_cache(); + read_cache(); + + for (i = 0; i < q->nr; i++) { + struct diff_filespec *one = q->queue[i]->one; + if (one->mode) { + struct cache_entry *ce; + ce = make_cache_entry(one->mode, one->sha1, one->path, + 0, 0); + add_cache_entry(ce, ADD_CACHE_OK_TO_ADD | + ADD_CACHE_OK_TO_REPLACE); + } else + remove_file_from_cache(one->path); + } +} + +static int read_from_tree(const char *prefix, const char **argv, + unsigned char *tree_sha1) +{ + struct lock_file *lock = xcalloc(1, sizeof(struct lock_file)); + int index_fd; + struct diff_options opt; + + memset(&opt, 0, sizeof(opt)); + diff_tree_setup_paths(get_pathspec(prefix, (const char **)argv), &opt); + opt.output_format = DIFF_FORMAT_CALLBACK; + opt.format_callback = update_index_from_diff; + + index_fd = hold_locked_index(lock, 1); + read_cache(); + if (do_diff_cache(tree_sha1, &opt)) + return 1; + diffcore_std(&opt); + diff_flush(&opt); + return write_cache(index_fd, active_cache, active_nr) || + close(index_fd) || + commit_locked_index(lock); +} + +static void prepend_reflog_action(const char *action, char *buf, size_t size) +{ + const char *sep = ": "; + const char *rla = getenv("GIT_REFLOG_ACTION"); + if (!rla) + rla = sep = ""; + if (snprintf(buf, size, "%s%s%s", rla, sep, action) >= size) + warning("Reflog action message too long: %.*s...", 50, buf); +} + +enum reset_type { MIXED, SOFT, HARD, NONE }; +static char *reset_type_names[] = { "mixed", "soft", "hard", NULL }; + +int cmd_reset(int argc, const char **argv, const char *prefix) +{ + int i = 1, reset_type = NONE, update_ref_status = 0; + const char *rev = "HEAD"; + unsigned char sha1[20], *orig = NULL, sha1_orig[20], + *old_orig = NULL, sha1_old_orig[20]; + struct commit *commit; + char *reflog_action, msg[1024]; + + git_config(git_default_config); + + reflog_action = args_to_str(argv); + setenv("GIT_REFLOG_ACTION", reflog_action, 0); + + if (i < argc) { + if (!strcmp(argv[i], "--mixed")) { + reset_type = MIXED; + i++; + } + else if (!strcmp(argv[i], "--soft")) { + reset_type = SOFT; + i++; + } + else if (!strcmp(argv[i], "--hard")) { + reset_type = HARD; + i++; + } + } + + if (i < argc && argv[i][0] != '-') + rev = argv[i++]; + + if (get_sha1(rev, sha1)) + die("Failed to resolve '%s' as a valid ref.", rev); + + commit = lookup_commit_reference(sha1); + if (!commit) + die("Could not parse object '%s'.", rev); + hashcpy(sha1, commit->object.sha1); + + if (i < argc && !strcmp(argv[i], "--")) + i++; + else if (i < argc && argv[i][0] == '-') + usage(builtin_reset_usage); + + /* git reset tree [--] paths... can be used to + * load chosen paths from the tree into the index without + * affecting the working tree nor HEAD. */ + if (i < argc) { + if (reset_type == MIXED) + warning("--mixed option is deprecated with paths."); + else if (reset_type != NONE) + die("Cannot do %s reset with paths.", + reset_type_names[reset_type]); + if (read_from_tree(prefix, argv + i, sha1)) + return 1; + return update_index_refresh() ? 1 : 0; + } + if (reset_type == NONE) + reset_type = MIXED; /* by default */ + + /* Soft reset does not touch the index file nor the working tree + * at all, but requires them in a good order. Other resets reset + * the index file to the tree object we are switching to. */ + if (reset_type == SOFT) { + if (is_merge() || unmerged_files()) + die("Cannot do a soft reset in the middle of a merge."); + } + else if (reset_index_file(sha1, (reset_type == HARD))) + die("Could not reset index file to revision '%s'.", rev); + + /* Any resets update HEAD to the head being switched to, + * saving the previous head in ORIG_HEAD before. */ + if (!get_sha1("ORIG_HEAD", sha1_old_orig)) + old_orig = sha1_old_orig; + if (!get_sha1("HEAD", sha1_orig)) { + orig = sha1_orig; + prepend_reflog_action("updating ORIG_HEAD", msg, sizeof(msg)); + update_ref(msg, "ORIG_HEAD", orig, old_orig, 0, MSG_ON_ERR); + } + else if (old_orig) + delete_ref("ORIG_HEAD", old_orig); + prepend_reflog_action("updating HEAD", msg, sizeof(msg)); + update_ref_status = update_ref(msg, "HEAD", sha1, orig, 0, MSG_ON_ERR); + + switch (reset_type) { + case HARD: + if (!update_ref_status) + print_new_head_line(commit); + break; + case SOFT: /* Nothing else to do. */ + break; + case MIXED: /* Report what has not been updated. */ + update_index_refresh(); + break; + } + + unlink(git_path("MERGE_HEAD")); + unlink(git_path("rr-cache/MERGE_RR")); + unlink(git_path("MERGE_MSG")); + unlink(git_path("SQUASH_MSG")); + + free(reflog_action); + + return update_ref_status; +} diff --git a/builtin.h b/builtin.h index bb720004af..03ee7bf780 100644 --- a/builtin.h +++ b/builtin.h @@ -60,6 +60,7 @@ extern int cmd_read_tree(int argc, const char **argv, const char *prefix); extern int cmd_reflog(int argc, const char **argv, const char *prefix); extern int cmd_config(int argc, const char **argv, const char *prefix); extern int cmd_rerere(int argc, const char **argv, const char *prefix); +extern int cmd_reset(int argc, const char **argv, const char *prefix); extern int cmd_rev_list(int argc, const char **argv, const char *prefix); extern int cmd_rev_parse(int argc, const char **argv, const char *prefix); extern int cmd_revert(int argc, const char **argv, const char *prefix); diff --git a/git-reset.sh b/contrib/examples/git-reset.sh similarity index 100% rename from git-reset.sh rename to contrib/examples/git-reset.sh diff --git a/git.c b/git.c index fd3d83cd4c..56ae8ccccf 100644 --- a/git.c +++ b/git.c @@ -364,6 +364,7 @@ static void handle_internal_command(int argc, const char **argv) { "reflog", cmd_reflog, RUN_SETUP }, { "repo-config", cmd_config }, { "rerere", cmd_rerere, RUN_SETUP }, + { "reset", cmd_reset, RUN_SETUP }, { "rev-list", cmd_rev_list, RUN_SETUP }, { "rev-parse", cmd_rev_parse, RUN_SETUP }, { "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE }, From 80bffaf7fbe09ef62ecb9a6ffea70ac0171b456c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Sep 2007 16:04:22 -0700 Subject: [PATCH 37/94] git-commit: Allow partial commit of file removal. When making a partial commit, git-commit uses git-ls-files with the --error-unmatch option to expand and sanity check the user supplied path patterns. When any path pattern does not match with the paths known to the index, it errors out, in order to catch a common mistake to say "git commit Makefiel cache.h" and end up with a commit that touches only cache.h (notice the misspelled "Makefile"). This detection however does not work well when the path has already been removed from the index. If you drop a path from the index and try to commit that partially, i.e. $ git rm COPYING $ git commit -m 'Remove COPYING' COPYING the command complains because git does not know anything about COPYING anymore. This introduces a new option --with-tree to git-ls-files and uses it in git-commit when we build a temporary index to write a tree object for the partial commit. When --with-tree= option is specified, names from the given tree are added to the set of names the index knows about, so we can treat COPYING file in the example as known. Of course, there is no reason to use "git rm" and git-aware people have long time done: $ rm COPYING $ git commit -m 'Remove COPYING' COPYING which works just fine. But this caused a constant confusion. Signed-off-by: Junio C Hamano --- builtin-ls-files.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ git-commit.sh | 5 ++- t/t7501-commit.sh | 21 +++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/builtin-ls-files.c b/builtin-ls-files.c index cce17b5ced..6c1db86e80 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -9,6 +9,7 @@ #include "quote.h" #include "dir.h" #include "builtin.h" +#include "tree.h" static int abbrev; static int show_deleted; @@ -26,6 +27,7 @@ static int prefix_offset; static const char **pathspec; static int error_unmatch; static char *ps_matched; +static const char *with_tree; static const char *tag_cached = ""; static const char *tag_unmerged = ""; @@ -247,6 +249,8 @@ static void show_files(struct dir_struct *dir, const char *prefix) continue; if (show_unmerged && !ce_stage(ce)) continue; + if (ce->ce_flags & htons(CE_UPDATE)) + continue; show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce); } } @@ -332,6 +336,67 @@ static const char *verify_pathspec(const char *prefix) return real_prefix; } +/* + * Read the tree specified with --with-tree option + * (typically, HEAD) into stage #1 and then + * squash them down to stage #0. This is used for + * --error-unmatch to list and check the path patterns + * that were given from the command line. We are not + * going to write this index out. + */ +static void overlay_tree(const char *tree_name, const char *prefix) +{ + struct tree *tree; + unsigned char sha1[20]; + const char **match; + struct cache_entry *last_stage0 = NULL; + int i; + + if (get_sha1(tree_name, sha1)) + die("tree-ish %s not found.", tree_name); + tree = parse_tree_indirect(sha1); + if (!tree) + die("bad tree-ish %s", tree_name); + + /* Hoist the unmerged entries up to stage #3 to make room */ + for (i = 0; i < active_nr; i++) { + struct cache_entry *ce = active_cache[i]; + if (!ce_stage(ce)) + continue; + ce->ce_flags |= htons(CE_STAGEMASK); + } + + if (prefix) { + static const char *(matchbuf[2]); + matchbuf[0] = prefix; + matchbuf [1] = NULL; + match = matchbuf; + } else + match = NULL; + if (read_tree(tree, 1, match)) + die("unable to read tree entries %s", tree_name); + + for (i = 0; i < active_nr; i++) { + struct cache_entry *ce = active_cache[i]; + switch (ce_stage(ce)) { + case 0: + last_stage0 = ce; + /* fallthru */ + default: + continue; + case 1: + /* + * If there is stage #0 entry for this, we do not + * need to show it. We use CE_UPDATE bit to mark + * such an entry. + */ + if (last_stage0 && + !strcmp(last_stage0->name, ce->name)) + ce->ce_flags |= htons(CE_UPDATE); + } + } +} + static const char ls_files_usage[] = "git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* " "[ --ignored ] [--exclude=] [--exclude-from=] " @@ -452,6 +517,10 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) error_unmatch = 1; continue; } + if (!prefixcmp(arg, "--with-tree=")) { + with_tree = arg + 12; + continue; + } if (!prefixcmp(arg, "--abbrev=")) { abbrev = strtoul(arg+9, NULL, 10); if (abbrev && abbrev < MINIMUM_ABBREV) @@ -503,6 +572,15 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) read_cache(); if (prefix) prune_cache(prefix); + if (with_tree) { + /* + * Basic sanity check; show-stages and show-unmerged + * would not make any sense with this option. + */ + if (show_stage || show_unmerged) + die("ls-files --with-tree is incompatible with -s or -u"); + overlay_tree(with_tree, prefix); + } show_files(&dir, prefix); if (ps_matched) { diff --git a/git-commit.sh b/git-commit.sh index 41538f16e5..5ea3fd0076 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -379,8 +379,11 @@ t,) then refuse_partial "Cannot do a partial commit during a merge." fi + TMP_INDEX="$GIT_DIR/tmp-index$$" - commit_only=`git ls-files --error-unmatch -- "$@"` || exit + W= + test -z "$initial_commit" && W=--with-tree=HEAD + commit_only=`git ls-files --error-unmatch $W -- "$@"` || exit # Build a temporary index and update the real index # the same way. diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 6bd3c9e3e0..f178f56208 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -131,4 +131,25 @@ test_expect_success \ 'validate git-rev-list output.' \ 'diff current expected' +test_expect_success 'partial commit that involve removal (1)' ' + + git rm --cached file && + mv file elif && + git add elif && + git commit -m "Partial: add elif" elif && + git diff-tree --name-status HEAD^ HEAD >current && + echo "A elif" >expected && + diff expected current + +' + +test_expect_success 'partial commit that involve removal (2)' ' + + git commit -m "Partial: remove file" file && + git diff-tree --name-status HEAD^ HEAD >current && + echo "D file" >expected && + diff expected current + +' + test_done From e7034d66ecd9c16ae8bd8d331fc41efc48e925f1 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:04:14 -0400 Subject: [PATCH 38/94] git-gui: Make backporting changes from i18n version easier This is a very trivial hack to define a global mc procedure that does not actually perform i18n translations on its input strings. By declaring an mc procedure here in our maint version of git-gui we can take patches that are intended for the latest development version of git-gui and easily backport them without needing to tweak the mc calls first. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git-gui.sh b/git-gui.sh index e221d5b511..31a36cb49f 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -62,6 +62,18 @@ if {![catch {set _verbose $env(GITGUI_VERBOSE)}]} { } } +###################################################################### +## +## Fake internationalization to ease backporting of changes. + +proc mc {fmt args} { + set cmk [string first @@ $fmt] + if {$cmk > 0} { + set fmt [string range $fmt 0 [expr {$cmk - 1}]] + } + return [eval [list format $fmt] $args] +} + ###################################################################### ## ## read only globals From afe2098ddd3e21d1d1afc428d3c8d91f37b01692 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:07:46 -0400 Subject: [PATCH 39/94] git-gui: Font chooser to handle a large number of font families Simon Sasburg noticed that on X11 if there are more fonts than can fit in the height of the screen Tk's native tk_optionMenu does not offer scroll arrows to the user and it is not possible to review all choices or to select those that are off-screen. On Mac OS X the tk_optionMenu works properly but is awkward to navigate if the list is long. This is a rewrite of our font selection by providing a new modal dialog that the user can launch from the git-gui Options panel. The dialog offers the user a scrolling list of fonts in a pane. An example text shows the user what the font looks like at the size they have selected. But I have to admit the example pane is less than ideal. For example in the case of our diff font we really should show the user an example diff complete with our native diff syntax coloring. Signed-off-by: Shawn O. Pearce Acked-by: Simon Sasburg --- lib/choose_font.tcl | 165 ++++++++++++++++++++++++++++++++++++++++++++ lib/option.tcl | 28 +++++--- 2 files changed, 182 insertions(+), 11 deletions(-) create mode 100644 lib/choose_font.tcl diff --git a/lib/choose_font.tcl b/lib/choose_font.tcl new file mode 100644 index 0000000000..b69215c91e --- /dev/null +++ b/lib/choose_font.tcl @@ -0,0 +1,165 @@ +# git-gui font chooser +# Copyright (C) 2007 Shawn Pearce + +class choose_font { + +field w +field w_family ; # UI widget of all known family names +field w_example ; # Example to showcase the chosen font + +field f_family ; # Currently chosen family name +field f_size ; # Currently chosen point size + +field v_family ; # Name of global variable for family +field v_size ; # Name of global variable for size + +variable all_families [list] ; # All fonts known to Tk + +constructor pick {path title a_family a_size} { + variable all_families + + set v_family $a_family + set v_size $a_size + + upvar #0 $v_family pv_family + upvar #0 $v_size pv_size + + set f_family $pv_family + set f_size $pv_size + + make_toplevel top w + wm title $top "[appname] ([reponame]): $title" + wm geometry $top "+[winfo rootx $path]+[winfo rooty $path]" + + label $w.header -text $title -font font_uibold + pack $w.header -side top -fill x + + frame $w.buttons + button $w.buttons.select \ + -text [mc Select] \ + -default active \ + -command [cb _select] + button $w.buttons.cancel \ + -text [mc Cancel] \ + -command [list destroy $w] + pack $w.buttons.select -side right + pack $w.buttons.cancel -side right -padx 5 + pack $w.buttons -side bottom -fill x -pady 10 -padx 10 + + frame $w.inner + + frame $w.inner.family + label $w.inner.family.l \ + -text [mc "Font Family"] \ + -anchor w + set w_family $w.inner.family.v + text $w_family \ + -background white \ + -borderwidth 1 \ + -relief sunken \ + -cursor $::cursor_ptr \ + -wrap none \ + -width 30 \ + -height 10 \ + -yscrollcommand [list $w.inner.family.sby set] + scrollbar $w.inner.family.sby -command [list $w_family yview] + pack $w.inner.family.l -side top -fill x + pack $w.inner.family.sby -side right -fill y + pack $w_family -fill both -expand 1 + + frame $w.inner.size + label $w.inner.size.l \ + -text [mc "Font Size"] \ + -anchor w + spinbox $w.inner.size.v \ + -textvariable @f_size \ + -from 2 -to 80 -increment 1 \ + -width 3 + bind $w.inner.size.v {%W selection range 0 end} + pack $w.inner.size.l -fill x -side top + pack $w.inner.size.v -fill x -padx 2 + + grid configure $w.inner.family $w.inner.size -sticky nsew + grid rowconfigure $w.inner 0 -weight 1 + grid columnconfigure $w.inner 0 -weight 1 + pack $w.inner -fill both -expand 1 -padx 5 -pady 5 + + frame $w.example + label $w.example.l \ + -text [mc "Font Example"] \ + -anchor w + set w_example $w.example.t + text $w_example \ + -background white \ + -borderwidth 1 \ + -relief sunken \ + -height 3 \ + -width 40 + $w_example tag conf example -justify center + $w_example insert end [mc "This is example text.\nIf you like this text, it can be your font."] example + $w_example conf -state disabled + pack $w.example.l -fill x + pack $w_example -fill x + pack $w.example -fill x -padx 5 + + if {$all_families eq {}} { + set all_families [lsort [font families]] + } + + $w_family tag conf pick + $w_family tag bind pick [cb _pick_family %x %y]\;break + $w_family tag conf cpck -background lightgray + foreach f $all_families { + set sel [list pick] + if {$f eq $f_family} { + lappend sel cpck + } + $w_family insert end "$f\n" $sel + } + $w_family conf -state disabled + _update $this + + trace add variable @f_size write [cb _update] + bind $w [list destroy $w] + bind $w [cb _select]\;break + bind $w " + grab $w + focus $w + " + tkwait window $w +} + +method _select {} { + upvar #0 $v_family pv_family + upvar #0 $v_size pv_size + + set pv_family $f_family + set pv_size $f_size + + destroy $w +} + +method _pick_family {x y} { + variable all_families + + set i [lindex [split [$w_family index @$x,$y] .] 0] + set n [lindex $all_families [expr {$i - 1}]] + if {$n ne {}} { + $w_family tag remove cpck 0.0 end + $w_family tag add cpck $i.0 [expr {$i + 1}].0 + set f_family $n + _update $this + } +} + +method _update {args} { + variable all_families + + set i [lsearch -exact $all_families $f_family] + if {$i < 0} return + + $w_example tag conf example -font [list $f_family $f_size] + $w_family see [expr {$i + 1}].0 +} + +} diff --git a/lib/option.tcl b/lib/option.tcl index aa9f783afd..063f5df6f7 100644 --- a/lib/option.tcl +++ b/lib/option.tcl @@ -255,17 +255,23 @@ proc do_options {} { frame $w.global.$name label $w.global.$name.l -text "$text:" - pack $w.global.$name.l -side left -anchor w -fill x - eval tk_optionMenu $w.global.$name.family \ - global_config_new(gui.$font^^family) \ - $all_fonts - spinbox $w.global.$name.size \ - -textvariable global_config_new(gui.$font^^size) \ - -from 2 -to 80 -increment 1 \ - -width 3 - bind $w.global.$name.size {%W selection range 0 end} - pack $w.global.$name.size -side right -anchor e - pack $w.global.$name.family -side right -anchor e + button $w.global.$name.b \ + -text [mc "Change Font"] \ + -command [list \ + choose_font::pick \ + $w \ + [mc "Choose %s" $text] \ + global_config_new(gui.$font^^family) \ + global_config_new(gui.$font^^size) \ + ] + label $w.global.$name.f -textvariable global_config_new(gui.$font^^family) + label $w.global.$name.s -textvariable global_config_new(gui.$font^^size) + label $w.global.$name.pt -text [mc "pt."] + pack $w.global.$name.l -side left -anchor w + pack $w.global.$name.b -side right -anchor e + pack $w.global.$name.pt -side right -anchor w + pack $w.global.$name.s -side right -anchor w + pack $w.global.$name.f -side right -anchor w pack $w.global.$name -side top -anchor w -fill x } From 042f53c569c92b40e63c6993c8998d2aac22e383 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 19:50:35 -0400 Subject: [PATCH 40/94] git-gui: Provide 'uninstall' Makefile target to undo an installation Several users have requested a "make uninstall" target be provided in the stock git-gui Makefile so that they can undo an install if git-gui goes to the wrong place during the initial install, or if they are unhappy with the tool and want to remove it from their system. We currently assume that the complete set of files we need to delete are those defined by our Makefile and current source directory. This could differ from what the user actually has installed if they installed one version then attempt to use another to perform the uninstall. Right now I'm just going to say that is "pilot error". Users should uninstall git-gui using the same version of source that they used to make the installation. Perhaps in the future we could read tclIndex and base our uninstall decisions on its contents. Signed-off-by: Shawn O. Pearce --- Makefile | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f11cf26760..18e6750137 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,9 @@ ifndef INSTALL INSTALL = install endif +RM_F ?= rm -f +RMDIR ?= rmdir + INSTALL_D0 = $(INSTALL) -d -m755 # space is required here INSTALL_D1 = INSTALL_R0 = $(INSTALL) -m644 # space is required here @@ -42,6 +45,12 @@ INSTALL_L1 = && ln # space is required here INSTALL_L2 = INSTALL_L3 = +REMOVE_D0 = $(RMDIR) # space is required here +REMOVE_D1 = || true +REMOVE_F0 = $(RM_F) # space is required here +REMOVE_F1 = +CLEAN_DST = true + ifndef V QUIET = @ QUIET_GEN = $(QUIET)echo ' ' GEN $@ && @@ -60,6 +69,12 @@ ifndef V INSTALL_L1 = && src= INSTALL_L2 = && dst= INSTALL_L3 = && echo ' ' 'LINK ' `basename "$$dst"` '->' `basename "$$src"` && rm -f "$$dst" && ln "$$src" "$$dst" + + CLEAN_DST = echo ' ' UNINSTALL + REMOVE_D0 = dir= + REMOVE_D1 = && echo ' ' REMOVE $$dir && test -d "$$dir" && $(RMDIR) "$$dir" || true + REMOVE_F0 = dst= + REMOVE_F1 = && echo ' ' REMOVE `basename "$$dst"` && $(RM_F) "$$dst" endif TCL_PATH ?= tclsh @@ -146,6 +161,17 @@ install: all $(QUIET)$(INSTALL_R0)lib/tclIndex $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)' $(QUIET)$(foreach p,$(ALL_LIBFILES), $(INSTALL_R0)$p $(INSTALL_R1) '$(DESTDIR_SQ)$(libdir_SQ)' &&) true +uninstall: + $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(gitexecdir_SQ)' + $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/git-gui $(REMOVE_F1) + $(QUIET)$(foreach p,$(GITGUI_BUILT_INS), $(REMOVE_F0)'$(DESTDIR_SQ)$(gitexecdir_SQ)'/$p $(REMOVE_F1) &&) true + $(QUIET)$(CLEAN_DST) '$(DESTDIR_SQ)$(libdir_SQ)' + $(QUIET)$(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/tclIndex $(REMOVE_F1) + $(QUIET)$(foreach p,$(ALL_LIBFILES), $(REMOVE_F0)'$(DESTDIR_SQ)$(libdir_SQ)'/$(notdir $p) $(REMOVE_F1) &&) true + $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(gitexecdir_SQ)' $(REMOVE_D1) + $(QUIET)$(REMOVE_D0)'$(DESTDIR_SQ)$(libdir_SQ)' $(REMOVE_D1) + $(QUIET)$(REMOVE_D0)`dirname '$(DESTDIR_SQ)$(libdir_SQ)'` $(REMOVE_D1) + dist-version: @mkdir -p $(TARDIR) @echo $(GITGUI_VERSION) > $(TARDIR)/version @@ -154,6 +180,6 @@ clean:: rm -f $(ALL_PROGRAMS) lib/tclIndex rm -f GIT-VERSION-FILE GIT-GUI-VARS -.PHONY: all install dist-version clean +.PHONY: all install uninstall dist-version clean .PHONY: .FORCE-GIT-VERSION-FILE .PHONY: .FORCE-GIT-GUI-VARS From 55bad4f096b1f18eec94169c864c39bf0abda1db Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Thu, 13 Sep 2007 20:08:53 -0400 Subject: [PATCH 41/94] git-gui: Paper bag fix "Commit->Revert" format arguments The recent bug fix to correctly handle filenames with %s (or any other valid Tcl format specifier) missed a \ on this line and caused the remaining format arguments to not be supplied when we updated the status bar. This caused a Tcl error anytime the user was trying to perform a file revert. Signed-off-by: Shawn O. Pearce --- lib/index.tcl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.tcl b/lib/index.tcl index cbbce13a77..44689ab63b 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -168,7 +168,7 @@ proc checkout_index {msg pathList after} { ui_status [format \ "%s... %i/%i files (%.2f%%)" \ - $msg + $msg \ $update_index_cp \ $totalCnt \ 0.0] From cbb390cd8f58ca6fc5c7b2c710425649b057b6d6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 13 Sep 2007 20:54:14 -0700 Subject: [PATCH 42/94] An additional test for "git-reset -- path" Signed-off-by: Junio C Hamano --- t/t7102-reset.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 2cad4db127..f64b1cbf75 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -386,4 +386,20 @@ test_expect_success 'test --mixed ' ' git diff output cached_expect ' +test_expect_success 'test resetting the index at give paths' ' + + mkdir sub && + >sub/file1 && + >sub/file2 && + git update-index --add sub/file1 sub/file2 && + T=$(git write-tree) && + ! git reset HEAD sub/file2 && + U=$(git write-tree) && + echo "$T" && + echo "$U" && + ! git diff-index --cached --exit-code "$T" && + test "$T" != "$U" + +' + test_done From c32da692de332d3c9a0b283066e3786af00f4931 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 12 Sep 2007 23:36:03 +0200 Subject: [PATCH 43/94] hooks--update: Explicitly check for all zeros for a deleted ref. The previous check caused the hook to reject as unannotated any tag whose SHA1 starts with a zero. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- templates/hooks--update | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/hooks--update b/templates/hooks--update index 9d3795c6d0..d8c76264be 100644 --- a/templates/hooks--update +++ b/templates/hooks--update @@ -42,7 +42,7 @@ fi # --- Check types # if $newrev is 0000...0000, it's a commit to delete a branch -if [ -z "${newrev##0*}" ]; then +if [ "$newrev" = "0000000000000000000000000000000000000000" ]; then newrev_type=commit else newrev_type=$(git-cat-file -t $newrev) From 1b655040bec1ff2f44fe309ac0f26085ed6372e9 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 13 Sep 2007 11:49:40 +0200 Subject: [PATCH 44/94] git.el: Keep the status buffer sorted by filename. This makes insertions and updates much more efficient. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 103 +++++++++++++++++++++++++++---------------- 1 file changed, 65 insertions(+), 38 deletions(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index 280557ecd4..b5d7c0664e 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -479,6 +479,27 @@ and returns the process output as a string." (setf (git-fileinfo->orig-name info) nil) (setf (git-fileinfo->needs-refresh info) t)))) +(defun git-set-filenames-state (status files state) + "Set the state of a list of named files." + (when files + (setq files (sort files #'string-lessp)) + (let ((file (pop files)) + (node (ewoc-nth status 0))) + (while (and file node) + (let ((info (ewoc-data node))) + (cond ((string-lessp (git-fileinfo->name info) file) + (setq node (ewoc-next status node))) + ((string-equal (git-fileinfo->name info) file) + (unless (eq (git-fileinfo->state info) state) + (setf (git-fileinfo->state info) state) + (setf (git-fileinfo->rename-state info) nil) + (setf (git-fileinfo->orig-name info) nil) + (setf (git-fileinfo->needs-refresh info) t)) + (setq file (pop files))) + (t (setq file (pop files))))))) + (unless state ;; delete files whose state has been set to nil + (ewoc-filter status (lambda (info) (git-fileinfo->state info)))))) + (defun git-state-code (code) "Convert from a string to a added/deleted/modified state." (case (string-to-char code) @@ -532,19 +553,36 @@ and returns the process output as a string." " " (git-escape-file-name (git-fileinfo->name info)) (git-rename-as-string info)))) -(defun git-insert-fileinfo (status info &optional refresh) - "Insert INFO in the status buffer, optionally refreshing an existing one." - (let ((node (and refresh - (git-find-status-file status (git-fileinfo->name info))))) - (setf (git-fileinfo->needs-refresh info) t) - (when node ;preserve the marked flag - (setf (git-fileinfo->marked info) (git-fileinfo->marked (ewoc-data node)))) - (if node (setf (ewoc-data node) info) (ewoc-enter-last status info)))) +(defun git-insert-info-list (status infolist) + "Insert a list of file infos in the status buffer, replacing existing ones if any." + (setq infolist (sort infolist + (lambda (info1 info2) + (string-lessp (git-fileinfo->name info1) + (git-fileinfo->name info2))))) + (let ((info (pop infolist)) + (node (ewoc-nth status 0))) + (while info + (setf (git-fileinfo->needs-refresh info) t) + (cond ((not node) + (ewoc-enter-last status info) + (setq info (pop infolist))) + ((string-lessp (git-fileinfo->name (ewoc-data node)) + (git-fileinfo->name info)) + (setq node (ewoc-next status node))) + ((string-equal (git-fileinfo->name (ewoc-data node)) + (git-fileinfo->name info)) + ;; preserve the marked flag + (setf (git-fileinfo->marked info) (git-fileinfo->marked (ewoc-data node))) + (setf (ewoc-data node) info) + (setq info (pop infolist))) + (t + (ewoc-enter-before status node info) + (setq info (pop infolist))))))) (defun git-run-diff-index (status files) "Run git-diff-index on FILES and parse the results into STATUS. Return the list of files that haven't been handled." - (let ((refresh files)) + (let (infolist) (with-temp-buffer (apply #'git-run-command t nil "diff-index" "-z" "-M" "HEAD" "--" files) (goto-char (point-min)) @@ -558,13 +596,14 @@ Return the list of files that haven't been handled." (new-name (match-string 8))) (if new-name ; copy or rename (if (eq ?C (string-to-char state)) - (git-insert-fileinfo status (git-create-fileinfo 'added new-name old-perm new-perm 'copy name) refresh) - (git-insert-fileinfo status (git-create-fileinfo 'deleted name 0 0 'rename new-name) refresh) - (git-insert-fileinfo status (git-create-fileinfo 'added new-name old-perm new-perm 'rename name)) refresh) - (git-insert-fileinfo status (git-create-fileinfo (git-state-code state) name old-perm new-perm) refresh)) + (push (git-create-fileinfo 'added new-name old-perm new-perm 'copy name) infolist) + (push (git-create-fileinfo 'deleted name 0 0 'rename new-name) infolist) + (push (git-create-fileinfo 'added new-name old-perm new-perm 'rename name) infolist)) + (push (git-create-fileinfo (git-state-code state) name old-perm new-perm) infolist)) (setq files (delete name files)) - (when new-name (setq files (delete new-name files))))))) - files) + (when new-name (setq files (delete new-name files)))))) + (git-insert-info-list status infolist) + files)) (defun git-find-status-file (status file) "Find a given file in the status ewoc and return its node." @@ -576,16 +615,16 @@ Return the list of files that haven't been handled." (defun git-run-ls-files (status files default-state &rest options) "Run git-ls-files on FILES and parse the results into STATUS. Return the list of files that haven't been handled." - (let ((refresh files)) + (let (infolist) (with-temp-buffer - (apply #'git-run-command t nil "ls-files" "-z" "-t" (append options (list "--") files)) + (apply #'git-run-command t nil "ls-files" "-z" (append options (list "--") files)) (goto-char (point-min)) - (while (re-search-forward "\\([HMRCK?]\\) \\([^\0]*\\)\0" nil t 1) - (let ((state (match-string 1)) - (name (match-string 2))) - (git-insert-fileinfo status (git-create-fileinfo (or (git-state-code state) default-state) name) refresh) - (setq files (delete name files)))))) - files) + (while (re-search-forward "\\([^\0]*\\)\0" nil t 1) + (let ((name (match-string 1))) + (push (git-create-fileinfo default-state name) infolist) + (setq files (delete name files))))) + (git-insert-info-list status infolist) + files)) (defun git-run-ls-unmerged (status files) "Run git-ls-files -u on FILES and parse the results into STATUS." @@ -594,9 +633,8 @@ Return the list of files that haven't been handled." (goto-char (point-min)) (let (unmerged-files) (while (re-search-forward "[0-7]\\{6\\} [0-9a-f]\\{40\\} [123]\t\\([^\0]+\\)\0" nil t) - (let ((node (git-find-status-file status (match-string 1)))) - (when node (push (ewoc-data node) unmerged-files)))) - (git-set-files-state unmerged-files 'unmerged)))) + (push (match-string 1) unmerged-files)) + (git-set-filenames-state status unmerged-files 'unmerged)))) (defun git-get-exclude-files () "Get the list of exclude files to pass to git-ls-files." @@ -622,18 +660,7 @@ Return the list of files that haven't been handled." (setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o" (concat "--exclude-per-directory=" git-per-dir-ignore-file) (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files))))) - ; mark remaining files with the default state (or remove them if nil) - (when remaining-files - (if default-state - (ewoc-map (lambda (info) - (when (member (git-fileinfo->name info) remaining-files) - (git-set-files-state (list info) default-state)) - nil) - status) - (ewoc-filter status - (lambda (info files) - (not (member (git-fileinfo->name info) files))) - remaining-files))) + (git-set-filenames-state status remaining-files default-state) (git-refresh-files) (git-refresh-ewoc-hf status))) From 98acc3fabc2d197525f1b0119382a00a664014b7 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 13 Sep 2007 11:50:08 +0200 Subject: [PATCH 45/94] git.el: Allow selecting whether to display uptodate/unknown/ignored files. The default behavior for each state can be customized, and it can also be toggled directly from the status buffer. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 92 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 77 insertions(+), 15 deletions(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index b5d7c0664e..d1068c6258 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -97,6 +97,21 @@ if there is already one that displays the same directory." :group 'git :type 'string) +(defcustom git-show-uptodate nil + "Whether to display up-to-date files." + :group 'git + :type 'boolean) + +(defcustom git-show-ignored nil + "Whether to display ignored files." + :group 'git + :type 'boolean) + +(defcustom git-show-unknown t + "Whether to display unknown files." + :group 'git + :type 'boolean) + (defface git-status-face '((((class color) (background light)) (:foreground "purple")) @@ -646,23 +661,30 @@ Return the list of files that haven't been handled." (push config files)) files)) +(defun git-run-ls-files-with-excludes (status files default-state &rest options) + "Run git-ls-files on FILES with appropriate --exclude-from options." + (let ((exclude-files (git-get-exclude-files))) + (apply #'git-run-ls-files status files default-state + (concat "--exclude-per-directory=" git-per-dir-ignore-file) + (append options (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files))))) + (defun git-update-status-files (files &optional default-state) "Update the status of FILES from the index." (unless git-status (error "Not in git-status buffer.")) - (let* ((status git-status) - (remaining-files + (unless files + (when git-show-uptodate (git-run-ls-files git-status nil 'uptodate "-c"))) + (let* ((remaining-files (if (git-empty-db-p) ; we need some special handling for an empty db - (git-run-ls-files status files 'added "-c") - (git-run-diff-index status files)))) - (git-run-ls-unmerged status files) - (when (or (not files) remaining-files) - (let ((exclude-files (git-get-exclude-files))) - (setq remaining-files (apply #'git-run-ls-files status remaining-files 'unknown "-o" - (concat "--exclude-per-directory=" git-per-dir-ignore-file) - (mapcar (lambda (f) (concat "--exclude-from=" f)) exclude-files))))) - (git-set-filenames-state status remaining-files default-state) + (git-run-ls-files git-status files 'added "-c") + (git-run-diff-index git-status files)))) + (git-run-ls-unmerged git-status files) + (when (or remaining-files (and git-show-unknown (not files))) + (setq remaining-files (git-run-ls-files-with-excludes git-status remaining-files 'unknown "-o"))) + (when (or remaining-files (and git-show-ignored (not files))) + (setq remaining-files (git-run-ls-files-with-excludes git-status remaining-files 'ignored "-o" "-i"))) + (git-set-filenames-state git-status remaining-files default-state) (git-refresh-files) - (git-refresh-ewoc-hf status))) + (git-refresh-ewoc-hf git-status))) (defun git-marked-files () "Return a list of all marked files, or if none a list containing just the file at cursor position." @@ -943,11 +965,41 @@ Return the list of files that haven't been handled." (interactive) (ewoc-filter git-status (lambda (info) - (not (or (eq (git-fileinfo->state info) 'ignored) - (eq (git-fileinfo->state info) 'uptodate))))) + (case (git-fileinfo->state info) + ('ignored git-show-ignored) + ('uptodate git-show-uptodate) + ('unknown git-show-unknown) + (t t)))) (unless (ewoc-nth git-status 0) ; refresh header if list is empty (git-refresh-ewoc-hf git-status))) +(defun git-toggle-show-uptodate () + "Toogle the option for showing up-to-date files." + (interactive) + (if (setq git-show-uptodate (not git-show-uptodate)) + (git-refresh-status) + (git-remove-handled))) + +(defun git-toggle-show-ignored () + "Toogle the option for showing ignored files." + (interactive) + (if (setq git-show-ignored (not git-show-ignored)) + (progn + (git-run-ls-files-with-excludes git-status nil 'ignored "-o" "-i") + (git-refresh-files) + (git-refresh-ewoc-hf git-status)) + (git-remove-handled))) + +(defun git-toggle-show-unknown () + "Toogle the option for showing unknown files." + (interactive) + (if (setq git-show-unknown (not git-show-unknown)) + (progn + (git-run-ls-files-with-excludes git-status nil 'unknown "-o") + (git-refresh-files) + (git-refresh-ewoc-hf git-status)) + (git-remove-handled))) + (defun git-setup-diff-buffer (buffer) "Setup a buffer for displaying a diff." (let ((dir default-directory)) @@ -1173,7 +1225,8 @@ Return the list of files that haven't been handled." (unless git-status-mode-map (let ((map (make-keymap)) - (diff-map (make-sparse-keymap))) + (diff-map (make-sparse-keymap)) + (toggle-map (make-sparse-keymap))) (suppress-keymap map) (define-key map "?" 'git-help) (define-key map "h" 'git-help) @@ -1197,6 +1250,7 @@ Return the list of files that haven't been handled." (define-key map "q" 'git-status-quit) (define-key map "r" 'git-remove-file) (define-key map "R" 'git-resolve-file) + (define-key map "t" toggle-map) (define-key map "T" 'git-toggle-all-marks) (define-key map "u" 'git-unmark-file) (define-key map "U" 'git-revert-file) @@ -1213,6 +1267,11 @@ Return the list of files that haven't been handled." (define-key diff-map "h" 'git-diff-file-merge-head) (define-key diff-map "m" 'git-diff-file-mine) (define-key diff-map "o" 'git-diff-file-other) + ; the toggle submap + (define-key toggle-map "u" 'git-toggle-show-uptodate) + (define-key toggle-map "i" 'git-toggle-show-ignored) + (define-key toggle-map "k" 'git-toggle-show-unknown) + (define-key toggle-map "m" 'git-toggle-all-marks) (setq git-status-mode-map map))) ;; git mode should only run in the *git status* buffer @@ -1234,6 +1293,9 @@ Commands: (let ((status (ewoc-create 'git-fileinfo-prettyprint "" ""))) (set (make-local-variable 'git-status) status)) (set (make-local-variable 'list-buffers-directory) default-directory) + (make-local-variable 'git-show-uptodate) + (make-local-variable 'git-show-ignored) + (make-local-variable 'git-show-unknown) (run-hooks 'git-status-mode-hook))) (defun git-find-status-buffer (dir) From 568d2cde9b9fe0fc6b3202c7987b13289cb1a4a0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Thu, 13 Sep 2007 11:50:29 +0200 Subject: [PATCH 46/94] git.el: Allow the add and remove commands to be applied to ignored files. Signed-off-by: Alexandre Julliard Signed-off-by: Junio C Hamano --- contrib/emacs/git.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/emacs/git.el b/contrib/emacs/git.el index d1068c6258..2d77fd47ec 100644 --- a/contrib/emacs/git.el +++ b/contrib/emacs/git.el @@ -902,7 +902,7 @@ Return the list of files that haven't been handled." (defun git-add-file () "Add marked file(s) to the index cache." (interactive) - (let ((files (git-get-filenames (git-marked-files-state 'unknown)))) + (let ((files (git-get-filenames (git-marked-files-state 'unknown 'ignored)))) (unless files (push (file-relative-name (read-file-name "File to add: " nil nil t)) files)) (apply #'git-run-command nil nil "update-index" "--add" "--" files) @@ -920,7 +920,7 @@ Return the list of files that haven't been handled." (defun git-remove-file () "Remove the marked file(s)." (interactive) - (let ((files (git-get-filenames (git-marked-files-state 'added 'modified 'unknown 'uptodate)))) + (let ((files (git-get-filenames (git-marked-files-state 'added 'modified 'unknown 'uptodate 'ignored)))) (unless files (push (file-relative-name (read-file-name "File to remove: " nil nil t)) files)) (if (yes-or-no-p From f28dd4774d4723e8251817e910dbdc5507282113 Mon Sep 17 00:00:00 2001 From: Gerrit Pape Date: Thu, 13 Sep 2007 11:36:22 +0000 Subject: [PATCH 47/94] git-clone: improve error message if curl program is missing or not executable If the curl program is not available (or not executable), and git clone is started to clone a repository through http, this is the output Initialized empty Git repository in /tmp/puppet/.git/ /usr/bin/git-clone: line 37: curl: command not found Cannot get remote repository information. Perhaps git-update-server-info needs to be run there? This patch improves the error message by checking the return code when running curl to exit immediately if it's 126 or 127; the error output now is Initialized empty Git repository in /tmp/puppet/.git/ /usr/bin/git-clone: line 37: curl: command not found Adrian Bridgett noticed this and reported through http://bugs.debian.org/440976 Signed-off-by: Gerrit Pape Signed-off-by: Junio C Hamano --- git-clone.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/git-clone.sh b/git-clone.sh index 18003ab4b3..5e582fe247 100755 --- a/git-clone.sh +++ b/git-clone.sh @@ -34,7 +34,11 @@ fi http_fetch () { # $1 = Remote, $2 = Local - curl -nsfL $curl_extra_args "$1" >"$2" + curl -nsfL $curl_extra_args "$1" >"$2" || + case $? in + 126|127) exit ;; + *) return $? ;; + esac } clone_dumb_http () { From f5de79956b2abeb0f45b338428d39ce089002b66 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Thu, 13 Sep 2007 17:57:56 +0200 Subject: [PATCH 48/94] Remove duplicate note about removing commits with git-filter-branch A duplicate of an already existing section in the documentation of git-filter-branch was added in commit f95eef15f2f8a336b9a42749f5458c841a5a5d63. This patch removes that redundant section. Signed-off-by: Ulrik Sverdrup Signed-off-by: Junio C Hamano --- Documentation/git-filter-branch.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Documentation/git-filter-branch.txt b/Documentation/git-filter-branch.txt index 29bb8cec0c..c878ed395e 100644 --- a/Documentation/git-filter-branch.txt +++ b/Documentation/git-filter-branch.txt @@ -220,11 +220,6 @@ git filter-branch --commit-filter ' fi' HEAD ------------------------------------------------------------------------------ -Note that the changes introduced by the commits, and not reverted by -subsequent commits, will still be in the rewritten branch. If you want -to throw out _changes_ together with the commits, you should use the -interactive mode of gitlink:git-rebase[1]. - The function 'skip_commits' is defined as follows: -------------------------- From 767c98a5929b02152c8904a09f1eabbf8d386395 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 00:45:29 -0700 Subject: [PATCH 49/94] git-add -u: do not barf on type changes Signed-off-by: Junio C Hamano --- builtin-add.c | 1 + 1 file changed, 1 insertion(+) diff --git a/builtin-add.c b/builtin-add.c index 105a9f0e1f..9847b7e019 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -98,6 +98,7 @@ static void update_callback(struct diff_queue_struct *q, die("unexpacted diff status %c", p->status); case DIFF_STATUS_UNMERGED: case DIFF_STATUS_MODIFIED: + case DIFF_STATUS_TYPE_CHANGED: add_file_to_cache(path, verbose); break; case DIFF_STATUS_DELETED: From 8419d2ee9ba8b375186a5c1019df8dfbce610aba Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 13 Sep 2007 22:30:45 -0700 Subject: [PATCH 50/94] git-format-patch --in-reply-to: accept with angle brackets This will allow RFC-literate users to say: format-patch --in-reply-to='' without forcing them to strip the surrounding angle brackets like this: format-patch --in-reply-to='message.id@site.name' We accept both forms, and the latter gets necessary < and > around it as before. Signed-off-by: Junio C Hamano --- builtin-log.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/builtin-log.c b/builtin-log.c index fa81c25920..c6cc3aef52 100644 --- a/builtin-log.c +++ b/builtin-log.c @@ -437,6 +437,34 @@ static void gen_message_id(char *dest, unsigned int length, char *base) (int)(email_end - email_start - 1), email_start + 1); } +static const char *clean_message_id(const char *msg_id) +{ + char ch; + const char *a, *z, *m; + char *n; + size_t len; + + m = msg_id; + while ((ch = *m) && (isspace(ch) || (ch == '<'))) + m++; + a = m; + z = NULL; + while ((ch = *m)) { + if (!isspace(ch) && (ch != '>')) + z = m; + m++; + } + if (!z) + die("insane in-reply-to: %s", msg_id); + if (++z == m) + return a; + len = z - a; + n = xmalloc(len + 1); + memcpy(n, a, len); + n[len] = 0; + return n; +} + int cmd_format_patch(int argc, const char **argv, const char *prefix) { struct commit *commit; @@ -625,7 +653,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix) if (numbered) rev.total = total + start_number - 1; rev.add_signoff = add_signoff; - rev.ref_message_id = in_reply_to; + if (in_reply_to) + rev.ref_message_id = clean_message_id(in_reply_to); while (0 <= --nr) { int shown; commit = list[nr]; From 09d5dc32fbdfa7bfd23fe377455445dd2605c3b9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 13 Sep 2007 20:33:11 -0700 Subject: [PATCH 51/94] Simplify cache API Earlier, add_file_to_index() invalidated the path in the cache-tree but remove_file_from_cache() did not, and the user of the latter needed to invalidate the entry himself. This led to a few bugs due to missed invalidate calls already. This patch makes the management of cache-tree less error prone by making more invalidate calls from lower level cache API functions. The rules are: - If you are going to write the index, you should either maintain cache_tree correctly. - If you cannot, alternatively you can remove the entire cache_tree by calling cache_tree_free() before you call write_cache(). - When you modify the index, cache_tree_invalidate_path() should be called with the path you are modifying, to discard the entry from the cache-tree structure. - The following cache API functions exported from read-cache.c (and the macro whose names have "cache" instead of "index") automatically call cache_tree_invalidate_path() for you: - remove_file_from_index(); - add_file_to_index(); - add_index_entry(); You can modify the index bypassing the above API functions (e.g. find an existing cache entry from the index and modify it in place). You need to call cache_tree_invalidate_path() yourself in such a case. Signed-off-by: Junio C Hamano --- builtin-add.c | 1 - builtin-apply.c | 2 -- builtin-mv.c | 7 ++----- builtin-rm.c | 1 - builtin-update-index.c | 9 --------- read-cache.c | 3 ++- 6 files changed, 4 insertions(+), 19 deletions(-) diff --git a/builtin-add.c b/builtin-add.c index 9847b7e019..866d19dd77 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -103,7 +103,6 @@ static void update_callback(struct diff_queue_struct *q, break; case DIFF_STATUS_DELETED: remove_file_from_cache(path); - cache_tree_invalidate_path(active_cache_tree, path); if (verbose) printf("remove '%s'\n", path); break; diff --git a/builtin-apply.c b/builtin-apply.c index 976ec77041..79a4852bc2 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2394,7 +2394,6 @@ static void remove_file(struct patch *patch, int rmdir_empty) if (update_index) { if (remove_file_from_cache(patch->old_name) < 0) die("unable to remove %s from index", patch->old_name); - cache_tree_invalidate_path(active_cache_tree, patch->old_name); } if (!cached) { if (S_ISGITLINK(patch->old_mode)) { @@ -2549,7 +2548,6 @@ static void create_file(struct patch *patch) mode = S_IFREG | 0644; create_one_file(path, mode, buf, size); add_index_file(path, mode, buf, size); - cache_tree_invalidate_path(active_cache_tree, path); } /* phase zero is to remove, phase one is to create */ diff --git a/builtin-mv.c b/builtin-mv.c index 3563216aca..b95b7d286a 100644 --- a/builtin-mv.c +++ b/builtin-mv.c @@ -276,11 +276,8 @@ int cmd_mv(int argc, const char **argv, const char *prefix) add_file_to_cache(path, verbose); } - for (i = 0; i < deleted.nr; i++) { - const char *path = deleted.items[i].path; - remove_file_from_cache(path); - cache_tree_invalidate_path(active_cache_tree, path); - } + for (i = 0; i < deleted.nr; i++) + remove_file_from_cache(deleted.items[i].path); if (active_cache_changed) { if (write_cache(newfd, active_cache, active_nr) || diff --git a/builtin-rm.c b/builtin-rm.c index 9a808c1bf9..3b0677e44b 100644 --- a/builtin-rm.c +++ b/builtin-rm.c @@ -227,7 +227,6 @@ int cmd_rm(int argc, const char **argv, const char *prefix) if (remove_file_from_cache(path)) die("git-rm: unable to remove %s", path); - cache_tree_invalidate_path(active_cache_tree, path); } if (show_only) diff --git a/builtin-update-index.c b/builtin-update-index.c index a7a4574f2b..55fb679d68 100644 --- a/builtin-update-index.c +++ b/builtin-update-index.c @@ -195,11 +195,6 @@ static int process_path(const char *path) int len; struct stat st; - /* We probably want to do this in remove_file_from_cache() and - * add_cache_entry() instead... - */ - cache_tree_invalidate_path(active_cache_tree, path); - /* * First things first: get the stat information, to decide * what to do about the pathname! @@ -239,7 +234,6 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1, return error("%s: cannot add to the index - missing --add option?", path); report("add '%s'", path); - cache_tree_invalidate_path(active_cache_tree, path); return 0; } @@ -284,7 +278,6 @@ static void update_one(const char *path, const char *prefix, int prefix_length) die("Unable to mark file %s", path); goto free_return; } - cache_tree_invalidate_path(active_cache_tree, path); if (force_remove) { if (remove_file_from_cache(p)) @@ -367,7 +360,6 @@ static void read_index_info(int line_termination) free(path_name); continue; } - cache_tree_invalidate_path(active_cache_tree, path_name); if (!mode) { /* mode == 0 means there is no such path -- remove */ @@ -474,7 +466,6 @@ static int unresolve_one(const char *path) goto free_return; } - cache_tree_invalidate_path(active_cache_tree, path); remove_file_from_cache(path); if (add_cache_entry(ce_2, ADD_CACHE_OK_TO_ADD)) { error("%s: cannot add our version to the index.", path); diff --git a/read-cache.c b/read-cache.c index 8b1c94e0e3..d82a99a915 100644 --- a/read-cache.c +++ b/read-cache.c @@ -346,6 +346,7 @@ int remove_file_from_index(struct index_state *istate, const char *path) int pos = index_name_pos(istate, path, strlen(path)); if (pos < 0) pos = -pos-1; + cache_tree_invalidate_path(istate->cache_tree, path); while (pos < istate->cache_nr && !strcmp(istate->cache[pos]->name, path)) remove_index_entry_at(istate, pos); return 0; @@ -430,7 +431,6 @@ int add_file_to_index(struct index_state *istate, const char *path, int verbose) die("unable to add %s to index",path); if (verbose) printf("add '%s'\n", path); - cache_tree_invalidate_path(istate->cache_tree, path); return 0; } @@ -673,6 +673,7 @@ static int add_index_entry_with_check(struct index_state *istate, struct cache_e int ok_to_replace = option & ADD_CACHE_OK_TO_REPLACE; int skip_df_check = option & ADD_CACHE_SKIP_DFCHECK; + cache_tree_invalidate_path(istate->cache_tree, ce->name); pos = index_name_pos(istate, ce->name, ntohs(ce->ce_flags)); /* existing match? Just replace it. */ From b78281f7215c0236da6bd5c04ec5e500c83fd101 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 12:12:32 -0700 Subject: [PATCH 52/94] diff --no-index: do not forget to run diff_setup_done() Code inspection by Linus found this. Signed-off-by: Junio C Hamano --- diff-lib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/diff-lib.c b/diff-lib.c index f5568c3b36..da5571302d 100644 --- a/diff-lib.c +++ b/diff-lib.c @@ -298,6 +298,8 @@ int setup_diff_no_index(struct rev_info *revs, revs->diffopt.nr_paths = 2; revs->diffopt.no_index = 1; revs->max_count = -2; + if (diff_setup_done(&revs->diffopt) < 0) + die("diff_setup_done failed"); return 0; } From 0024a54923a12f8c05ce4290f5ebefab0cce4336 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Fri, 14 Sep 2007 10:39:48 -0700 Subject: [PATCH 53/94] Fix the rename detection limit checking This adds more proper rename detection limits. Instead of just checking the limit against the number of potential rename destinations, we verify that the rename matrix (which is what really matters) doesn't grow ridiculously large, and we also make sure that we don't overflow when doing the matrix size calculation. This also changes the default limits from unlimited, to a rename matrix that is limited to 100 entries on a side. You can raise it with the config entry, or by using the "-l" command line flag, but at least the default is now a sane number that avoids spending lots of time (and memory) in situations that likely don't merit it. The choice of default value is of course very debatable. Limiting the rename matrix to a 100x100 size will mean that even if you have just one obvious rename, but you also create (or delete) 10,000 files, the rename matrix will be so big that we disable the heuristics. Sounds reasonable to me, but let's see if people hit this (and, perhaps more importantly, actually *care*) in real life. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- diff.c | 2 +- diffcore-rename.c | 19 +++++++++++++++++-- wt-status.c | 1 + 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/diff.c b/diff.c index 1aca5df522..0ee9ea1c1b 100644 --- a/diff.c +++ b/diff.c @@ -17,7 +17,7 @@ #endif static int diff_detect_rename_default; -static int diff_rename_limit_default = -1; +static int diff_rename_limit_default = 100; static int diff_use_color_default; int diff_auto_refresh_index = 1; diff --git a/diffcore-rename.c b/diffcore-rename.c index 6bde4396f2..41b35c3a9e 100644 --- a/diffcore-rename.c +++ b/diffcore-rename.c @@ -298,10 +298,25 @@ void diffcore_rename(struct diff_options *options) else if (detect_rename == DIFF_DETECT_COPY) register_rename_src(p->one, 1, p->score); } - if (rename_dst_nr == 0 || rename_src_nr == 0 || - (0 < rename_limit && rename_limit < rename_dst_nr)) + if (rename_dst_nr == 0 || rename_src_nr == 0) goto cleanup; /* nothing to do */ + /* + * This basically does a test for the rename matrix not + * growing larger than a "rename_limit" square matrix, ie: + * + * rename_dst_nr * rename_src_nr > rename_limit * rename_limit + * + * but handles the potential overflow case specially (and we + * assume at least 32-bit integers) + */ + if (rename_limit <= 0 || rename_limit > 32767) + rename_limit = 32767; + if (rename_dst_nr > rename_limit && rename_src_nr > rename_limit) + goto cleanup; + if (rename_dst_nr * rename_src_nr > rename_limit * rename_limit) + goto cleanup; + /* We really want to cull the candidates list early * with cheap tests in order to avoid doing deltas. * The first round matches up the up-to-date entries, diff --git a/wt-status.c b/wt-status.c index 52054201c2..10ce6eedc7 100644 --- a/wt-status.c +++ b/wt-status.c @@ -227,6 +227,7 @@ static void wt_status_print_updated(struct wt_status *s) rev.diffopt.format_callback = wt_status_print_updated_cb; rev.diffopt.format_callback_data = s; rev.diffopt.detect_rename = 1; + rev.diffopt.rename_limit = 100; wt_read_cache(s); run_diff_index(&rev, 1); } From 42b5f8693eddbbd486579fb2304db1bc7282ac26 Mon Sep 17 00:00:00 2001 From: Jari Aalto Date: Fri, 14 Sep 2007 21:38:02 +0300 Subject: [PATCH 54/94] Documentation/git-archive.txt: a couple of clarifications. The description of the option gave impression that there were several formats available by using three dots. There are no other formats than tar and gzip currently supported. Clarify that the archive goes to the standard output. Signed-off-by: Jari Aalto Signed-off-by: Junio C Hamano --- Documentation/git-archive.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Documentation/git-archive.txt b/Documentation/git-archive.txt index f2080eb6ad..e1e2d60fef 100644 --- a/Documentation/git-archive.txt +++ b/Documentation/git-archive.txt @@ -15,7 +15,8 @@ SYNOPSIS DESCRIPTION ----------- Creates an archive of the specified format containing the tree -structure for the named tree. If is specified it is +structure for the named tree, and writes it out to the standard +output. If is specified it is prepended to the filenames in the archive. 'git-archive' behaves differently when given a tree ID versus when @@ -31,7 +32,7 @@ OPTIONS ------- --format=:: - Format of the resulting archive: 'tar', 'zip'... The default + Format of the resulting archive: 'tar' or 'zip'. The default is 'tar'. --list, -l:: From 43b98acc23306fd7fff888477937063361a09593 Mon Sep 17 00:00:00 2001 From: Benoit Sigoure Date: Fri, 14 Sep 2007 10:29:04 +0200 Subject: [PATCH 55/94] Add test to check recent fix to "git add -u" An earlier commit fixed type-change case in "git add -u". This adds a test to make sure we do not introduce regression. At the same time, it fixes a stupid typo in the error message. Signed-off-by: Benoit Sigoure Signed-off-by: Junio C Hamano --- builtin-add.c | 2 +- t/t2200-add-update.sh | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/builtin-add.c b/builtin-add.c index 9847b7e019..3d8b8b4f89 100644 --- a/builtin-add.c +++ b/builtin-add.c @@ -95,7 +95,7 @@ static void update_callback(struct diff_queue_struct *q, const char *path = p->one->path; switch (p->status) { default: - die("unexpacted diff status %c", p->status); + die("unexpected diff status %c", p->status); case DIFF_STATUS_UNMERGED: case DIFF_STATUS_MODIFIED: case DIFF_STATUS_TYPE_CHANGED: diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index 61d08bb431..eb1ced3c37 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -16,11 +16,12 @@ only the updates to dir/sub.' test_expect_success setup ' echo initial >check && echo initial >top && + echo initial >foo && mkdir dir1 dir2 && echo initial >dir1/sub1 && echo initial >dir1/sub2 && echo initial >dir2/sub3 && - git add check dir1 dir2 top && + git add check dir1 dir2 top foo && test_tick git-commit -m initial && @@ -76,4 +77,12 @@ test_expect_success 'change gets noticed' ' ' +test_expect_success 'replace a file with a symlink' ' + + rm foo && + ln -s top foo && + git add -u -- foo + +' + test_done From 7c8b5eaf225db0b6b502126fc16f8f6814c38d24 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 14:51:08 -0700 Subject: [PATCH 56/94] Documentation/git-config.txt: AsciiDoc tweak to avoid leading dot Bram Schoenmakers noticed that git-config document was formatted incorrectly. Depending on the version of AsciiDoc and docbook toolchain, it is sometimes taken as a numbered example by AsciiDoc, some other times passed intact to roff format to confuse "man". Since we refer to the repository metadata directory as $GIT_DIR elsewhere, work it around by using that symbolic name. Signed-off-by: Junio C Hamano --- Documentation/git-config.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index 5b794f4399..a592b61e2f 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -142,7 +142,7 @@ FILES If not set explicitly with '--file', there are three files where git-config will search for configuration options: -.git/config:: +$GIT_DIR/config:: Repository specific configuration file. (The filename is of course relative to the repository root, not the working directory.) From d99ebf081797dbb43ff618ff59f4c607b0acf045 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 00:31:00 -0700 Subject: [PATCH 57/94] Split grep arguments in a way that does not requires to add /dev/null. In order to (almost) always show the name of the file without relying on "-H" option of GNU grep, we used to add /dev/null to the argument list unless we are doing -l or -L. This caused "/dev/null:0" to show up when -c is given in the output. It is not enough to add -c to the set of options we do not pass /dev/null for. When we have too many files, we invoke grep multiple times and we need to avoid giving a widow filename to the last invocation -- otherwise we will not see the name. This keeps two filenames when the argv[] buffer is about to overflow and we have not finished iterating over the index, so that the last round will always have at least two paths to work with (and not require /dev/null). An obvious and the only exception is when there is only 1 file that is given to the underlying grep, and in that case we avoid passing /dev/null and let the external "grep -c" report only the number of matches. Signed-off-by: Junio C Hamano --- builtin-grep.c | 90 +++++++++++++++++++++++++++++++++++++++++-------- t/t7002-grep.sh | 4 +++ 2 files changed, 80 insertions(+), 14 deletions(-) diff --git a/builtin-grep.c b/builtin-grep.c index e13cb31f2b..c7b45c4d58 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -187,6 +187,78 @@ static int exec_grep(int argc, const char **argv) else die("maximum number of args exceeded"); \ } while (0) +/* + * If you send a singleton filename to grep, it does not give + * the name of the file. GNU grep has "-H" but we would want + * that behaviour in a portable way. + * + * So we keep two pathnames in argv buffer unsent to grep in + * the main loop if we need to do more than one grep. + */ +static int flush_grep(struct grep_opt *opt, + int argc, int arg0, const char **argv, int *kept) +{ + int status; + int count = argc - arg0; + const char *kept_0 = NULL; + + if (count <= 2) { + /* + * Because we keep at least 2 paths in the call from + * the main loop (i.e. kept != NULL), and MAXARGS is + * far greater than 2, this usually is a call to + * conclude the grep. However, the user could attempt + * to overflow the argv buffer by giving too many + * options to leave very small number of real + * arguments even for the call in the main loop. + */ + if (kept) + die("insanely many options to grep"); + + /* + * If we have two or more paths, we do not have to do + * anything special, but we need to push /dev/null to + * get "-H" behaviour of GNU grep portably but when we + * are not doing "-l" nor "-L" nor "-c". + */ + if (count == 1 && + !opt->name_only && + !opt->unmatch_name_only && + !opt->count) { + argv[argc++] = "/dev/null"; + argv[argc] = NULL; + } + } + + else if (kept) { + /* + * Called because we found many paths and haven't finished + * iterating over the cache yet. We keep two paths + * for the concluding call. argv[argc-2] and argv[argc-1] + * has the last two paths, so save the first one away, + * replace it with NULL while sending the list to grep, + * and recover them after we are done. + */ + *kept = 2; + kept_0 = argv[argc-2]; + argv[argc-2] = NULL; + argc -= 2; + } + + status = exec_grep(argc, argv); + + if (kept_0) { + /* + * Then recover them. Now the last arg is beyond the + * terminating NULL which is at argc, and the second + * from the last is what we saved away in kept_0 + */ + argv[arg0++] = kept_0; + argv[arg0] = argv[argc+1]; + } + return status; +} + static int external_grep(struct grep_opt *opt, const char **paths, int cached) { int i, nr, argc, hit, len, status; @@ -253,22 +325,12 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) push_arg(p->pattern); } - /* - * To make sure we get the header printed out when we want it, - * add /dev/null to the paths to grep. This is unnecessary - * (and wrong) with "-l" or "-L", which always print out the - * name anyway. - * - * GNU grep has "-H", but this is portable. - */ - if (!opt->name_only && !opt->unmatch_name_only) - push_arg("/dev/null"); - hit = 0; argc = nr; for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; char *name; + int kept; if (!S_ISREG(ntohl(ce->ce_mode))) continue; if (!pathspec_matches(paths, ce->name)) @@ -283,10 +345,10 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) argv[argc++] = name; if (argc < MAXARGS && !ce_stage(ce)) continue; - status = exec_grep(argc, argv); + status = flush_grep(opt, argc, nr, argv, &kept); if (0 < status) hit = 1; - argc = nr; + argc = nr + kept; if (ce_stage(ce)) { do { i++; @@ -296,7 +358,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) } } if (argc > nr) { - status = exec_grep(argc, argv); + status = flush_grep(opt, argc, nr, argv, NULL); if (0 < status) hit = 1; } diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 6bfb899ed1..68b2b92879 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -107,6 +107,10 @@ do diff expected actual ' + test_expect_failure "grep -c $L (no /dev/null)" ' + git grep -c test $H | grep -q "/dev/null" + ' + done test_done From db33af0a7f64ffc48de3ad018a1df03f744fb7a2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 16:53:58 -0700 Subject: [PATCH 58/94] git-commit: partial commit of paths only removed from the index Because a partial commit is meant to be a way to ignore what are staged in the index, "git rm --cached A && git commit A" should just record what is in A on the filesystem. The previous patch made the command sequence to barf, saying that A has not been added yet. This fixes it. Signed-off-by: Junio C Hamano --- git-commit.sh | 2 +- t/t7501-commit.sh | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/git-commit.sh b/git-commit.sh index 5ea3fd0076..bb113e858b 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -404,7 +404,7 @@ t,) ( GIT_INDEX_FILE="$NEXT_INDEX" export GIT_INDEX_FILE - git update-index --remove --stdin + git update-index --add --remove --stdin ) || exit ;; esac diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index f178f56208..b151b51a34 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -131,7 +131,7 @@ test_expect_success \ 'validate git-rev-list output.' \ 'diff current expected' -test_expect_success 'partial commit that involve removal (1)' ' +test_expect_success 'partial commit that involves removal (1)' ' git rm --cached file && mv file elif && @@ -143,7 +143,7 @@ test_expect_success 'partial commit that involve removal (1)' ' ' -test_expect_success 'partial commit that involve removal (2)' ' +test_expect_success 'partial commit that involves removal (2)' ' git commit -m "Partial: remove file" file && git diff-tree --name-status HEAD^ HEAD >current && @@ -152,4 +152,15 @@ test_expect_success 'partial commit that involve removal (2)' ' ' +test_expect_success 'partial commit that involves removal (3)' ' + + git rm --cached elif && + echo elif >elif && + git commit -m "Partial: modify elif" elif && + git diff-tree --name-status HEAD^ HEAD >current && + echo "M elif" >expected && + diff expected current + +' + test_done From a7a0f3d3f858eef1f1326821343c640c5b3838ce Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 16:59:04 -0700 Subject: [PATCH 59/94] Document ls-files --with-tree= Signed-off-by: Junio C Hamano --- Documentation/git-ls-files.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 997594549f..9e454f0a4d 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -15,7 +15,7 @@ SYNOPSIS [-x |--exclude=] [-X |--exclude-from=] [--exclude-per-directory=] - [--error-unmatch] + [--error-unmatch] [--with-tree=] [--full-name] [--abbrev] [--] []\* DESCRIPTION @@ -81,6 +81,13 @@ OPTIONS If any does not appear in the index, treat this as an error (return 1). +--with-tree=:: + When using --error-unmatch to expand the user supplied + (i.e. path pattern) arguments to paths, pretend + that paths which were removed in the index since the + named are still present. Using this option + with `-s` or `-u` options does not make any sense. + -t:: Identify the file status with the following tags (followed by a space) at the start of each line: From e1ef867328bd7d2cd67499ac30479821bdf96662 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 22:30:20 -0700 Subject: [PATCH 60/94] builtin-pack-objects.c: avoid bogus gcc warnings These empty statement marcos can solicit bogus "statement with no effect" warnings; squelch them. Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b126fc8e72..a15906bdb2 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1311,12 +1311,12 @@ static pthread_mutex_t progress_mutex = PTHREAD_MUTEX_INITIALIZER; #else -#define read_lock() 0 -#define read_unlock() 0 -#define cache_lock() 0 -#define cache_unlock() 0 -#define progress_lock() 0 -#define progress_unlock() 0 +#define read_lock() (void)0 +#define read_unlock() (void)0 +#define cache_lock() (void)0 +#define cache_unlock() (void)0 +#define progress_lock() (void)0 +#define progress_unlock() (void)0 #endif From e598c5177e439271e8bd81ef2a689a3ab0db80e6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 15 Sep 2007 16:32:23 -0700 Subject: [PATCH 61/94] git-sh-setup: typofix in comments Noticed by Anupam Srivastava. Signed-off-by: Junio C Hamano --- git-sh-setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 185c5c6c95..3c325fd133 100755 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -6,7 +6,7 @@ # it dies. # Having this variable in your environment would break scripts because -# you would cause "cd" to be be taken to unexpected places. If you +# you would cause "cd" to be taken to unexpected places. If you # like CDPATH, define it for your interactive shell sessions without # exporting it. unset CDPATH From 023756f4eb71bfa37e17b0bdbf4b9fcbbba95466 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 15 Sep 2007 18:39:52 +0100 Subject: [PATCH 62/94] revision walker: --cherry-pick is a limited operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We used to rely on the fact that cherry-pick would trigger the code path to set limited = 1 in handle_commit(), when an uninteresting commit was encountered. However, when cherry picking between two independent branches, i.e. when there are no merge bases, and there is only linear development (which can happen when you cvsimport a fork of a project), no uninteresting commit will be encountered. So set limited = 1 when --cherry-pick was asked for. Noticed by Martin Bähr. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- revision.c | 1 + t/t6007-rev-list-cherry-pick-file.sh | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/revision.c b/revision.c index c193c3ea22..33d092c3c4 100644 --- a/revision.c +++ b/revision.c @@ -1024,6 +1024,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch } if (!strcmp(arg, "--cherry-pick")) { revs->cherry_pick = 1; + revs->limited = 1; continue; } if (!strcmp(arg, "--objects")) { diff --git a/t/t6007-rev-list-cherry-pick-file.sh b/t/t6007-rev-list-cherry-pick-file.sh index 3faeae6c01..4b8611ce20 100755 --- a/t/t6007-rev-list-cherry-pick-file.sh +++ b/t/t6007-rev-list-cherry-pick-file.sh @@ -40,4 +40,18 @@ test_expect_success '--cherry-pick bar does not come up empty' ' ! test -z "$(git rev-list --left-right --cherry-pick B...C -- bar)" ' +test_expect_success '--cherry-pick with independent, but identical branches' ' + git symbolic-ref HEAD refs/heads/independent && + rm .git/index && + echo Hallo > foo && + git add foo && + test_tick && + git commit -m "independent" && + echo Bello > foo && + test_tick && + git commit -m "independent, too" foo && + test -z "$(git rev-list --left-right --cherry-pick \ + HEAD...master -- foo)" +' + test_done From 971aa71fc695e0b56ffe2172543a126d20b16842 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Thu, 30 Aug 2007 22:49:33 -0400 Subject: [PATCH 63/94] user-manual: adjust section levels in "git internals" The descriptions of the various object types should all be a subsection of the "Object Database" section. I cribbed most of this chapter from the README (now core-intro.txt and git(7)), because there's stuff in there people need to know and I was too lazy to rewrite it. The audience isn't quite right, though--the chapter is a mixture of user- and developer- level documentation that isn't as appropriate now as it was originally. So, reserve this chapter for stuff users need to know, and move the source code introduction into a new "git hacking" chapter where we'll also move any hacker-only technical details. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 35298e626b..75f23709f8 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2787,7 +2787,7 @@ The object types in some more detail: [[blob-object]] Blob Object ------------ +~~~~~~~~~~~ A "blob" object is nothing but a binary blob of data, and doesn't refer to anything else. There is no signature or any other @@ -2809,7 +2809,7 @@ is run, and its data can be accessed by gitlink:git-cat-file[1]. [[tree-object]] Tree Object ------------ +~~~~~~~~~~~ The next hierarchical object type is the "tree" object. A tree object is a list of mode/name/blob data, sorted by name. Alternatively, the @@ -2851,7 +2851,7 @@ Two trees can be compared with gitlink:git-diff-tree[1]. [[commit-object]] Commit Object -------------- +~~~~~~~~~~~~~ The "commit" object is an object that introduces the notion of history into the picture. In contrast to the other objects, it @@ -2878,7 +2878,7 @@ its data can be accessed by gitlink:git-cat-file[1]. [[trust]] Trust ------ +~~~~~ An aside on the notion of "trust". Trust is really outside the scope of "git", but it's worth noting a few things. First off, since @@ -2908,7 +2908,7 @@ To assist in this, git also provides the tag object... [[tag-object]] Tag Object ----------- +~~~~~~~~~~ Git provides the "tag" object to simplify creating, managing and exchanging symbolic and signed tokens. The "tag" object at its @@ -3474,6 +3474,13 @@ confusing and scary messages, but it won't actually do anything bad. In contrast, running "git prune" while somebody is actively changing the repository is a *BAD* idea). +[[hacking-git]] +Hacking git +=========== + +This chapter covers internal details of the git implementation which +probably only git developers need to understand. + [[birdview-on-the-source-code]] A birds-eye view of Git's source code ------------------------------------- From f2327c6c52d4d523312dc32c143d2c29131ea24e Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Thu, 30 Aug 2007 23:07:05 -0400 Subject: [PATCH 64/94] user-manual: move object format details to hacking-git chapter Most of this is probably only of interest to git developers. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 55 ++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 75f23709f8..f7457ef487 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2760,29 +2760,6 @@ used to sign other objects. It contains the identifier and type of another object, a symbolic name (of course!) and, optionally, a signature. -Regardless of object type, all objects share the following -characteristics: they are all deflated with zlib, and have a header -that not only specifies their type, but also provides size information -about the data in the object. It's worth noting that the SHA1 hash -that is used to name the object is the hash of the original data -plus this header, so `sha1sum` 'file' does not match the object name -for 'file'. -(Historical note: in the dawn of the age of git the hash -was the sha1 of the 'compressed' object.) - -As a result, the general consistency of an object can always be tested -independently of the contents or the type of the object: all objects can -be validated by verifying that (a) their hashes match the content of the -file and (b) the object successfully inflates to a stream of bytes that -forms a sequence of {plus} {plus} {plus} {plus} . - -The structured objects can further have their structure and -connectivity to other objects verified. This is generally done with -the `git-fsck` program, which generates a full dependency graph -of all objects, and verifies their internal consistency (in addition -to just verifying their superficial consistency through the hash). - The object types in some more detail: [[blob-object]] @@ -3481,6 +3458,38 @@ Hacking git This chapter covers internal details of the git implementation which probably only git developers need to understand. +[[object-details]] +Object storage format +--------------------- + +All objects have a statically determined "type" which identifies the +format of the object (i.e. how it is used, and how it can refer to other +objects). There are currently four different object types: "blob", +"tree", "commit", and "tag". + +Regardless of object type, all objects share the following +characteristics: they are all deflated with zlib, and have a header +that not only specifies their type, but also provides size information +about the data in the object. It's worth noting that the SHA1 hash +that is used to name the object is the hash of the original data +plus this header, so `sha1sum` 'file' does not match the object name +for 'file'. +(Historical note: in the dawn of the age of git the hash +was the sha1 of the 'compressed' object.) + +As a result, the general consistency of an object can always be tested +independently of the contents or the type of the object: all objects can +be validated by verifying that (a) their hashes match the content of the +file and (b) the object successfully inflates to a stream of bytes that +forms a sequence of {plus} {plus} {plus} {plus} . + +The structured objects can further have their structure and +connectivity to other objects verified. This is generally done with +the `git-fsck` program, which generates a full dependency graph +of all objects, and verifies their internal consistency (in addition +to just verifying their superficial consistency through the hash). + [[birdview-on-the-source-code]] A birds-eye view of Git's source code ------------------------------------- From 036f81997c3ed144236a2aa7bb546df1a87f0c81 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Thu, 30 Aug 2007 23:10:05 -0400 Subject: [PATCH 65/94] user-manual: rename "git internals" to "git concepts" "git internals" sounds like something only git developers must know about, but this stuff should be of wider interest. Rename the chapter and give it a slightly friendlier introduction. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index f7457ef487..09d01817c2 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -182,7 +182,7 @@ has that commit at all). Since the object name is computed as a hash over the contents of the commit, you are guaranteed that the commit can never change without its name also changing. -In fact, in <> we shall see that everything stored in git +In fact, in <> we shall see that everything stored in git history, including file data and directory contents, is stored in an object with a name that is a hash of its contents. @@ -2708,12 +2708,16 @@ See gitlink:git-config[1] for more details on the configuration options mentioned above. -[[git-internals]] -Git internals -============= +[[git-concepts]] +Git concepts +============ -Git depends on two fundamental abstractions: the "object database", and -the "current directory cache" aka "index". +Git is built on a small number of simple but powerful ideas. While it +is possible to get things done without understanding them, you will find +git much more intuitive if you do. + +We start with the most important, the <> and the <>. [[the-object-database]] The Object Database From 1c6045fffa55ee314717e26756182562e45976e6 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Mon, 3 Sep 2007 11:27:56 -0400 Subject: [PATCH 66/94] user-manual: create new "low-level git operations" chapter The low-level index operations aren't as important to regular users as the rest of this "git concepts" chapter; so move it into a separate chapter, and do some minor cleanup. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 09d01817c2..e613ba8b83 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2963,29 +2963,41 @@ instantiated. So the index can be thought of as a write-back cache, which can contain dirty information that has not yet been written back to the backing store. +[[low-level-operations]] +Low-level git operations +======================== +Many of the higher-level commands were originally implemented as shell +scripts using a smaller core of low-level git commands. These can still +be useful when doing unusual things with git, or just as a way to +understand its inner workings. [[the-workflow]] The Workflow ------------ +High-level operations such as gitlink:git-commit[1], +gitlink:git-checkout[1] and git-reset[1] work by moving data between the +working tree, the index, and the object database. Git provides +low-level operations which perform each of these steps individually. + Generally, all "git" operations work on the index file. Some operations work *purely* on the index file (showing the current state of the -index), but most operations move data to and from the index file. Either -from the database or from the working directory. Thus there are four -main combinations: +index), but most operations move data between the index file and either +the database or the working directory. Thus there are four main +combinations: [[working-directory-to-index]] working directory -> index ~~~~~~~~~~~~~~~~~~~~~~~~~~ -You update the index with information from the working directory with -the gitlink:git-update-index[1] command. You -generally update the index information by just specifying the filename -you want to update, like so: +The gitlink:git-update-index[1] command updates the index with +information from the working directory. You generally update the +index information by just specifying the filename you want to update, +like so: ------------------------------------------------- -$ git-update-index filename +$ git update-index filename ------------------------------------------------- but to avoid common mistakes with filename globbing etc, the command @@ -3009,6 +3021,9 @@ stat information. It will 'not' update the object status itself, and it will only update the fields that are used to quickly test whether an object still matches its old backing store object. +The previously introduced gitlink:git-add[1] is just a wrapper for +gitlink:git-update-index[1]. + [[index-to-object-database]] index -> object database ~~~~~~~~~~~~~~~~~~~~~~~~ @@ -3016,7 +3031,7 @@ index -> object database You write your current index file to a "tree" object with the program ------------------------------------------------- -$ git-write-tree +$ git write-tree ------------------------------------------------- that doesn't come with any options - it will just write out the From 1c097891e49042cf7ee4628a58836625fb65016d Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Mon, 3 Sep 2007 12:59:55 -0400 Subject: [PATCH 67/94] user-manual: rewrite index discussion Add an example using git-ls-files, standardize on the new "index" terminology (as opposed to "cache"), attempt to clarify discussion and make it a little shorter, avoid some unnecessary jargon ("write-back cache"). Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 104 ++++++++++++++++++---------------- 1 file changed, 55 insertions(+), 49 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index e613ba8b83..065b1cc416 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2911,57 +2911,63 @@ gitlink:git-verify-tag[1]. [[the-index]] -The "index" aka "Current Directory Cache" ------------------------------------------ +The index +----------- + +The index is a binary file (generally kept in .git/index) containing a +sorted list of path names, each with permissions and the SHA1 of a blob +object; gitlink:git-ls-files[1] can show you the contents of the index: -The index is a simple binary file, which contains an efficient -representation of the contents of a virtual directory. It -does so by a simple array that associates a set of names, dates, -permissions and content (aka "blob") objects together. The cache is -always kept ordered by name, and names are unique (with a few very -specific rules) at any point in time, but the cache has no long-term -meaning, and can be partially updated at any time. - -In particular, the index certainly does not need to be consistent with -the current directory contents (in fact, most operations will depend on -different ways to make the index 'not' be consistent with the directory -hierarchy), but it has three very important attributes: - -'(a) it can re-generate the full state it caches (not just the -directory structure: it contains pointers to the "blob" objects so -that it can regenerate the data too)' - -As a special case, there is a clear and unambiguous one-way mapping -from a current directory cache to a "tree object", which can be -efficiently created from just the current directory cache without -actually looking at any other data. So a directory cache at any one -time uniquely specifies one and only one "tree" object (but has -additional data to make it easy to match up that tree object with what -has happened in the directory) - -'(b) it has efficient methods for finding inconsistencies between that -cached state ("tree object waiting to be instantiated") and the -current state.' - -'(c) it can additionally efficiently represent information about merge -conflicts between different tree objects, allowing each pathname to be +------------------------------------------------- +$ git ls-files --stage +100644 63c918c667fa005ff12ad89437f2fdc80926e21c 0 .gitignore +100644 5529b198e8d14decbe4ad99db3f7fb632de0439d 0 .mailmap +100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0 COPYING +100644 a37b2152bd26be2c2289e1f57a292534a51a93c7 0 Documentation/.gitignore +100644 fbefe9a45b00a54b58d94d06eca48b03d40a50e0 0 Documentation/Makefile +... +100644 2511aef8d89ab52be5ec6a5e46236b4b6bcd07ea 0 xdiff/xtypes.h +100644 2ade97b2574a9f77e7ae4002a4e07a6a38e46d07 0 xdiff/xutils.c +100644 d5de8292e05e7c36c4b68857c1cf9855e3d2f70a 0 xdiff/xutils.h +------------------------------------------------- + +Note that in older documentation you may see the index called the +"current directory cache" or just the "cache". It has three important +properties: + +1. The index contains all the information necessary to generate a single +(uniquely determined) tree object. ++ +For example, running gitlink:git-commit[1] generates this tree object +from the index, stores it in the object database, and uses it as the +tree object associated with the new commit. + +2. The index enables fast comparisons between the tree object it defines +and the working tree. ++ +It does this by storing some additional data for each entry (such as +the last modified time). This data is not displayed above, and is not +stored in the created tree object, but it can be used to determine +quickly which files in the working directory differ from what was +stored in the index, and thus save git from having to read all of the +data from such files to look for changes. + +3. It can efficiently represent information about merge conflicts +between different tree objects, allowing each pathname to be associated with sufficient information about the trees involved that -you can create a three-way merge between them.' - -Those are the ONLY three things that the directory cache does. It's a -cache, and the normal operation is to re-generate it completely from a -known tree object, or update/compare it with a live tree that is being -developed. If you blow the directory cache away entirely, you generally -haven't lost any information as long as you have the name of the tree -that it described. - -At the same time, the index is also the staging area for creating -new trees, and creating a new tree always involves a controlled -modification of the index file. In particular, the index file can -have the representation of an intermediate tree that has not yet been -instantiated. So the index can be thought of as a write-back cache, -which can contain dirty information that has not yet been written back -to the backing store. +you can create a three-way merge between them. ++ +We saw in <> that during a merge the index can +store multiple versions of a single file (called "stages"). The third +column in the gitlink:git-ls-files[1] output above is the stage +number, and will take on values other than 0 for files with merge +conflicts. + +The index is thus a sort of temporary staging area, which is filled with +a tree which you are in the process of working on. + +If you blow the index away entirely, you generally haven't lost any +information as long as you have the name of the tree that it described. [[low-level-operations]] Low-level git operations From 513d419c5989b8aaeec1cb1ed356519370079dc1 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Fri, 31 Aug 2007 23:26:38 -0400 Subject: [PATCH 68/94] user-manual: reorder commit, blob, tree discussion The bottom-up blog, tree, commit order makes sense unless you want to give explicit examples--it's easier to discover objects to examine if you go in the other order...., Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 82 +++++++++++++++++------------------ 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 065b1cc416..223ec75914 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2766,27 +2766,32 @@ signature. The object types in some more detail: -[[blob-object]] -Blob Object -~~~~~~~~~~~ +[[commit-object]] +Commit Object +~~~~~~~~~~~~~ -A "blob" object is nothing but a binary blob of data, and doesn't -refer to anything else. There is no signature or any other -verification of the data, so while the object is consistent (it 'is' -indexed by its sha1 hash, so the data itself is certainly correct), it -has absolutely no other attributes. No name associations, no -permissions. It is purely a blob of data (i.e. normally "file -contents"). +The "commit" object is an object that introduces the notion of +history into the picture. In contrast to the other objects, it +doesn't just describe the physical state of a tree, it describes how +we got there, and why. -In particular, since the blob is entirely defined by its data, if two -files in a directory tree (or in multiple different versions of the -repository) have the same contents, they will share the same blob -object. The object is totally independent of its location in the -directory tree, and renaming a file does not change the object that -file is associated with in any way. +A "commit" is defined by the tree-object that it results in, the +parent commits (zero, one or more) that led up to that point, and a +comment on what happened. Again, a commit is not trusted per se: +the contents are well-defined and "safe" due to the cryptographically +strong signatures at all levels, but there is no reason to believe +that the tree is "good" or that the merge information makes sense. +The parents do not have to actually have any relationship with the +result, for example. -A blob is typically created when gitlink:git-update-index[1] -is run, and its data can be accessed by gitlink:git-cat-file[1]. +Note on commits: unlike some SCM's, commits do not contain +rename information or file mode change information. All of that is +implicit in the trees involved (the result tree, and the result trees +of the parents), and describing that makes no sense in this idiotic +file manager. + +A commit is created with gitlink:git-commit-tree[1] and +its data can be accessed by gitlink:git-cat-file[1]. [[tree-object]] Tree Object @@ -2830,32 +2835,27 @@ A tree is created with gitlink:git-write-tree[1] and its data can be accessed by gitlink:git-ls-tree[1]. Two trees can be compared with gitlink:git-diff-tree[1]. -[[commit-object]] -Commit Object -~~~~~~~~~~~~~ - -The "commit" object is an object that introduces the notion of -history into the picture. In contrast to the other objects, it -doesn't just describe the physical state of a tree, it describes how -we got there, and why. +[[blob-object]] +Blob Object +~~~~~~~~~~~ -A "commit" is defined by the tree-object that it results in, the -parent commits (zero, one or more) that led up to that point, and a -comment on what happened. Again, a commit is not trusted per se: -the contents are well-defined and "safe" due to the cryptographically -strong signatures at all levels, but there is no reason to believe -that the tree is "good" or that the merge information makes sense. -The parents do not have to actually have any relationship with the -result, for example. +A "blob" object is nothing but a binary blob of data, and doesn't +refer to anything else. There is no signature or any other +verification of the data, so while the object is consistent (it 'is' +indexed by its sha1 hash, so the data itself is certainly correct), it +has absolutely no other attributes. No name associations, no +permissions. It is purely a blob of data (i.e. normally "file +contents"). -Note on commits: unlike some SCM's, commits do not contain -rename information or file mode change information. All of that is -implicit in the trees involved (the result tree, and the result trees -of the parents), and describing that makes no sense in this idiotic -file manager. +In particular, since the blob is entirely defined by its data, if two +files in a directory tree (or in multiple different versions of the +repository) have the same contents, they will share the same blob +object. The object is totally independent of its location in the +directory tree, and renaming a file does not change the object that +file is associated with in any way. -A commit is created with gitlink:git-commit-tree[1] and -its data can be accessed by gitlink:git-cat-file[1]. +A blob is typically created when gitlink:git-update-index[1] +is run, and its data can be accessed by gitlink:git-cat-file[1]. [[trust]] Trust From 1bbf1c7900337a646b6ca65c8b3505e784012f39 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sun, 10 Jun 2007 15:15:08 -0400 Subject: [PATCH 69/94] user-manual: rewrite object database discussion Rewrite the introduction. Rewrite each section completely to make them work in the new order, to add some examples, and to move plumbing commands (like git-commit-tree) to the following chapter. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 335 ++++++++++++++++++++-------------- 1 file changed, 196 insertions(+), 139 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 223ec75914..4fb2f30efb 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2723,46 +2723,44 @@ database>> and the <>. The Object Database ------------------- -The object database is literally just a content-addressable collection -of objects. All objects are named by their content, which is -approximated by the SHA1 hash of the object itself. Objects may refer -to other objects (by referencing their SHA1 hash), and so you can -build up a hierarchy of objects. - -All objects have a statically determined "type" which is -determined at object creation time, and which identifies the format of -the object (i.e. how it is used, and how it can refer to other -objects). There are currently four different object types: "blob", -"tree", "commit", and "tag". -A <> cannot refer to any other object, -and is, as the name implies, a pure storage object containing some -user data. It is used to actually store the file data, i.e. a blob -object is associated with some particular version of some file. - -A <> is an object that ties one or more -"blob" objects into a directory structure. In addition, a tree object -can refer to other tree objects, thus creating a directory hierarchy. - -A <> ties such directory hierarchies -together into a <> of revisions - each -"commit" is associated with exactly one tree (the directory hierarchy at -the time of the commit). In addition, a "commit" refers to one or more -"parent" commit objects that describe the history of how we arrived at -that directory hierarchy. - -As a special case, a commit object with no parents is called the "root" -commit, and is the point of an initial project commit. Each project -must have at least one root, and while you can tie several different -root objects together into one project by creating a commit object which -has two or more separate roots as its ultimate parents, that's probably -just going to confuse people. So aim for the notion of "one root object -per project", even if git itself does not enforce that. - -A <> symbolically identifies and can be -used to sign other objects. It contains the identifier and type of -another object, a symbolic name (of course!) and, optionally, a -signature. +We already saw in <> that all commits are stored +under a 40-digit "object name". In fact, all the information needed to +represent the history of a project is stored in objects with such names. +In each case the name is calculated by taking the SHA1 hash of the +contents of the object. The SHA1 hash is a cryptographic hash function. +What that means to us is that it is impossible to find two different +objects with the same name. This has a number of advantages; among +others: + +- Git can quickly determine whether two objects are identical or not, + just by comparing names. +- Since object names are computed the same way in ever repository, the + same content stored in two repositories will always be stored under + the same name. +- Git can detect errors when it reads an object, by checking that the + object's name is still the SHA1 hash of its contents. + +(See <> for the details of the object formatting and +SHA1 calculation.) + +There are four different types of objects: "blob", "tree", "commit", and +"tag". + +- A <> is used to store file data. +- A <> is an object that ties one or more + "blob" objects into a directory structure. In addition, a tree object + can refer to other tree objects, thus creating a directory hierarchy. +- A <> ties such directory hierarchies + together into a <> of revisions - each + commit contains the object name of exactly one tree designating the + directory hierarchy at the time of the commit. In addition, a commit + refers to "parent" commit objects that describe the history of how we + arrived at that directory hierarchy. +- A <> symbolically identifies and can be + used to sign other objects. It contains the object name and type of + another object, a symbolic name (of course!) and, optionally, a + signature. The object types in some more detail: @@ -2770,109 +2768,142 @@ The object types in some more detail: Commit Object ~~~~~~~~~~~~~ -The "commit" object is an object that introduces the notion of -history into the picture. In contrast to the other objects, it -doesn't just describe the physical state of a tree, it describes how -we got there, and why. - -A "commit" is defined by the tree-object that it results in, the -parent commits (zero, one or more) that led up to that point, and a -comment on what happened. Again, a commit is not trusted per se: -the contents are well-defined and "safe" due to the cryptographically -strong signatures at all levels, but there is no reason to believe -that the tree is "good" or that the merge information makes sense. -The parents do not have to actually have any relationship with the -result, for example. - -Note on commits: unlike some SCM's, commits do not contain -rename information or file mode change information. All of that is -implicit in the trees involved (the result tree, and the result trees -of the parents), and describing that makes no sense in this idiotic -file manager. - -A commit is created with gitlink:git-commit-tree[1] and -its data can be accessed by gitlink:git-cat-file[1]. +The "commit" object links a physical state of a tree with a description +of how we got there and why. Use the --pretty=raw option to +gitlink:git-show[1] or gitlink:git-log[1] to examine your favorite +commit: + +------------------------------------------------ +$ git show -s --pretty=raw 2be7fcb476 +commit 2be7fcb4764f2dbcee52635b91fedb1b3dcf7ab4 +tree fb3a8bdd0ceddd019615af4d57a53f43d8cee2bf +parent 257a84d9d02e90447b149af58b271c19405edb6a +author Dave Watson 1187576872 -0400 +committer Junio C Hamano 1187591163 -0700 + + Fix misspelling of 'suppress' in docs + + Signed-off-by: Junio C Hamano +------------------------------------------------ + +As you can see, a commit is defined by: + +- a tree: The SHA1 name of a tree object (as defined below), representing + the contents of a directory at a certain point in time. +- parent(s): The SHA1 name of some number of commits which represent the + immediately prevoius step(s) in the history of the project. The + example above has one parent; merge commits may have more than + one. A commit with no parents is called a "root" commit, and + represents the initial revision of a project. Each project must have + at least one root. A project can also have multiple roots, though + that isn't common (or necessarily a good idea). +- an author: The name of the person responsible for this change, together + with its date. +- a committer: The name of the person who actually created the commit, + with the date it was done. This may be different from the author, for + example, if the author was someone who wrote a patch and emailed it + to the person who used it to create the commit. +- a comment describing this commit. + +Note that a commit does not itself contain any information about what +actually changed; all changes are calculated by comparing the contents +of the tree referred to by this commit with the trees associated with +its parents. In particular, git does not attempt to record file renames +explicitly, though it can identify cases where the existence of the same +file data at changing paths suggests a rename. (See, for example, the +-M option to gitlink:git-diff[1]). + +A commit is usually created by gitlink:git-commit[1], which creates a +commit whose parent is normally the current HEAD, and whose tree is +taken from the content currently stored in the index. [[tree-object]] Tree Object ~~~~~~~~~~~ -The next hierarchical object type is the "tree" object. A tree object -is a list of mode/name/blob data, sorted by name. Alternatively, the -mode data may specify a directory mode, in which case instead of -naming a blob, that name is associated with another TREE object. - -Like the "blob" object, a tree object is uniquely determined by the -set contents, and so two separate but identical trees will always -share the exact same object. This is true at all levels, i.e. it's -true for a "leaf" tree (which does not refer to any other trees, only -blobs) as well as for a whole subdirectory. - -For that reason a "tree" object is just a pure data abstraction: it -has no history, no signatures, no verification of validity, except -that since the contents are again protected by the hash itself, we can -trust that the tree is immutable and its contents never change. - -So you can trust the contents of a tree to be valid, the same way you -can trust the contents of a blob, but you don't know where those -contents 'came' from. - -Side note on trees: since a "tree" object is a sorted list of -"filename+content", you can create a diff between two trees without -actually having to unpack two trees. Just ignore all common parts, -and your diff will look right. In other words, you can effectively -(and efficiently) tell the difference between any two random trees by -O(n) where "n" is the size of the difference, rather than the size of -the tree. - -Side note 2 on trees: since the name of a "blob" depends entirely and -exclusively on its contents (i.e. there are no names or permissions -involved), you can see trivial renames or permission changes by -noticing that the blob stayed the same. However, renames with data -changes need a smarter "diff" implementation. - -A tree is created with gitlink:git-write-tree[1] and -its data can be accessed by gitlink:git-ls-tree[1]. -Two trees can be compared with gitlink:git-diff-tree[1]. +The ever-versatile gitlink:git-show[1] command can also be used to +examine tree objects, but gitlink:git-ls-tree[1] will give you more +details: + +------------------------------------------------ +$ git ls-tree fb3a8bdd0ce +100644 blob 63c918c667fa005ff12ad89437f2fdc80926e21c .gitignore +100644 blob 5529b198e8d14decbe4ad99db3f7fb632de0439d .mailmap +100644 blob 6ff87c4664981e4397625791c8ea3bbb5f2279a3 COPYING +040000 tree 2fb783e477100ce076f6bf57e4a6f026013dc745 Documentation +100755 blob 3c0032cec592a765692234f1cba47dfdcc3a9200 GIT-VERSION-GEN +100644 blob 289b046a443c0647624607d471289b2c7dcd470b INSTALL +100644 blob 4eb463797adc693dc168b926b6932ff53f17d0b1 Makefile +100644 blob 548142c327a6790ff8821d67c2ee1eff7a656b52 README +... +------------------------------------------------ + +As you can see, a tree object contains a list of entries, each with a +mode, object type, SHA1 name, and name, sorted by name. It represents +the contents of a single directory tree. + +The object type may be a blob, representing the contents of a file, or +another tree, representing the contents of a subdirectory. Since trees +and blobs, like all other objects, are named by the SHA1 hash of their +contents, two trees have the same SHA1 name if and only if their +contents (including, recursively, the contents of all subdirectories) +are identical. This allows git to quickly determine the differences +between two related tree objects, since it can ignore any entries with +identical object names. + +(Note: in the presence of submodules, trees may also have commits as +entries. See gitlink:git-submodule[1] and gitlink:gitmodules.txt[1] +for partial documentation.) + +Note that the files all have mode 644 or 755: git actually only pays +attention to the executable bit. [[blob-object]] Blob Object ~~~~~~~~~~~ -A "blob" object is nothing but a binary blob of data, and doesn't -refer to anything else. There is no signature or any other -verification of the data, so while the object is consistent (it 'is' -indexed by its sha1 hash, so the data itself is certainly correct), it -has absolutely no other attributes. No name associations, no -permissions. It is purely a blob of data (i.e. normally "file -contents"). +You can use gitlink:git-show[1] to examine the contents of a blob; take, +for example, the blob in the entry for "COPYING" from the tree above: + +------------------------------------------------ +$ git show 6ff87c4664 + + Note that the only valid version of the GPL as far as this project + is concerned is _this_ particular version of the license (ie v2, not + v2.2 or v3.x or whatever), unless explicitly otherwise stated. +... +------------------------------------------------ -In particular, since the blob is entirely defined by its data, if two -files in a directory tree (or in multiple different versions of the -repository) have the same contents, they will share the same blob -object. The object is totally independent of its location in the -directory tree, and renaming a file does not change the object that -file is associated with in any way. +A "blob" object is nothing but a binary blob of data. It doesn't refer +to anything else or have attributes of any kind. -A blob is typically created when gitlink:git-update-index[1] -is run, and its data can be accessed by gitlink:git-cat-file[1]. +Since the blob is entirely defined by its data, if two files in a +directory tree (or in multiple different versions of the repository) +have the same contents, they will share the same blob object. The object +is totally independent of its location in the directory tree, and +renaming a file does not change the object that file is associated with. + +Note that any tree or blob object can be examined using +gitlink:git-show[1] with the : syntax. This can +sometimes be useful for browsing the contents of a tree that is not +currently checked out. [[trust]] Trust ~~~~~ -An aside on the notion of "trust". Trust is really outside the scope -of "git", but it's worth noting a few things. First off, since -everything is hashed with SHA1, you 'can' trust that an object is -intact and has not been messed with by external sources. So the name -of an object uniquely identifies a known state - just not a state that -you may want to trust. +If you receive the SHA1 name of a blob from one source, and its contents +from another (possibly untrusted) source, you can still trust that those +contents are correct as long as the SHA1 name agrees. This is because +the SHA1 is designed so that it is infeasible to find different contents +that produce the same hash. -Furthermore, since the SHA1 signature of a commit refers to the -SHA1 signatures of the tree it is associated with and the signatures -of the parent, a single named commit specifies uniquely a whole set -of history, with full contents. You can't later fake any step of the -way once you have the name of a commit. +Similarly, you need only trust the SHA1 name of a top-level tree object +to trust the contents of the entire directory that it refers to, and if +you receive the SHA1 name of a commit from a trusted source, then you +can easily verify the entire history of commits reachable through +parents of that commit, and all of those contents of the trees referred +to by those commits. So to introduce some real trust in the system, the only thing you need to do is to digitally sign just 'one' special note, which includes the @@ -2891,23 +2922,31 @@ To assist in this, git also provides the tag object... Tag Object ~~~~~~~~~~ -Git provides the "tag" object to simplify creating, managing and -exchanging symbolic and signed tokens. The "tag" object at its -simplest simply symbolically identifies another object by containing -the sha1, type and symbolic name. - -However it can optionally contain additional signature information -(which git doesn't care about as long as there's less than 8k of -it). This can then be verified externally to git. +A tag object contains an object, object type, tag name, the name of the +person ("tagger") who created the tag, and a message, which may contain +a signature, as can be seen using the gitlink:git-cat-file[1]: -Note that despite the tag features, "git" itself only handles content -integrity; the trust framework (and signature provision and -verification) has to come from outside. +------------------------------------------------ +$ git cat-file tag v1.5.0 +object 437b1b20df4b356c9342dac8d38849f24ef44f27 +type commit +tag v1.5.0 +tagger Junio C Hamano 1171411200 +0000 + +GIT 1.5.0 +-----BEGIN PGP SIGNATURE----- +Version: GnuPG v1.4.6 (GNU/Linux) + +iD8DBQBF0lGqwMbZpPMRm5oRAuRiAJ9ohBLd7s2kqjkKlq1qqC57SbnmzQCdG4ui +nLE/L9aUXdWeTFPron96DLA= +=2E+0 +-----END PGP SIGNATURE----- +------------------------------------------------ -A tag is created with gitlink:git-mktag[1], -its data can be accessed by gitlink:git-cat-file[1], -and the signature can be verified by -gitlink:git-verify-tag[1]. +See the gitlink:git-tag[1] command to learn how to create and verify tag +objects. (Note that gitlink:git-tag[1] can also be used to create +"lightweight tags", which are not tag objects at all, but just simple +references in .git/refs/tags/). [[the-index]] @@ -2978,6 +3017,24 @@ scripts using a smaller core of low-level git commands. These can still be useful when doing unusual things with git, or just as a way to understand its inner workings. +[[object-manipulation]] +Object access and manipulation +------------------------------ + +The gitlink:git-cat-file[1] command can show the contents of any object, +though the higher-level gitlink:git-show[1] is usually more useful. + +The gitlink:git-commit-tree[1] command allows constructing commits with +arbitrary parents and trees. + +A tree can be created with gitlink:git-write-tree[1] and its data can be +accessed by gitlink:git-ls-tree[1]. Two trees can be compared with +gitlink:git-diff-tree[1]. + +A tag is created with gitlink:git-mktag[1], and the signature can be +verified by gitlink:git-verify-tag[1], though it is normally simpler to +use gitlink:git-tag[1] for both. + [[the-workflow]] The Workflow ------------ From 09eff7b0f7c1f55f8714f19c5d87bbd92ddee453 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sat, 8 Sep 2007 22:13:53 -0400 Subject: [PATCH 70/94] user-manual: move packfile and dangling object discussion The discussions of packfiles and dangling objects both belong in the object database section. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 295 +++++++++++++++++----------------- 1 file changed, 147 insertions(+), 148 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 4fb2f30efb..4a0fa7e958 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2948,6 +2948,153 @@ objects. (Note that gitlink:git-tag[1] can also be used to create "lightweight tags", which are not tag objects at all, but just simple references in .git/refs/tags/). +[[pack-files]] +How git stores objects efficiently: pack files +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +We've seen how git stores each object in a file named after the +object's SHA1 hash. + +Unfortunately this system becomes inefficient once a project has a +lot of objects. Try this on an old project: + +------------------------------------------------ +$ git count-objects +6930 objects, 47620 kilobytes +------------------------------------------------ + +The first number is the number of objects which are kept in +individual files. The second is the amount of space taken up by +those "loose" objects. + +You can save space and make git faster by moving these loose objects in +to a "pack file", which stores a group of objects in an efficient +compressed format; the details of how pack files are formatted can be +found in link:technical/pack-format.txt[technical/pack-format.txt]. + +To put the loose objects into a pack, just run git repack: + +------------------------------------------------ +$ git repack +Generating pack... +Done counting 6020 objects. +Deltifying 6020 objects. + 100% (6020/6020) done +Writing 6020 objects. + 100% (6020/6020) done +Total 6020, written 6020 (delta 4070), reused 0 (delta 0) +Pack pack-3e54ad29d5b2e05838c75df582c65257b8d08e1c created. +------------------------------------------------ + +You can then run + +------------------------------------------------ +$ git prune +------------------------------------------------ + +to remove any of the "loose" objects that are now contained in the +pack. This will also remove any unreferenced objects (which may be +created when, for example, you use "git reset" to remove a commit). +You can verify that the loose objects are gone by looking at the +.git/objects directory or by running + +------------------------------------------------ +$ git count-objects +0 objects, 0 kilobytes +------------------------------------------------ + +Although the object files are gone, any commands that refer to those +objects will work exactly as they did before. + +The gitlink:git-gc[1] command performs packing, pruning, and more for +you, so is normally the only high-level command you need. + +[[dangling-objects]] +Dangling objects +~~~~~~~~~~~~~~~~ + +The gitlink:git-fsck[1] command will sometimes complain about dangling +objects. They are not a problem. + +The most common cause of dangling objects is that you've rebased a +branch, or you have pulled from somebody else who rebased a branch--see +<>. In that case, the old head of the original +branch still exists, as does everything it pointed to. The branch +pointer itself just doesn't, since you replaced it with another one. + +There are also other situations that cause dangling objects. For +example, a "dangling blob" may arise because you did a "git add" of a +file, but then, before you actually committed it and made it part of the +bigger picture, you changed something else in that file and committed +that *updated* thing - the old state that you added originally ends up +not being pointed to by any commit or tree, so it's now a dangling blob +object. + +Similarly, when the "recursive" merge strategy runs, and finds that +there are criss-cross merges and thus more than one merge base (which is +fairly unusual, but it does happen), it will generate one temporary +midway tree (or possibly even more, if you had lots of criss-crossing +merges and more than two merge bases) as a temporary internal merge +base, and again, those are real objects, but the end result will not end +up pointing to them, so they end up "dangling" in your repository. + +Generally, dangling objects aren't anything to worry about. They can +even be very useful: if you screw something up, the dangling objects can +be how you recover your old tree (say, you did a rebase, and realized +that you really didn't want to - you can look at what dangling objects +you have, and decide to reset your head to some old dangling state). + +For commits, you can just use: + +------------------------------------------------ +$ gitk --not --all +------------------------------------------------ + +This asks for all the history reachable from the given commit but not +from any branch, tag, or other reference. If you decide it's something +you want, you can always create a new reference to it, e.g., + +------------------------------------------------ +$ git branch recovered-branch +------------------------------------------------ + +For blobs and trees, you can't do the same, but you can still examine +them. You can just do + +------------------------------------------------ +$ git show +------------------------------------------------ + +to show what the contents of the blob were (or, for a tree, basically +what the "ls" for that directory was), and that may give you some idea +of what the operation was that left that dangling object. + +Usually, dangling blobs and trees aren't very interesting. They're +almost always the result of either being a half-way mergebase (the blob +will often even have the conflict markers from a merge in it, if you +have had conflicting merges that you fixed up by hand), or simply +because you interrupted a "git fetch" with ^C or something like that, +leaving _some_ of the new objects in the object database, but just +dangling and useless. + +Anyway, once you are sure that you're not interested in any dangling +state, you can just prune all unreachable objects: + +------------------------------------------------ +$ git prune +------------------------------------------------ + +and they'll be gone. But you should only run "git prune" on a quiescent +repository - it's kind of like doing a filesystem fsck recovery: you +don't want to do that while the filesystem is mounted. + +(The same is true of "git-fsck" itself, btw - but since +git-fsck never actually *changes* the repository, it just reports +on what it found, git-fsck itself is never "dangerous" to run. +Running it while somebody is actually changing the repository can cause +confusing and scary messages, but it won't actually do anything bad. In +contrast, running "git prune" while somebody is actively changing the +repository is a *BAD* idea). [[the-index]] The index @@ -3385,154 +3532,6 @@ $ git-merge-index git-merge-one-file hello.c and that is what higher level `git merge -s resolve` is implemented with. -[[pack-files]] -How git stores objects efficiently: pack files ----------------------------------------------- - -We've seen how git stores each object in a file named after the -object's SHA1 hash. - -Unfortunately this system becomes inefficient once a project has a -lot of objects. Try this on an old project: - ------------------------------------------------- -$ git count-objects -6930 objects, 47620 kilobytes ------------------------------------------------- - -The first number is the number of objects which are kept in -individual files. The second is the amount of space taken up by -those "loose" objects. - -You can save space and make git faster by moving these loose objects in -to a "pack file", which stores a group of objects in an efficient -compressed format; the details of how pack files are formatted can be -found in link:technical/pack-format.txt[technical/pack-format.txt]. - -To put the loose objects into a pack, just run git repack: - ------------------------------------------------- -$ git repack -Generating pack... -Done counting 6020 objects. -Deltifying 6020 objects. - 100% (6020/6020) done -Writing 6020 objects. - 100% (6020/6020) done -Total 6020, written 6020 (delta 4070), reused 0 (delta 0) -Pack pack-3e54ad29d5b2e05838c75df582c65257b8d08e1c created. ------------------------------------------------- - -You can then run - ------------------------------------------------- -$ git prune ------------------------------------------------- - -to remove any of the "loose" objects that are now contained in the -pack. This will also remove any unreferenced objects (which may be -created when, for example, you use "git reset" to remove a commit). -You can verify that the loose objects are gone by looking at the -.git/objects directory or by running - ------------------------------------------------- -$ git count-objects -0 objects, 0 kilobytes ------------------------------------------------- - -Although the object files are gone, any commands that refer to those -objects will work exactly as they did before. - -The gitlink:git-gc[1] command performs packing, pruning, and more for -you, so is normally the only high-level command you need. - -[[dangling-objects]] -Dangling objects ----------------- - -The gitlink:git-fsck[1] command will sometimes complain about dangling -objects. They are not a problem. - -The most common cause of dangling objects is that you've rebased a -branch, or you have pulled from somebody else who rebased a branch--see -<>. In that case, the old head of the original -branch still exists, as does everything it pointed to. The branch -pointer itself just doesn't, since you replaced it with another one. - -There are also other situations that cause dangling objects. For -example, a "dangling blob" may arise because you did a "git add" of a -file, but then, before you actually committed it and made it part of the -bigger picture, you changed something else in that file and committed -that *updated* thing - the old state that you added originally ends up -not being pointed to by any commit or tree, so it's now a dangling blob -object. - -Similarly, when the "recursive" merge strategy runs, and finds that -there are criss-cross merges and thus more than one merge base (which is -fairly unusual, but it does happen), it will generate one temporary -midway tree (or possibly even more, if you had lots of criss-crossing -merges and more than two merge bases) as a temporary internal merge -base, and again, those are real objects, but the end result will not end -up pointing to them, so they end up "dangling" in your repository. - -Generally, dangling objects aren't anything to worry about. They can -even be very useful: if you screw something up, the dangling objects can -be how you recover your old tree (say, you did a rebase, and realized -that you really didn't want to - you can look at what dangling objects -you have, and decide to reset your head to some old dangling state). - -For commits, you can just use: - ------------------------------------------------- -$ gitk --not --all ------------------------------------------------- - -This asks for all the history reachable from the given commit but not -from any branch, tag, or other reference. If you decide it's something -you want, you can always create a new reference to it, e.g., - ------------------------------------------------- -$ git branch recovered-branch ------------------------------------------------- - -For blobs and trees, you can't do the same, but you can still examine -them. You can just do - ------------------------------------------------- -$ git show ------------------------------------------------- - -to show what the contents of the blob were (or, for a tree, basically -what the "ls" for that directory was), and that may give you some idea -of what the operation was that left that dangling object. - -Usually, dangling blobs and trees aren't very interesting. They're -almost always the result of either being a half-way mergebase (the blob -will often even have the conflict markers from a merge in it, if you -have had conflicting merges that you fixed up by hand), or simply -because you interrupted a "git fetch" with ^C or something like that, -leaving _some_ of the new objects in the object database, but just -dangling and useless. - -Anyway, once you are sure that you're not interested in any dangling -state, you can just prune all unreachable objects: - ------------------------------------------------- -$ git prune ------------------------------------------------- - -and they'll be gone. But you should only run "git prune" on a quiescent -repository - it's kind of like doing a filesystem fsck recovery: you -don't want to do that while the filesystem is mounted. - -(The same is true of "git-fsck" itself, btw - but since -git-fsck never actually *changes* the repository, it just reports -on what it found, git-fsck itself is never "dangerous" to run. -Running it while somebody is actually changing the repository can cause -confusing and scary messages, but it won't actually do anything bad. In -contrast, running "git prune" while somebody is actively changing the -repository is a *BAD* idea). - [[hacking-git]] Hacking git =========== From 9644ffdd65f10970d54ab56ae128cde6f3fe1b96 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sat, 8 Sep 2007 22:27:18 -0400 Subject: [PATCH 71/94] user-manual: fix introduction to packfiles Actually I don't think we've previously mentioned .git/objects, so we need a different introduction here. Signed-off-by: J. Bruce Fields --- Documentation/user-manual.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index 4a0fa7e958..cf0c188fa5 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -2952,8 +2952,8 @@ references in .git/refs/tags/). How git stores objects efficiently: pack files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -We've seen how git stores each object in a file named after the -object's SHA1 hash. +Newly created objects are initially created in a file named after the +object's SHA1 hash (stored in .git/objects). Unfortunately this system becomes inefficient once a project has a lot of objects. Try this on an old project: From ecd95b536e37e0a816d8c9832e04f61c3f1d4423 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sun, 2 Sep 2007 23:28:49 -0400 Subject: [PATCH 72/94] user-manual: todo updates and cleanup Format a couple lists. Reminder that we may want to add submodule documentation some day. --- Documentation/user-manual.txt | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/Documentation/user-manual.txt b/Documentation/user-manual.txt index cf0c188fa5..ecb2bf93f2 100644 --- a/Documentation/user-manual.txt +++ b/Documentation/user-manual.txt @@ -4023,25 +4023,26 @@ Appendix B: Notes and todo list for this manual This is a work in progress. The basic requirements: - - It must be readable in order, from beginning to end, by - someone intelligent with a basic grasp of the UNIX - command line, but without any special knowledge of git. If - necessary, any other prerequisites should be specifically - mentioned as they arise. - - Whenever possible, section headings should clearly describe - the task they explain how to do, in language that requires - no more knowledge than necessary: for example, "importing - patches into a project" rather than "the git-am command" + +- It must be readable in order, from beginning to end, by someone + intelligent with a basic grasp of the UNIX command line, but without + any special knowledge of git. If necessary, any other prerequisites + should be specifically mentioned as they arise. +- Whenever possible, section headings should clearly describe the task + they explain how to do, in language that requires no more knowledge + than necessary: for example, "importing patches into a project" rather + than "the git-am command" Think about how to create a clear chapter dependency graph that will allow people to get to important topics without necessarily reading everything in between. Scan Documentation/ for other stuff left out; in particular: - howto's - some of technical/? - hooks - list of commands in gitlink:git[1] + +- howto's +- some of technical/? +- hooks +- list of commands in gitlink:git[1] Scan email archives for other stuff left out @@ -4070,3 +4071,5 @@ Write a chapter on using plumbing and writing scripts. Alternates, clone -reference, etc. git unpack-objects -r for recovery + +submodules From 40dac517ee09e2d0d5ae7b4f904f29b36fa82ef2 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Mon, 3 Sep 2007 00:01:19 -0400 Subject: [PATCH 73/94] documentation: replace Discussion section by link to user-manual chapter The "Discussion" section has a lot of useful information, but is a little wordy, especially for an already-long man page, and is designed for an audience more of potential git hackers than users, which probably doesn't make as much sense as git matures. Also, I (perhaps foolishly) forked a version in the user manual, which has been significantly rewritten in an attempt to address some of the above problems. So, remove this section and replace it by a (very terse) summary of the original material--my attempt at the World's Shortest Git Overview--and a reference to the appropriate chapter of the user manual. It's unfortunate to remove something that's been in this place for a long time, as some people may still depend on finding it there. But I think we'll want to do this some day anyway. Cc: Andreas Ericsson Signed-off-by: J. Bruce Fields --- Documentation/Makefile | 2 +- Documentation/core-intro.txt | 592 ----------------------------------- Documentation/git.txt | 57 +++- 3 files changed, 54 insertions(+), 597 deletions(-) delete mode 100644 Documentation/core-intro.txt diff --git a/Documentation/Makefile b/Documentation/Makefile index fbefe9a45b..39ec0ede02 100644 --- a/Documentation/Makefile +++ b/Documentation/Makefile @@ -123,7 +123,7 @@ cmd-list.made: cmd-list.perl $(MAN1_TXT) perl ./cmd-list.perl date >$@ -git.7 git.html: git.txt core-intro.txt +git.7 git.html: git.txt clean: $(RM) *.xml *.xml+ *.html *.html+ *.1 *.5 *.7 *.texi *.texi+ howto-index.txt howto/*.html doc.dep diff --git a/Documentation/core-intro.txt b/Documentation/core-intro.txt deleted file mode 100644 index f3cc2238c7..0000000000 --- a/Documentation/core-intro.txt +++ /dev/null @@ -1,592 +0,0 @@ -//////////////////////////////////////////////////////////////// - - GIT - the stupid content tracker - -//////////////////////////////////////////////////////////////// - -"git" can mean anything, depending on your mood. - - - random three-letter combination that is pronounceable, and not - actually used by any common UNIX command. The fact that it is a - mispronunciation of "get" may or may not be relevant. - - stupid. contemptible and despicable. simple. Take your pick from the - dictionary of slang. - - "global information tracker": you're in a good mood, and it actually - works for you. Angels sing, and a light suddenly fills the room. - - "goddamn idiotic truckload of sh*t": when it breaks - -This is a (not so) stupid but extremely fast directory content manager. -It doesn't do a whole lot at its core, but what it 'does' do is track -directory contents efficiently. - -There are two object abstractions: the "object database", and the -"current directory cache" aka "index". - -The Object Database -~~~~~~~~~~~~~~~~~~~ -The object database is literally just a content-addressable collection -of objects. All objects are named by their content, which is -approximated by the SHA1 hash of the object itself. Objects may refer -to other objects (by referencing their SHA1 hash), and so you can -build up a hierarchy of objects. - -All objects have a statically determined "type" aka "tag", which is -determined at object creation time, and which identifies the format of -the object (i.e. how it is used, and how it can refer to other -objects). There are currently four different object types: "blob", -"tree", "commit" and "tag". - -A "blob" object cannot refer to any other object, and is, like the type -implies, a pure storage object containing some user data. It is used to -actually store the file data, i.e. a blob object is associated with some -particular version of some file. - -A "tree" object is an object that ties one or more "blob" objects into a -directory structure. In addition, a tree object can refer to other tree -objects, thus creating a directory hierarchy. - -A "commit" object ties such directory hierarchies together into -a DAG of revisions - each "commit" is associated with exactly one tree -(the directory hierarchy at the time of the commit). In addition, a -"commit" refers to one or more "parent" commit objects that describe the -history of how we arrived at that directory hierarchy. - -As a special case, a commit object with no parents is called the "root" -object, and is the point of an initial project commit. Each project -must have at least one root, and while you can tie several different -root objects together into one project by creating a commit object which -has two or more separate roots as its ultimate parents, that's probably -just going to confuse people. So aim for the notion of "one root object -per project", even if git itself does not enforce that. - -A "tag" object symbolically identifies and can be used to sign other -objects. It contains the identifier and type of another object, a -symbolic name (of course!) and, optionally, a signature. - -Regardless of object type, all objects share the following -characteristics: they are all deflated with zlib, and have a header -that not only specifies their type, but also provides size information -about the data in the object. It's worth noting that the SHA1 hash -that is used to name the object is the hash of the original data -plus this header, so `sha1sum` 'file' does not match the object name -for 'file'. -(Historical note: in the dawn of the age of git the hash -was the sha1 of the 'compressed' object.) - -As a result, the general consistency of an object can always be tested -independently of the contents or the type of the object: all objects can -be validated by verifying that (a) their hashes match the content of the -file and (b) the object successfully inflates to a stream of bytes that -forms a sequence of + + + + . - -The structured objects can further have their structure and -connectivity to other objects verified. This is generally done with -the `git-fsck` program, which generates a full dependency graph -of all objects, and verifies their internal consistency (in addition -to just verifying their superficial consistency through the hash). - -The object types in some more detail: - -Blob Object -~~~~~~~~~~~ -A "blob" object is nothing but a binary blob of data, and doesn't -refer to anything else. There is no signature or any other -verification of the data, so while the object is consistent (it 'is' -indexed by its sha1 hash, so the data itself is certainly correct), it -has absolutely no other attributes. No name associations, no -permissions. It is purely a blob of data (i.e. normally "file -contents"). - -In particular, since the blob is entirely defined by its data, if two -files in a directory tree (or in multiple different versions of the -repository) have the same contents, they will share the same blob -object. The object is totally independent of its location in the -directory tree, and renaming a file does not change the object that -file is associated with in any way. - -A blob is typically created when gitlink:git-update-index[1] -(or gitlink:git-add[1]) is run, and its data can be accessed by -gitlink:git-cat-file[1]. - -Tree Object -~~~~~~~~~~~ -The next hierarchical object type is the "tree" object. A tree object -is a list of mode/name/blob data, sorted by name. Alternatively, the -mode data may specify a directory mode, in which case instead of -naming a blob, that name is associated with another TREE object. - -Like the "blob" object, a tree object is uniquely determined by the -set contents, and so two separate but identical trees will always -share the exact same object. This is true at all levels, i.e. it's -true for a "leaf" tree (which does not refer to any other trees, only -blobs) as well as for a whole subdirectory. - -For that reason a "tree" object is just a pure data abstraction: it -has no history, no signatures, no verification of validity, except -that since the contents are again protected by the hash itself, we can -trust that the tree is immutable and its contents never change. - -So you can trust the contents of a tree to be valid, the same way you -can trust the contents of a blob, but you don't know where those -contents 'came' from. - -Side note on trees: since a "tree" object is a sorted list of -"filename+content", you can create a diff between two trees without -actually having to unpack two trees. Just ignore all common parts, -and your diff will look right. In other words, you can effectively -(and efficiently) tell the difference between any two random trees by -O(n) where "n" is the size of the difference, rather than the size of -the tree. - -Side note 2 on trees: since the name of a "blob" depends entirely and -exclusively on its contents (i.e. there are no names or permissions -involved), you can see trivial renames or permission changes by -noticing that the blob stayed the same. However, renames with data -changes need a smarter "diff" implementation. - -A tree is created with gitlink:git-write-tree[1] and -its data can be accessed by gitlink:git-ls-tree[1]. -Two trees can be compared with gitlink:git-diff-tree[1]. - -Commit Object -~~~~~~~~~~~~~ -The "commit" object is an object that introduces the notion of -history into the picture. In contrast to the other objects, it -doesn't just describe the physical state of a tree, it describes how -we got there, and why. - -A "commit" is defined by the tree-object that it results in, the -parent commits (zero, one or more) that led up to that point, and a -comment on what happened. Again, a commit is not trusted per se: -the contents are well-defined and "safe" due to the cryptographically -strong signatures at all levels, but there is no reason to believe -that the tree is "good" or that the merge information makes sense. -The parents do not have to actually have any relationship with the -result, for example. - -Note on commits: unlike real SCM's, commits do not contain -rename information or file mode change information. All of that is -implicit in the trees involved (the result tree, and the result trees -of the parents), and describing that makes no sense in this idiotic -file manager. - -A commit is created with gitlink:git-commit-tree[1] and -its data can be accessed by gitlink:git-cat-file[1]. - -Trust -~~~~~ -An aside on the notion of "trust". Trust is really outside the scope -of "git", but it's worth noting a few things. First off, since -everything is hashed with SHA1, you 'can' trust that an object is -intact and has not been messed with by external sources. So the name -of an object uniquely identifies a known state - just not a state that -you may want to trust. - -Furthermore, since the SHA1 signature of a commit refers to the -SHA1 signatures of the tree it is associated with and the signatures -of the parent, a single named commit specifies uniquely a whole set -of history, with full contents. You can't later fake any step of the -way once you have the name of a commit. - -So to introduce some real trust in the system, the only thing you need -to do is to digitally sign just 'one' special note, which includes the -name of a top-level commit. Your digital signature shows others -that you trust that commit, and the immutability of the history of -commits tells others that they can trust the whole history. - -In other words, you can easily validate a whole archive by just -sending out a single email that tells the people the name (SHA1 hash) -of the top commit, and digitally sign that email using something -like GPG/PGP. - -To assist in this, git also provides the tag object... - -Tag Object -~~~~~~~~~~ -Git provides the "tag" object to simplify creating, managing and -exchanging symbolic and signed tokens. The "tag" object at its -simplest simply symbolically identifies another object by containing -the sha1, type and symbolic name. - -However it can optionally contain additional signature information -(which git doesn't care about as long as there's less than 8k of -it). This can then be verified externally to git. - -Note that despite the tag features, "git" itself only handles content -integrity; the trust framework (and signature provision and -verification) has to come from outside. - -A tag is created with gitlink:git-mktag[1], -its data can be accessed by gitlink:git-cat-file[1], -and the signature can be verified by -gitlink:git-verify-tag[1]. - - -The "index" aka "Current Directory Cache" ------------------------------------------ -The index is a simple binary file, which contains an efficient -representation of a virtual directory content at some random time. It -does so by a simple array that associates a set of names, dates, -permissions and content (aka "blob") objects together. The cache is -always kept ordered by name, and names are unique (with a few very -specific rules) at any point in time, but the cache has no long-term -meaning, and can be partially updated at any time. - -In particular, the index certainly does not need to be consistent with -the current directory contents (in fact, most operations will depend on -different ways to make the index 'not' be consistent with the directory -hierarchy), but it has three very important attributes: - -'(a) it can re-generate the full state it caches (not just the -directory structure: it contains pointers to the "blob" objects so -that it can regenerate the data too)' - -As a special case, there is a clear and unambiguous one-way mapping -from a current directory cache to a "tree object", which can be -efficiently created from just the current directory cache without -actually looking at any other data. So a directory cache at any one -time uniquely specifies one and only one "tree" object (but has -additional data to make it easy to match up that tree object with what -has happened in the directory) - -'(b) it has efficient methods for finding inconsistencies between that -cached state ("tree object waiting to be instantiated") and the -current state.' - -'(c) it can additionally efficiently represent information about merge -conflicts between different tree objects, allowing each pathname to be -associated with sufficient information about the trees involved that -you can create a three-way merge between them.' - -Those are the three ONLY things that the directory cache does. It's a -cache, and the normal operation is to re-generate it completely from a -known tree object, or update/compare it with a live tree that is being -developed. If you blow the directory cache away entirely, you generally -haven't lost any information as long as you have the name of the tree -that it described. - -At the same time, the index is at the same time also the -staging area for creating new trees, and creating a new tree always -involves a controlled modification of the index file. In particular, -the index file can have the representation of an intermediate tree that -has not yet been instantiated. So the index can be thought of as a -write-back cache, which can contain dirty information that has not yet -been written back to the backing store. - - - -The Workflow ------------- -Generally, all "git" operations work on the index file. Some operations -work *purely* on the index file (showing the current state of the -index), but most operations move data to and from the index file. Either -from the database or from the working directory. Thus there are four -main combinations: - -1) working directory -> index -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You update the index with information from the working directory with -the gitlink:git-update-index[1] command. You -generally update the index information by just specifying the filename -you want to update, like so: - - git-update-index filename - -but to avoid common mistakes with filename globbing etc, the command -will not normally add totally new entries or remove old entries, -i.e. it will normally just update existing cache entries. - -To tell git that yes, you really do realize that certain files no -longer exist, or that new files should be added, you -should use the `--remove` and `--add` flags respectively. - -NOTE! A `--remove` flag does 'not' mean that subsequent filenames will -necessarily be removed: if the files still exist in your directory -structure, the index will be updated with their new status, not -removed. The only thing `--remove` means is that update-cache will be -considering a removed file to be a valid thing, and if the file really -does not exist any more, it will update the index accordingly. - -As a special case, you can also do `git-update-index --refresh`, which -will refresh the "stat" information of each index to match the current -stat information. It will 'not' update the object status itself, and -it will only update the fields that are used to quickly test whether -an object still matches its old backing store object. - -2) index -> object database -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You write your current index file to a "tree" object with the program - - git-write-tree - -that doesn't come with any options - it will just write out the -current index into the set of tree objects that describe that state, -and it will return the name of the resulting top-level tree. You can -use that tree to re-generate the index at any time by going in the -other direction: - -3) object database -> index -~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You read a "tree" file from the object database, and use that to -populate (and overwrite - don't do this if your index contains any -unsaved state that you might want to restore later!) your current -index. Normal operation is just - - git-read-tree - -and your index file will now be equivalent to the tree that you saved -earlier. However, that is only your 'index' file: your working -directory contents have not been modified. - -4) index -> working directory -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -You update your working directory from the index by "checking out" -files. This is not a very common operation, since normally you'd just -keep your files updated, and rather than write to your working -directory, you'd tell the index files about the changes in your -working directory (i.e. `git-update-index`). - -However, if you decide to jump to a new version, or check out somebody -else's version, or just restore a previous tree, you'd populate your -index file with read-tree, and then you need to check out the result -with - - git-checkout-index filename - -or, if you want to check out all of the index, use `-a`. - -NOTE! git-checkout-index normally refuses to overwrite old files, so -if you have an old version of the tree already checked out, you will -need to use the "-f" flag ('before' the "-a" flag or the filename) to -'force' the checkout. - - -Finally, there are a few odds and ends which are not purely moving -from one representation to the other: - -5) Tying it all together -~~~~~~~~~~~~~~~~~~~~~~~~ -To commit a tree you have instantiated with "git-write-tree", you'd -create a "commit" object that refers to that tree and the history -behind it - most notably the "parent" commits that preceded it in -history. - -Normally a "commit" has one parent: the previous state of the tree -before a certain change was made. However, sometimes it can have two -or more parent commits, in which case we call it a "merge", due to the -fact that such a commit brings together ("merges") two or more -previous states represented by other commits. - -In other words, while a "tree" represents a particular directory state -of a working directory, a "commit" represents that state in "time", -and explains how we got there. - -You create a commit object by giving it the tree that describes the -state at the time of the commit, and a list of parents: - - git-commit-tree -p [-p ..] - -and then giving the reason for the commit on stdin (either through -redirection from a pipe or file, or by just typing it at the tty). - -git-commit-tree will return the name of the object that represents -that commit, and you should save it away for later use. Normally, -you'd commit a new `HEAD` state, and while git doesn't care where you -save the note about that state, in practice we tend to just write the -result to the file pointed at by `.git/HEAD`, so that we can always see -what the last committed state was. - -Here is an ASCII art by Jon Loeliger that illustrates how -various pieces fit together. - ------------- - - commit-tree - commit obj - +----+ - | | - | | - V V - +-----------+ - | Object DB | - | Backing | - | Store | - +-----------+ - ^ - write-tree | | - tree obj | | - | | read-tree - | | tree obj - V - +-----------+ - | Index | - | "cache" | - +-----------+ - update-index ^ - blob obj | | - | | - checkout-index -u | | checkout-index - stat | | blob obj - V - +-----------+ - | Working | - | Directory | - +-----------+ - ------------- - - -6) Examining the data -~~~~~~~~~~~~~~~~~~~~~ - -You can examine the data represented in the object database and the -index with various helper tools. For every object, you can use -gitlink:git-cat-file[1] to examine details about the -object: - - git-cat-file -t - -shows the type of the object, and once you have the type (which is -usually implicit in where you find the object), you can use - - git-cat-file blob|tree|commit|tag - -to show its contents. NOTE! Trees have binary content, and as a result -there is a special helper for showing that content, called -`git-ls-tree`, which turns the binary content into a more easily -readable form. - -It's especially instructive to look at "commit" objects, since those -tend to be small and fairly self-explanatory. In particular, if you -follow the convention of having the top commit name in `.git/HEAD`, -you can do - - git-cat-file commit HEAD - -to see what the top commit was. - -7) Merging multiple trees -~~~~~~~~~~~~~~~~~~~~~~~~~ - -Git helps you do a three-way merge, which you can expand to n-way by -repeating the merge procedure arbitrary times until you finally -"commit" the state. The normal situation is that you'd only do one -three-way merge (two parents), and commit it, but if you like to, you -can do multiple parents in one go. - -To do a three-way merge, you need the two sets of "commit" objects -that you want to merge, use those to find the closest common parent (a -third "commit" object), and then use those commit objects to find the -state of the directory ("tree" object) at these points. - -To get the "base" for the merge, you first look up the common parent -of two commits with - - git-merge-base - -which will return you the commit they are both based on. You should -now look up the "tree" objects of those commits, which you can easily -do with (for example) - - git-cat-file commit | head -1 - -since the tree object information is always the first line in a commit -object. - -Once you know the three trees you are going to merge (the one -"original" tree, aka the common case, and the two "result" trees, aka -the branches you want to merge), you do a "merge" read into the -index. This will complain if it has to throw away your old index contents, so you should -make sure that you've committed those - in fact you would normally -always do a merge against your last commit (which should thus match -what you have in your current index anyway). - -To do the merge, do - - git-read-tree -m -u - -which will do all trivial merge operations for you directly in the -index file, and you can just write the result out with -`git-write-tree`. - -Historical note. We did not have `-u` facility when this -section was first written, so we used to warn that -the merge is done in the index file, not in your -working tree, and your working tree will not match your -index after this step. -This is no longer true. The above command, thanks to `-u` -option, updates your working tree with the merge results for -paths that have been trivially merged. - - -8) Merging multiple trees, continued -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Sadly, many merges aren't trivial. If there are files that have -been added, moved or removed, or if both branches have modified the -same file, you will be left with an index tree that contains "merge -entries" in it. Such an index tree can 'NOT' be written out to a tree -object, and you will have to resolve any such merge clashes using -other tools before you can write out the result. - -You can examine such index state with `git-ls-files --unmerged` -command. An example: - ------------------------------------------------- -$ git-read-tree -m $orig HEAD $target -$ git-ls-files --unmerged -100644 263414f423d0e4d70dae8fe53fa34614ff3e2860 1 hello.c -100644 06fa6a24256dc7e560efa5687fa84b51f0263c3a 2 hello.c -100644 cc44c73eb783565da5831b4d820c962954019b69 3 hello.c ------------------------------------------------- - -Each line of the `git-ls-files --unmerged` output begins with -the blob mode bits, blob SHA1, 'stage number', and the -filename. The 'stage number' is git's way to say which tree it -came from: stage 1 corresponds to `$orig` tree, stage 2 `HEAD` -tree, and stage3 `$target` tree. - -Earlier we said that trivial merges are done inside -`git-read-tree -m`. For example, if the file did not change -from `$orig` to `HEAD` nor `$target`, or if the file changed -from `$orig` to `HEAD` and `$orig` to `$target` the same way, -obviously the final outcome is what is in `HEAD`. What the -above example shows is that file `hello.c` was changed from -`$orig` to `HEAD` and `$orig` to `$target` in a different way. -You could resolve this by running your favorite 3-way merge -program, e.g. `diff3` or `merge`, on the blob objects from -these three stages yourself, like this: - ------------------------------------------------- -$ git-cat-file blob 263414f... >hello.c~1 -$ git-cat-file blob 06fa6a2... >hello.c~2 -$ git-cat-file blob cc44c73... >hello.c~3 -$ merge hello.c~2 hello.c~1 hello.c~3 ------------------------------------------------- - -This would leave the merge result in `hello.c~2` file, along -with conflict markers if there are conflicts. After verifying -the merge result makes sense, you can tell git what the final -merge result for this file is by: - - mv -f hello.c~2 hello.c - git-update-index hello.c - -When a path is in unmerged state, running `git-update-index` for -that path tells git to mark the path resolved. - -The above is the description of a git merge at the lowest level, -to help you understand what conceptually happens under the hood. -In practice, nobody, not even git itself, uses three `git-cat-file` -for this. There is `git-merge-index` program that extracts the -stages to temporary files and calls a "merge" script on it: - - git-merge-index git-merge-one-file hello.c - -and that is what higher level `git merge -s resolve` is implemented -with. diff --git a/Documentation/git.txt b/Documentation/git.txt index 6f7db2935b..a7cd91acc1 100644 --- a/Documentation/git.txt +++ b/Documentation/git.txt @@ -134,9 +134,9 @@ FURTHER DOCUMENTATION See the references above to get started using git. The following is probably more detail than necessary for a first-time user. -The <> section below and the -link:core-tutorial.html[Core tutorial] both provide introductions to the -underlying git architecture. +The link:user-manual.html#git-concepts[git concepts chapter of the +user-manual] and the link:core-tutorial.html[Core tutorial] both provide +introductions to the underlying git architecture. See also the link:howto-index.html[howto] documents for some useful examples. @@ -474,7 +474,56 @@ for further details. Discussion[[Discussion]] ------------------------ -include::core-intro.txt[] + +More detail on the following is available from the +link:user-manual.html#git-concepts[git concepts chapter of the +user-manual] and the link:core-tutorial.html[Core tutorial]. + +A git project normally consists of a working directory with a ".git" +subdirectory at the top level. The .git directory contains, among other +things, a compressed object database representing the complete history +of the project, an "index" file which links that history to the current +contents of the working tree, and named pointers into that history such +as tags and branch heads. + +The object database contains objects of three main types: blobs, which +hold file data; trees, which point to blobs and other trees to build up +directory heirarchies; and commits, which each reference a single tree +and some number of parent commits. + +The commit, equivalent to what other systems call a "changeset" or +"version", represents a step in the project's history, and each parent +represents an immediately preceding step. Commits with more than one +parent represent merges of independent lines of development. + +All objects are named by the SHA1 hash of their contents, normally +written as a string of 40 hex digits. Such names are globally unique. +The entire history leading up to a commit can be vouched for by signing +just that commit. A fourth object type, the tag, is provided for this +purpose. + +When first created, objects are stored in individual files, but for +efficiency may later be compressed together into "pack files". + +Named pointers called refs mark interesting points in history. A ref +may contain the SHA1 name of an object or the name of another ref. Refs +with names beginning `ref/head/` contain the SHA1 name of the most +recent commit (or "head") of a branch under developement. SHA1 names of +tags of interest are stored under `ref/tags/`. A special ref named +`HEAD` contains the name of the currently checked-out branch. + +The index file is initialized with a list of all paths and, for each +path, a blob object and a set of attributes. The blob object represents +the contents of the file as of the head of the current branch. The +attributes (last modified time, size, etc.) are taken from the +corresponding file in the working tree. Subsequent changes to the +working tree can be found by comparing these attributes. The index may +be updated with new content, and new commits may be created from the +content stored in the index. + +The index is also capable of storing multiple entries (called "stages") +for a given pathname. These stages are used to hold the various +unmerged version of a file when a merge is in progress. Authors ------- From a85fecafe63b49f89e0c055db6fb24b057db88c6 Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Mon, 3 Sep 2007 10:34:27 -0400 Subject: [PATCH 74/94] core-tutorial: minor cleanup Revise the introduction for concision, add pointers to the tutorial and user manual as appropriate, delete cvsimport note from the end, as that work's been done elsewhere already. Signed-off-by: J. Bruce Fields --- Documentation/core-tutorial.txt | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) diff --git a/Documentation/core-tutorial.txt b/Documentation/core-tutorial.txt index 4fb6f4143c..4b4fd9a506 100644 --- a/Documentation/core-tutorial.txt +++ b/Documentation/core-tutorial.txt @@ -4,34 +4,24 @@ A git core tutorial for developers Introduction ------------ -This is trying to be a short tutorial on setting up and using a git -repository, mainly because being hands-on and using explicit examples is -often the best way of explaining what is going on. +This tutorial explains how to use the "core" git programs to set up and +work with a git repository. -In normal life, most people wouldn't use the "core" git programs -directly, but rather script around them to make them more palatable. -Understanding the core git stuff may help some people get those scripts -done, though, and it may also be instructive in helping people -understand what it is that the higher-level helper scripts are actually -doing. +If you just need to use git as a revision control system you may prefer +to start with link:tutorial.html[a tutorial introduction to git] or +link:user-manual.html[the git user manual]. + +However, an understanding of these low-level tools can be helpful if +you want to understand git's internals. The core git is often called "plumbing", with the prettier user interfaces on top of it called "porcelain". You may not want to use the plumbing directly very often, but it can be good to know what the plumbing does for when the porcelain isn't flushing. -The material presented here often goes deep describing how things -work internally. If you are mostly interested in using git as a -SCM, you can skip them during your first pass. - [NOTE] -And those "too deep" descriptions are often marked as Note. - -[NOTE] -If you are already familiar with another version control system, -like CVS, you may want to take a look at -link:everyday.html[Everyday GIT in 20 commands or so] first -before reading this. +Deeper technical details are often marked as Notes, which you can +skip on your first reading. Creating a git repository @@ -1686,5 +1676,3 @@ merge two at a time, documenting how you resolved the conflicts, and the reason why you preferred changes made in one side over the other. Otherwise it would make the project history harder to follow, not easier. - -[ to be continued.. cvsimports ] From ece7b74903007cee8d280573647243d46a6f3a95 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 17 Sep 2007 01:24:57 +0100 Subject: [PATCH 75/94] apply --index-info: fall back to current index for mode changes "git diff" does not record index lines for pure mode changes (i.e. no lines changed). Therefore, apply --index-info would call out a bogus error. Instead, fall back to reading the info from the current index. Incidentally, this fixes an error where git-rebase would not rebase a commit including a pure mode change, and changes requiring a threeway merge. Noticed and later tested by Chris Shoemaker. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- builtin-apply.c | 26 ++++++++++++++++++++++++-- t/t3400-rebase.sh | 15 +++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 976ec77041..f4ecf03ed4 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -2227,6 +2227,20 @@ static int check_patch_list(struct patch *patch) return err; } +/* This function tries to read the sha1 from the current index */ +static int get_current_sha1(const char *path, unsigned char *sha1) +{ + int pos; + + if (read_cache() < 0) + return -1; + pos = cache_name_pos(path, strlen(path)); + if (pos < 0) + return -1; + hashcpy(sha1, active_cache[pos]->sha1); + return 0; +} + static void show_index_list(struct patch *list) { struct patch *patch; @@ -2243,8 +2257,16 @@ static void show_index_list(struct patch *list) if (0 < patch->is_new) sha1_ptr = null_sha1; else if (get_sha1(patch->old_sha1_prefix, sha1)) - die("sha1 information is lacking or useless (%s).", - name); + /* git diff has no index line for mode/type changes */ + if (!patch->lines_added && !patch->lines_deleted) { + if (get_current_sha1(patch->new_name, sha1) || + get_current_sha1(patch->old_name, sha1)) + die("mode change for %s, which is not " + "in current HEAD", name); + sha1_ptr = sha1; + } else + die("sha1 information is lacking or useless " + "(%s).", name); else sha1_ptr = sha1; diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 62205b2531..95e33b5210 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -68,4 +68,19 @@ test_expect_success \ test 3 = $(git rev-list master.. | wc -l) ' +test_expect_success 'rebase a single mode change' ' + git checkout master && + echo 1 > X && + git add X && + test_tick && + git commit -m prepare && + git checkout -b modechange HEAD^ && + echo 1 > X && + git add X && + chmod a+x A && + test_tick && + git commit -m modechange A X && + GIT_TRACE=1 git rebase master +' + test_done From 3849bfba84fb5b0e9d46920f62105b4e1dd97e63 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Sun, 16 Sep 2007 23:12:19 -0400 Subject: [PATCH 76/94] git-gui: Disable native platform text selection in "lists" Sometimes we use a Tk text widget as though it were a listbox. This happens typically when we want to show an icon to the left of the text label or just when a text widget is generally a better choice then the native listbox widget. In these cases if we want the user to have control over the selection we implement our own "in_sel" tag that shows the selected region and we perform our own selection management in the background via keybindings and mouse bindings. In such uses we don't want the user to be able to activate the native platform selection by dragging their mouse through the text widget. Doing so creates a very confusing display and the user is left wondering what it may mean to have two different types of selection in the same widget. Tk doesn't allow us to delete the "sel" tag that it uses internally to manage the native selection but it will allow us to make it invisible by setting the tag to have the same display properties as unselected text. So long as we don't actually use the "sel" tag for anything in code its effectively invisible. Signed-off-by: Shawn O. Pearce --- git-gui.sh | 14 ++++++++++++-- lib/browser.tcl | 4 +--- lib/choose_font.tcl | 9 +++++---- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 31a36cb49f..f789e91b66 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -481,6 +481,16 @@ proc tk_optionMenu {w varName args} { return $m } +proc rmsel_tag {text} { + $text tag conf sel \ + -background [$text cget -background] \ + -foreground [$text cget -foreground] \ + -borderwidth 0 + $text tag conf in_sel -background lightgray + bind $text break + return $text +} + ###################################################################### ## ## find git @@ -2151,8 +2161,8 @@ pack $ui_workdir -side left -fill both -expand 1 .vpane.files add .vpane.files.workdir -sticky nsew foreach i [list $ui_index $ui_workdir] { - $i tag conf in_diff -background lightgray - $i tag conf in_sel -background lightgray + rmsel_tag $i + $i tag conf in_diff -background [$i tag cget in_sel -background] } unset i diff --git a/lib/browser.tcl b/lib/browser.tcl index 888db3c889..31349009ae 100644 --- a/lib/browser.tcl +++ b/lib/browser.tcl @@ -47,9 +47,7 @@ constructor new {commit {path {}}} { -width 70 \ -xscrollcommand [list $w.list.sbx set] \ -yscrollcommand [list $w.list.sby set] - $w_list tag conf in_sel \ - -background [$w_list cget -foreground] \ - -foreground [$w_list cget -background] + rmsel_tag $w_list scrollbar $w.list.sbx -orient h -command [list $w_list xview] scrollbar $w.list.sby -orient v -command [list $w_list yview] pack $w.list.sbx -side bottom -fill x diff --git a/lib/choose_font.tcl b/lib/choose_font.tcl index b69215c91e..0c4051b375 100644 --- a/lib/choose_font.tcl +++ b/lib/choose_font.tcl @@ -62,6 +62,7 @@ constructor pick {path title a_family a_size} { -width 30 \ -height 10 \ -yscrollcommand [list $w.inner.family.sby set] + rmsel_tag $w_family scrollbar $w.inner.family.sby -command [list $w_family yview] pack $w.inner.family.l -side top -fill x pack $w.inner.family.sby -side right -fill y @@ -95,6 +96,7 @@ constructor pick {path title a_family a_size} { -relief sunken \ -height 3 \ -width 40 + rmsel_tag $w_example $w_example tag conf example -justify center $w_example insert end [mc "This is example text.\nIf you like this text, it can be your font."] example $w_example conf -state disabled @@ -108,11 +110,10 @@ constructor pick {path title a_family a_size} { $w_family tag conf pick $w_family tag bind pick [cb _pick_family %x %y]\;break - $w_family tag conf cpck -background lightgray foreach f $all_families { set sel [list pick] if {$f eq $f_family} { - lappend sel cpck + lappend sel in_sel } $w_family insert end "$f\n" $sel } @@ -145,8 +146,8 @@ method _pick_family {x y} { set i [lindex [split [$w_family index @$x,$y] .] 0] set n [lindex $all_families [expr {$i - 1}]] if {$n ne {}} { - $w_family tag remove cpck 0.0 end - $w_family tag add cpck $i.0 [expr {$i + 1}].0 + $w_family tag remove in_sel 0.0 end + $w_family tag add in_sel $i.0 [expr {$i + 1}].0 set f_family $n _update $this } From d7416ecac8508367a8ac35ab74ef09b7707d0c4b Mon Sep 17 00:00:00 2001 From: "J. Bruce Fields" Date: Sun, 16 Sep 2007 18:49:00 -0400 Subject: [PATCH 77/94] git-apply: fix whitespace stripping The algorithm isn't right here: it accumulates any set of 8 spaces into tabs even if they're separated by tabs, so is converted to when it should be just So teach git-apply that a tab hides any group of less than 8 previous spaces in a row. Signed-off-by: J. Bruce Fields Signed-off-by: Junio C Hamano --- builtin-apply.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index f4ecf03ed4..5ad371424b 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -1642,15 +1642,22 @@ static int apply_line(char *output, const char *patch, int plen) buf = output; if (need_fix_leading_space) { + int consecutive_spaces = 0; /* between patch[1..last_tab_in_indent] strip the * funny spaces, updating them to tab as needed. */ for (i = 1; i < last_tab_in_indent; i++, plen--) { char ch = patch[i]; - if (ch != ' ') + if (ch != ' ') { + consecutive_spaces = 0; *output++ = ch; - else if ((i % 8) == 0) - *output++ = '\t'; + } else { + consecutive_spaces++; + if (consecutive_spaces == 8) { + *output++ = '\t'; + consecutive_spaces = 0; + } + } } fixed = 1; i = last_tab_in_indent; From be510cfef3d8344007bd34128ca6eb799b714c8c Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Mon, 17 Sep 2007 21:18:20 -0700 Subject: [PATCH 78/94] send-email: make message-id generation a bit more robust Earlier code took Unix time and appended a few random digits. If you are firing off many messages within a second, you could issue the same id to different messages, which is a no-no. If you send out 31 messages within a single second, with random integer taken out of rand(4200), you have about 10% chance of producing the same message ID. This fixes the problem by uses a prefix string which is constant-per-invocation (time and pid), with a serial number for each message generated by the process appended at the end. Signed-off-by: Junio C Hamano --- git-send-email.perl | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 195fe6f70a..9547cc37a1 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -437,10 +437,17 @@ sub extract_valid_address { # We'll setup a template for the message id, using the "from" address: +my ($message_id_stamp, $message_id_serial); sub make_message_id { - my $date = time; - my $pseudo_rand = int (rand(4200)); + my $uniq; + if (!defined $message_id_stamp) { + $message_id_stamp = sprintf("%s-%s", time, $$); + $message_id_serial = 0; + } + $message_id_serial++; + $uniq = "$message_id_stamp-$message_id_serial"; + my $du_part; for ($sender, $repocommitter, $repoauthor) { $du_part = extract_valid_address(sanitize_address($_)); @@ -450,8 +457,8 @@ sub make_message_id use Sys::Hostname qw(); $du_part = 'user@' . Sys::Hostname::hostname(); } - my $message_id_template = "<%s-git-send-email-$du_part>"; - $message_id = sprintf $message_id_template, "$date$pseudo_rand"; + my $message_id_template = "<%s-git-send-email-%s>"; + $message_id = sprintf($message_id_template, $uniq, $du_part); #print "new message id = $message_id\n"; # Was useful for debugging } From 64586e75af3c84844b80652575a8b63a9612b24a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 12 Sep 2007 16:04:22 -0700 Subject: [PATCH 79/94] git-commit: Allow partial commit of file removal. When making a partial commit, git-commit uses git-ls-files with the --error-unmatch option to expand and sanity check the user supplied path patterns. When any path pattern does not match with the paths known to the index, it errors out, in order to catch a common mistake to say "git commit Makefiel cache.h" and end up with a commit that touches only cache.h (notice the misspelled "Makefile"). This detection however does not work well when the path has already been removed from the index. If you drop a path from the index and try to commit that partially, i.e. $ git rm COPYING $ git commit -m 'Remove COPYING' COPYING the command complains because git does not know anything about COPYING anymore. This introduces a new option --with-tree to git-ls-files and uses it in git-commit when we build a temporary index to write a tree object for the partial commit. When --with-tree= option is specified, names from the given tree are added to the set of names the index knows about, so we can treat COPYING file in the example as known. Of course, there is no reason to use "git rm" and git-aware people have long time done: $ rm COPYING $ git commit -m 'Remove COPYING' COPYING which works just fine. But this caused a constant confusion. Signed-off-by: Junio C Hamano --- builtin-ls-files.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ git-commit.sh | 5 ++- t/t7501-commit.sh | 21 +++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) diff --git a/builtin-ls-files.c b/builtin-ls-files.c index cce17b5ced..6c1db86e80 100644 --- a/builtin-ls-files.c +++ b/builtin-ls-files.c @@ -9,6 +9,7 @@ #include "quote.h" #include "dir.h" #include "builtin.h" +#include "tree.h" static int abbrev; static int show_deleted; @@ -26,6 +27,7 @@ static int prefix_offset; static const char **pathspec; static int error_unmatch; static char *ps_matched; +static const char *with_tree; static const char *tag_cached = ""; static const char *tag_unmerged = ""; @@ -247,6 +249,8 @@ static void show_files(struct dir_struct *dir, const char *prefix) continue; if (show_unmerged && !ce_stage(ce)) continue; + if (ce->ce_flags & htons(CE_UPDATE)) + continue; show_ce_entry(ce_stage(ce) ? tag_unmerged : tag_cached, ce); } } @@ -332,6 +336,67 @@ static const char *verify_pathspec(const char *prefix) return real_prefix; } +/* + * Read the tree specified with --with-tree option + * (typically, HEAD) into stage #1 and then + * squash them down to stage #0. This is used for + * --error-unmatch to list and check the path patterns + * that were given from the command line. We are not + * going to write this index out. + */ +static void overlay_tree(const char *tree_name, const char *prefix) +{ + struct tree *tree; + unsigned char sha1[20]; + const char **match; + struct cache_entry *last_stage0 = NULL; + int i; + + if (get_sha1(tree_name, sha1)) + die("tree-ish %s not found.", tree_name); + tree = parse_tree_indirect(sha1); + if (!tree) + die("bad tree-ish %s", tree_name); + + /* Hoist the unmerged entries up to stage #3 to make room */ + for (i = 0; i < active_nr; i++) { + struct cache_entry *ce = active_cache[i]; + if (!ce_stage(ce)) + continue; + ce->ce_flags |= htons(CE_STAGEMASK); + } + + if (prefix) { + static const char *(matchbuf[2]); + matchbuf[0] = prefix; + matchbuf [1] = NULL; + match = matchbuf; + } else + match = NULL; + if (read_tree(tree, 1, match)) + die("unable to read tree entries %s", tree_name); + + for (i = 0; i < active_nr; i++) { + struct cache_entry *ce = active_cache[i]; + switch (ce_stage(ce)) { + case 0: + last_stage0 = ce; + /* fallthru */ + default: + continue; + case 1: + /* + * If there is stage #0 entry for this, we do not + * need to show it. We use CE_UPDATE bit to mark + * such an entry. + */ + if (last_stage0 && + !strcmp(last_stage0->name, ce->name)) + ce->ce_flags |= htons(CE_UPDATE); + } + } +} + static const char ls_files_usage[] = "git-ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified])* " "[ --ignored ] [--exclude=] [--exclude-from=] " @@ -452,6 +517,10 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) error_unmatch = 1; continue; } + if (!prefixcmp(arg, "--with-tree=")) { + with_tree = arg + 12; + continue; + } if (!prefixcmp(arg, "--abbrev=")) { abbrev = strtoul(arg+9, NULL, 10); if (abbrev && abbrev < MINIMUM_ABBREV) @@ -503,6 +572,15 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) read_cache(); if (prefix) prune_cache(prefix); + if (with_tree) { + /* + * Basic sanity check; show-stages and show-unmerged + * would not make any sense with this option. + */ + if (show_stage || show_unmerged) + die("ls-files --with-tree is incompatible with -s or -u"); + overlay_tree(with_tree, prefix); + } show_files(&dir, prefix); if (ps_matched) { diff --git a/git-commit.sh b/git-commit.sh index 41538f16e5..5ea3fd0076 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -379,8 +379,11 @@ t,) then refuse_partial "Cannot do a partial commit during a merge." fi + TMP_INDEX="$GIT_DIR/tmp-index$$" - commit_only=`git ls-files --error-unmatch -- "$@"` || exit + W= + test -z "$initial_commit" && W=--with-tree=HEAD + commit_only=`git ls-files --error-unmatch $W -- "$@"` || exit # Build a temporary index and update the real index # the same way. diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 6bd3c9e3e0..f178f56208 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -131,4 +131,25 @@ test_expect_success \ 'validate git-rev-list output.' \ 'diff current expected' +test_expect_success 'partial commit that involve removal (1)' ' + + git rm --cached file && + mv file elif && + git add elif && + git commit -m "Partial: add elif" elif && + git diff-tree --name-status HEAD^ HEAD >current && + echo "A elif" >expected && + diff expected current + +' + +test_expect_success 'partial commit that involve removal (2)' ' + + git commit -m "Partial: remove file" file && + git diff-tree --name-status HEAD^ HEAD >current && + echo "D file" >expected && + diff expected current + +' + test_done From cba8d4896187abedd9c35936504b7254a2ecbd91 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 16:53:58 -0700 Subject: [PATCH 80/94] git-commit: partial commit of paths only removed from the index Because a partial commit is meant to be a way to ignore what are staged in the index, "git rm --cached A && git commit A" should just record what is in A on the filesystem. The previous patch made the command sequence to barf, saying that A has not been added yet. This fixes it. Signed-off-by: Junio C Hamano --- git-commit.sh | 2 +- t/t7501-commit.sh | 15 +++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/git-commit.sh b/git-commit.sh index 5ea3fd0076..bb113e858b 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -404,7 +404,7 @@ t,) ( GIT_INDEX_FILE="$NEXT_INDEX" export GIT_INDEX_FILE - git update-index --remove --stdin + git update-index --add --remove --stdin ) || exit ;; esac diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index f178f56208..b151b51a34 100644 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -131,7 +131,7 @@ test_expect_success \ 'validate git-rev-list output.' \ 'diff current expected' -test_expect_success 'partial commit that involve removal (1)' ' +test_expect_success 'partial commit that involves removal (1)' ' git rm --cached file && mv file elif && @@ -143,7 +143,7 @@ test_expect_success 'partial commit that involve removal (1)' ' ' -test_expect_success 'partial commit that involve removal (2)' ' +test_expect_success 'partial commit that involves removal (2)' ' git commit -m "Partial: remove file" file && git diff-tree --name-status HEAD^ HEAD >current && @@ -152,4 +152,15 @@ test_expect_success 'partial commit that involve removal (2)' ' ' +test_expect_success 'partial commit that involves removal (3)' ' + + git rm --cached elif && + echo elif >elif && + git commit -m "Partial: modify elif" elif && + git diff-tree --name-status HEAD^ HEAD >current && + echo "M elif" >expected && + diff expected current + +' + test_done From 7a461b5a33239cfba3bbf0a1deef544c7f1dcfeb Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 14 Sep 2007 16:59:04 -0700 Subject: [PATCH 81/94] Document ls-files --with-tree= Signed-off-by: Junio C Hamano --- Documentation/git-ls-files.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Documentation/git-ls-files.txt b/Documentation/git-ls-files.txt index 997594549f..9e454f0a4d 100644 --- a/Documentation/git-ls-files.txt +++ b/Documentation/git-ls-files.txt @@ -15,7 +15,7 @@ SYNOPSIS [-x |--exclude=] [-X |--exclude-from=] [--exclude-per-directory=] - [--error-unmatch] + [--error-unmatch] [--with-tree=] [--full-name] [--abbrev] [--] []\* DESCRIPTION @@ -81,6 +81,13 @@ OPTIONS If any does not appear in the index, treat this as an error (return 1). +--with-tree=:: + When using --error-unmatch to expand the user supplied + (i.e. path pattern) arguments to paths, pretend + that paths which were removed in the index since the + named are still present. Using this option + with `-s` or `-u` options does not make any sense. + -t:: Identify the file status with the following tags (followed by a space) at the start of each line: From ce0cbad7727457854d631a6314d9aee7c837cb65 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 17 Sep 2007 05:28:20 +0200 Subject: [PATCH 82/94] rev-list --bisect: Move finding bisection into do_find_bisection. This factorises some code and make a big function smaller. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin-rev-list.c | 90 ++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 42 deletions(-) diff --git a/builtin-rev-list.c b/builtin-rev-list.c index ac551d59f3..2dae287129 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -268,39 +268,12 @@ static void show_list(const char *debug, int counted, int nr, * unknown. After running count_distance() first, they will get zero * or positive distance. */ - -static struct commit_list *find_bisection(struct commit_list *list, - int *reaches, int *all) +static struct commit_list *do_find_bisection(struct commit_list *list, + int nr, int *weights) { - int n, nr, on_list, counted, distance; - struct commit_list *p, *best, *next, *last; - int *weights; - - show_list("bisection 2 entry", 0, 0, list); - - /* - * Count the number of total and tree-changing items on the - * list, while reversing the list. - */ - for (nr = on_list = 0, last = NULL, p = list; - p; - p = next) { - unsigned flags = p->item->object.flags; + int n, counted, distance; + struct commit_list *p, *best; - next = p->next; - if (flags & UNINTERESTING) - continue; - p->next = last; - last = p; - if (!revs.prune_fn || (flags & TREECHANGE)) - nr++; - on_list++; - } - list = last; - show_list("bisection 2 sorted", 0, nr, list); - - *all = nr; - weights = xcalloc(on_list, sizeof(*weights)); counted = 0; for (n = 0, p = list; p; p = p->next) { @@ -357,12 +330,8 @@ static struct commit_list *find_bisection(struct commit_list *list, weight_set(p, distance); /* Does it happen to be at exactly half-way? */ - if (halfway(p, distance, nr)) { - p->next = NULL; - *reaches = distance; - free(weights); + if (halfway(p, distance, nr)) return p; - } counted++; } @@ -400,12 +369,8 @@ static struct commit_list *find_bisection(struct commit_list *list, /* Does it happen to be at exactly half-way? */ distance = weight(p); - if (halfway(p, distance, nr)) { - p->next = NULL; - *reaches = distance; - free(weights); + if (halfway(p, distance, nr)) return p; - } } } @@ -425,12 +390,53 @@ static struct commit_list *find_bisection(struct commit_list *list, if (distance > counted) { best = p; counted = distance; - *reaches = weight(p); } } + return best; +} + +static struct commit_list *find_bisection(struct commit_list *list, + int *reaches, int *all) +{ + int nr, on_list; + struct commit_list *p, *best, *next, *last; + int *weights; + + show_list("bisection 2 entry", 0, 0, list); + + /* + * Count the number of total and tree-changing items on the + * list, while reversing the list. + */ + for (nr = on_list = 0, last = NULL, p = list; + p; + p = next) { + unsigned flags = p->item->object.flags; + + next = p->next; + if (flags & UNINTERESTING) + continue; + p->next = last; + last = p; + if (!revs.prune_fn || (flags & TREECHANGE)) + nr++; + on_list++; + } + list = last; + show_list("bisection 2 sorted", 0, nr, list); + + *all = nr; + weights = xcalloc(on_list, sizeof(*weights)); + + /* Do the real work of finding bisection commit. */ + best = do_find_bisection(list, nr, weights); + if (best) best->next = NULL; + + *reaches = weight(best); free(weights); + return best; } From 77c11e064c5daadeb42e79b7fc6b28857e9b6bb6 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 17 Sep 2007 05:28:29 +0200 Subject: [PATCH 83/94] rev-list --bisect: Move some bisection code into best_bisection. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin-rev-list.c | 43 ++++++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 2dae287129..8c9635abea 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -255,6 +255,30 @@ static void show_list(const char *debug, int counted, int nr, } #endif /* DEBUG_BISECT */ +static struct commit_list *best_bisection(struct commit_list *list, int nr) +{ + struct commit_list *p, *best; + int best_distance = -1; + + best = list; + for (p = list; p; p = p->next) { + int distance; + unsigned flags = p->item->object.flags; + + if (revs.prune_fn && !(flags & TREECHANGE)) + continue; + distance = weight(p); + if (nr - distance < distance) + distance = nr - distance; + if (distance > best_distance) { + best = p; + best_distance = distance; + } + } + + return best; +} + /* * zero or positive weight is the number of interesting commits it can * reach, including itself. Especially, weight = 0 means it does not @@ -272,7 +296,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list, int nr, int *weights) { int n, counted, distance; - struct commit_list *p, *best; + struct commit_list *p; counted = 0; @@ -377,22 +401,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list, show_list("bisection 2 counted all", counted, nr, list); /* Then find the best one */ - counted = -1; - best = list; - for (p = list; p; p = p->next) { - unsigned flags = p->item->object.flags; - - if (revs.prune_fn && !(flags & TREECHANGE)) - continue; - distance = weight(p); - if (nr - distance < distance) - distance = nr - distance; - if (distance > counted) { - best = p; - counted = distance; - } - } - return best; + return best_bisection(list, nr); } static struct commit_list *find_bisection(struct commit_list *list, From 53271411e7c4d9b92cc5aa1cc02492e9a3593d23 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Mon, 17 Sep 2007 05:28:36 +0200 Subject: [PATCH 84/94] rev-list --bisect: Bisection "distance" clean up. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- builtin-rev-list.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/builtin-rev-list.c b/builtin-rev-list.c index 8c9635abea..899a31d09a 100644 --- a/builtin-rev-list.c +++ b/builtin-rev-list.c @@ -189,7 +189,7 @@ static int count_interesting_parents(struct commit *commit) return count; } -static inline int halfway(struct commit_list *p, int distance, int nr) +static inline int halfway(struct commit_list *p, int nr) { /* * Don't short-cut something we are not going to return! @@ -202,8 +202,7 @@ static inline int halfway(struct commit_list *p, int distance, int nr) * 2 and 3 are halfway of 5. * 3 is halfway of 6 but 2 and 4 are not. */ - distance *= 2; - switch (distance - nr) { + switch (2 * weight(p) - nr) { case -1: case 0: case 1: return 1; default: @@ -295,7 +294,7 @@ static struct commit_list *best_bisection(struct commit_list *list, int nr) static struct commit_list *do_find_bisection(struct commit_list *list, int nr, int *weights) { - int n, counted, distance; + int n, counted; struct commit_list *p; counted = 0; @@ -346,15 +345,13 @@ static struct commit_list *do_find_bisection(struct commit_list *list, for (p = list; p; p = p->next) { if (p->item->object.flags & UNINTERESTING) continue; - n = weight(p); - if (n != -2) + if (weight(p) != -2) continue; - distance = count_distance(p); + weight_set(p, count_distance(p)); clear_distance(list); - weight_set(p, distance); /* Does it happen to be at exactly half-way? */ - if (halfway(p, distance, nr)) + if (halfway(p, nr)) return p; counted++; } @@ -392,8 +389,7 @@ static struct commit_list *do_find_bisection(struct commit_list *list, weight_set(p, weight(q)); /* Does it happen to be at exactly half-way? */ - distance = weight(p); - if (halfway(p, distance, nr)) + if (halfway(p, nr)) return p; } } From 7f8cfadf218c8b28caf52b1490fb8b881945b0ea Mon Sep 17 00:00:00 2001 From: Nguyen Thai Ngoc Duy Date: Tue, 18 Sep 2007 03:26:01 -0400 Subject: [PATCH 85/94] contrib/fast-import: add simple shell example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This example just puts a directory under git control. It is significantly slower than using the git tools directly, but hopefully shows a bit how fast-import works. [jk: added header comments] Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/fast-import/git-import.sh | 38 +++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100755 contrib/fast-import/git-import.sh diff --git a/contrib/fast-import/git-import.sh b/contrib/fast-import/git-import.sh new file mode 100755 index 0000000000..0ca7718d05 --- /dev/null +++ b/contrib/fast-import/git-import.sh @@ -0,0 +1,38 @@ +#!/bin/sh +# +# Performs an initial import of a directory. This is the equivalent +# of doing 'git init; git add .; git commit'. It's a lot slower, +# but is meant to be a simple fast-import example. + +if [ -z "$1" -o -z "$2" ]; then + echo "Usage: git-import branch import-message" + exit 1 +fi + +USERNAME="$(git config user.name)" +EMAIL="$(git config user.email)" + +if [ -z "$USERNAME" -o -z "$EMAIL" ]; then + echo "You need to set user name and email" + exit 1 +fi + +git init + +( + cat < now +data < Date: Tue, 18 Sep 2007 03:26:27 -0400 Subject: [PATCH 86/94] contrib/fast-import: add perl version of simple example This is based on the git-import.sh script, but is a little more robust and efficient. More importantly, it should serve as a quick template for interfacing fast-import with perl scripts. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- contrib/fast-import/git-import.perl | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100755 contrib/fast-import/git-import.perl diff --git a/contrib/fast-import/git-import.perl b/contrib/fast-import/git-import.perl new file mode 100755 index 0000000000..f9fef6db28 --- /dev/null +++ b/contrib/fast-import/git-import.perl @@ -0,0 +1,64 @@ +#!/usr/bin/perl +# +# Performs an initial import of a directory. This is the equivalent +# of doing 'git init; git add .; git commit'. It's a little slower, +# but is meant to be a simple fast-import example. + +use strict; +use File::Find; + +my $USAGE = 'Usage: git-import branch import-message'; +my $branch = shift or die "$USAGE\n"; +my $message = shift or die "$USAGE\n"; + +chomp(my $username = `git config user.name`); +chomp(my $email = `git config user.email`); +die 'You need to set user name and email' + unless $username && $email; + +system('git init'); +open(my $fi, '|-', qw(git fast-import --date-format=now)) + or die "unable to spawn fast-import: $!"; + +print $fi < now +data < 0) { + my $r = read($in, my $buf, $len < 4096 ? $len : 4096); + defined($r) or die "read error from $fn: $!"; + $r > 0 or die "premature EOF from $fn: $!"; + print $fi $buf; + $len -= $r; + } + print $fi "\n"; + + }, '.' +); + +close($fi); +exit $?; From bf1ee636780f3fcaf358827168fa8a0e26c598e2 Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Tue, 18 Sep 2007 11:29:09 +0200 Subject: [PATCH 87/94] git-svnimport: Use separate arguments in the pipe for git-rev-parse Some people seem to create SVN branch names with spaces or other shell metacharacters. Signed-off-by: Matthias Urlichs Signed-off-by: Junio C Hamano --- git-svnimport.perl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-svnimport.perl b/git-svnimport.perl index d3ad5b904f..aa5b3b2c97 100755 --- a/git-svnimport.perl +++ b/git-svnimport.perl @@ -633,7 +633,7 @@ sub commit { my $rev; if($revision > $opt_s and defined $parent) { - open(H,"git-rev-parse --verify $parent |"); + open(H,'-|',"git-rev-parse","--verify",$parent); $rev = ; close(H) or do { print STDERR "$revision: cannot find commit '$parent'!\n"; From 5c633a4cbeb95fc86c9b3e6126749cf34a2691b5 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 18 Sep 2007 04:15:34 -0400 Subject: [PATCH 88/94] git-push: documentation and tests for pushing only branches Commit 098e711e caused git-push to match only branches when considering which refs to push. This patch updates the documentation accordingly and adds a test for this behavior. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/git-push.txt | 4 ++-- Documentation/git-send-pack.txt | 4 ++-- t/t5400-send-pack.sh | 10 ++++++++++ 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt index 7b8e075c42..6bc559ddd8 100644 --- a/Documentation/git-push.txt +++ b/Documentation/git-push.txt @@ -48,7 +48,7 @@ even if it does not result in a fast forward update. Note: If no explicit refspec is found, (that is neither on the command line nor in any Push line of the corresponding remotes file---see below), then all the -refs that exist both on the local side and on the remote +heads that exist both on the local side and on the remote side are updated. + `tag ` means the same as `refs/tags/:refs/tags/`. @@ -61,7 +61,7 @@ the remote repository. \--all:: Instead of naming each ref to push, specifies that all - refs be pushed. + refs under `$GIT_DIR/refs/heads/` be pushed. \--tags:: All refs under `$GIT_DIR/refs/tags` are pushed, in diff --git a/Documentation/git-send-pack.txt b/Documentation/git-send-pack.txt index 205bfd2d25..3271e88183 100644 --- a/Documentation/git-send-pack.txt +++ b/Documentation/git-send-pack.txt @@ -32,7 +32,7 @@ OPTIONS \--all:: Instead of explicitly specifying which refs to update, - update all refs that locally exist. + update all heads that locally exist. \--force:: Usually, the command refuses to update a remote ref that @@ -70,7 +70,7 @@ With '--all' flag, all refs that exist locally are transferred to the remote side. You cannot specify any '' if you use this flag. -Without '--all' and without any '', the refs that exist +Without '--all' and without any '', the heads that exist both on the local side and on the remote side are updated. When one or more '' are specified explicitly, it can be either a diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 6c8767e1df..57c6397be1 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -113,4 +113,14 @@ test_expect_success \ ! git diff .git/refs/heads/master victim/.git/refs/heads/master ' +test_expect_success \ + 'pushing does not include non-head refs' ' + mkdir parent && cd parent && + git-init && touch file && git-add file && git-commit -m add && + cd .. && + git-clone parent child && cd child && git-push --all && + cd ../parent && + git-branch -a >branches && ! grep -q origin/master branches +' + test_done From 3d845d77639a8f91b9774b830d1a2d986a791489 Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Tue, 18 Sep 2007 12:12:58 +0200 Subject: [PATCH 89/94] Fix lapsus in builtin-apply.c Signed-off-by: Pierre Habouzit Signed-off-by: Junio C Hamano --- builtin-apply.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin-apply.c b/builtin-apply.c index 5ad371424b..bd969778e0 100644 --- a/builtin-apply.c +++ b/builtin-apply.c @@ -254,7 +254,7 @@ static char *find_name(const char *line, char *def, int p_value, int terminate) if (name) { char *cp = name; while (p_value) { - cp = strchr(name, '/'); + cp = strchr(cp, '/'); if (!cp) break; cp++; From 76bf8d0e0ad0840395471fd862bd2cdad095345d Mon Sep 17 00:00:00 2001 From: Dmitry Potapov Date: Sun, 16 Sep 2007 21:07:38 +0400 Subject: [PATCH 90/94] preserve executable bits in zip archives Correct `git-archive --format=zip' command to preserve executable bits in zip archives. Signed-off-by: Junio C Hamano --- archive-zip.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/archive-zip.c b/archive-zip.c index f63dff3834..74e30f6205 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -192,7 +192,8 @@ static int write_zip_entry(const unsigned char *sha1, compressed_size = 0; } else if (S_ISREG(mode) || S_ISLNK(mode)) { method = 0; - attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) : 0; + attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) : + (mode & 0111) ? ((mode) << 16) : 0; if (S_ISREG(mode) && zlib_compression_level != 0) method = 8; result = 0; @@ -231,7 +232,8 @@ static int write_zip_entry(const unsigned char *sha1, } copy_le32(dirent.magic, 0x02014b50); - copy_le16(dirent.creator_version, S_ISLNK(mode) ? 0x0317 : 0); + copy_le16(dirent.creator_version, + S_ISLNK(mode) || (S_ISREG(mode) && (mode & 0111)) ? 0x0317 : 0); copy_le16(dirent.version, 10); copy_le16(dirent.flags, 0); copy_le16(dirent.compression_method, method); From d28840461d9cebd79f1ec30a4117661b41e2c9a3 Mon Sep 17 00:00:00 2001 From: David Kastrup Date: Mon, 17 Sep 2007 22:56:44 +0200 Subject: [PATCH 91/94] git-commit.sh: Shell script cleanup This moves "shift" out of the argument processing "case". It also replaces quite a bit of expr calls with ${parameter#word} constructs, and uses ${parameter:+word} for avoiding conditionals where possible. Signed-off-by: David Kastrup Signed-off-by: Junio C Hamano --- git-commit.sh | 72 ++++++++++----------------------------------------- 1 file changed, 14 insertions(+), 58 deletions(-) diff --git a/git-commit.sh b/git-commit.sh index bb113e858b..3e46dbba74 100755 --- a/git-commit.sh +++ b/git-commit.sh @@ -98,101 +98,71 @@ do no_edit=t log_given=t$log_given logfile="$1" - shift ;; -F*|-f*) no_edit=t log_given=t$log_given - logfile=`expr "z$1" : 'z-[Ff]\(.*\)'` - shift + logfile="${1#-[Ff]}" ;; --F=*|--f=*|--fi=*|--fil=*|--file=*) no_edit=t log_given=t$log_given - logfile=`expr "z$1" : 'z-[^=]*=\(.*\)'` - shift + logfile="${1#*=}" ;; -a|--a|--al|--all) all=t - shift ;; --au=*|--aut=*|--auth=*|--autho=*|--author=*) - force_author=`expr "z$1" : 'z-[^=]*=\(.*\)'` - shift + force_author="${1#*=}" ;; --au|--aut|--auth|--autho|--author) case "$#" in 1) usage ;; esac shift force_author="$1" - shift ;; -e|--e|--ed|--edi|--edit) edit_flag=t - shift ;; -i|--i|--in|--inc|--incl|--inclu|--includ|--include) also=t - shift ;; --int|--inte|--inter|--intera|--interac|--interact|--interacti|\ --interactiv|--interactive) interactive=t - shift ;; -o|--o|--on|--onl|--only) only=t - shift ;; -m|--m|--me|--mes|--mess|--messa|--messag|--message) case "$#" in 1) usage ;; esac shift log_given=m$log_given - if test "$log_message" = '' - then - log_message="$1" - else - log_message="$log_message + log_message="${log_message:+${log_message} -$1" - fi +}$1" no_edit=t - shift ;; -m*) log_given=m$log_given - if test "$log_message" = '' - then - log_message=`expr "z$1" : 'z-m\(.*\)'` - else - log_message="$log_message + log_message="${log_message:+${log_message} -`expr "z$1" : 'z-m\(.*\)'`" - fi +}${1#-m}" no_edit=t - shift ;; --m=*|--me=*|--mes=*|--mess=*|--messa=*|--messag=*|--message=*) log_given=m$log_given - if test "$log_message" = '' - then - log_message=`expr "z$1" : 'z-[^=]*=\(.*\)'` - else - log_message="$log_message + log_message="${log_message:+${log_message} -`expr "z$1" : 'zq-[^=]*=\(.*\)'`" - fi +}${1#*=}" no_edit=t - shift ;; -n|--n|--no|--no-|--no-v|--no-ve|--no-ver|--no-veri|--no-verif|\ --no-verify) verify= - shift ;; --a|--am|--ame|--amen|--amend) amend=t use_commit=HEAD - shift ;; -c) case "$#" in 1) usage ;; esac @@ -200,15 +170,13 @@ $1" log_given=t$log_given use_commit="$1" no_edit= - shift ;; --ree=*|--reed=*|--reedi=*|--reedit=*|--reedit-=*|--reedit-m=*|\ --reedit-me=*|--reedit-mes=*|--reedit-mess=*|--reedit-messa=*|\ --reedit-messag=*|--reedit-message=*) log_given=t$log_given - use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` + use_commit="${1#*=}" no_edit= - shift ;; --ree|--reed|--reedi|--reedit|--reedit-|--reedit-m|--reedit-me|\ --reedit-mes|--reedit-mess|--reedit-messa|--reedit-messag|\ @@ -218,7 +186,6 @@ $1" log_given=t$log_given use_commit="$1" no_edit= - shift ;; -C) case "$#" in 1) usage ;; esac @@ -226,15 +193,13 @@ $1" log_given=t$log_given use_commit="$1" no_edit=t - shift ;; --reu=*|--reus=*|--reuse=*|--reuse-=*|--reuse-m=*|--reuse-me=*|\ --reuse-mes=*|--reuse-mess=*|--reuse-messa=*|--reuse-messag=*|\ --reuse-message=*) log_given=t$log_given - use_commit=`expr "z$1" : 'z-[^=]*=\(.*\)'` + use_commit="${1#*=}" no_edit=t - shift ;; --reu|--reus|--reuse|--reuse-|--reuse-m|--reuse-me|--reuse-mes|\ --reuse-mess|--reuse-messa|--reuse-messag|--reuse-message) @@ -243,32 +208,26 @@ $1" log_given=t$log_given use_commit="$1" no_edit=t - shift ;; -s|--s|--si|--sig|--sign|--signo|--signof|--signoff) signoff=t - shift ;; -t|--t|--te|--tem|--temp|--templ|--templa|--templat|--template) case "$#" in 1) usage ;; esac shift templatefile="$1" no_edit= - shift ;; -q|--q|--qu|--qui|--quie|--quiet) quiet=t - shift ;; -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) verbose=t - shift ;; -u|--u|--un|--unt|--untr|--untra|--untrac|--untrack|--untracke|\ --untracked|--untracked-|--untracked-f|--untracked-fi|--untracked-fil|\ --untracked-file|--untracked-files) untracked_files=t - shift ;; --) shift @@ -281,6 +240,7 @@ $1" break ;; esac + shift done case "$edit_flag" in t) no_edit= ;; esac @@ -441,12 +401,8 @@ esac if test t = "$verify" && test -x "$GIT_DIR"/hooks/pre-commit then - if test "$TMP_INDEX" - then - GIT_INDEX_FILE="$TMP_INDEX" "$GIT_DIR"/hooks/pre-commit - else - GIT_INDEX_FILE="$USE_INDEX" "$GIT_DIR"/hooks/pre-commit - fi || exit + GIT_INDEX_FILE="${TMP_INDEX:-${USE_INDEX}}" "$GIT_DIR"/hooks/pre-commit \ + || exit fi if test "$log_message" != '' From cd894ee9adf0c026b74761d7b1c0d8dabe4ff4e1 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 18 Sep 2007 15:19:47 -0700 Subject: [PATCH 92/94] t/t4014: test "am -3" with mode-only change. Earlier commit ece7b74903007cee8d280573647243d46a6f3a95 added a test for rebase that uses "am -3", but this adds a test to check "am -3" itself. Signed-off-by: Junio C Hamano --- t/t4014-format-patch.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index df969bb69c..0a6fe53375 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -10,12 +10,15 @@ test_description='Format-patch skipping already incorporated patches' test_expect_success setup ' for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file && - git add file && + cat file >elif && + git add file elif && git commit -m Initial && git checkout -b side && for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file && - git update-index file && + chmod +x elif && + git update-index file elif && + git update-index --chmod=+x elif && git commit -m "Side changes #1" && for i in D E F; do echo "$i"; done >>file && From bd43098c26cca4e831405d6114df5ad911550124 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 18 Sep 2007 16:50:42 -0700 Subject: [PATCH 93/94] Documentation/git-svn: updated design philosophy notes This section has not been updated in a while and --branches/--tags/--trunk options are commonly used nowadays. Noticed-by: Lars Hjemli Signed-off-by: Eric Wong Signed-off-by: Junio C Hamano --- Documentation/git-svn.txt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Documentation/git-svn.txt b/Documentation/git-svn.txt index be2e34eb8f..e157c6ab50 100644 --- a/Documentation/git-svn.txt +++ b/Documentation/git-svn.txt @@ -478,11 +478,12 @@ previous commits in SVN. DESIGN PHILOSOPHY ----------------- Merge tracking in Subversion is lacking and doing branched development -with Subversion is cumbersome as a result. git-svn does not do -automated merge/branch tracking by default and leaves it entirely up to -the user on the git side. git-svn does however follow copy -history of the directory that it is tracking, however (much like -how 'svn log' works). +with Subversion can be cumbersome as a result. While git-svn can track +copy history (including branches and tags) for repositories adopting a +standard layout, it cannot yet represent merge history that happened +inside git back upstream to SVN users. Therefore it is advised that +users keep history as linear as possible inside git to ease +compatibility with SVN (see the CAVEATS section below). CAVEATS ------- From 8ae674952c8f301034e8ae9dceff38dda740623b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A4in=C3=B6=20J=C3=A4rvel=C3=A4?= Date: Tue, 18 Sep 2007 15:26:09 +0300 Subject: [PATCH 94/94] Fixed update-hook example allow-users format. The example provided with the update-hook-example does not work on either bash 2.05b.0(1)-release nor 3.1.17(1)-release. The matcher did not match the lines that it advertised to match, such as: refs/heads/bw/ linus refs/heads/tmp/* * In POSIX 1003.2 regular expressions, the star (*), is not an wildcard meaning "match everything", it matches 0 or more matches of the atom preceding it. So to match "refs/heads/bw/topic-branch", the matcher should be written as "refs/heads/bw/.*" to match "refs/heads/bw/" and everything after it. Signed-off-by: Junio C Hamano --- Documentation/howto/update-hook-example.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Documentation/howto/update-hook-example.txt b/Documentation/howto/update-hook-example.txt index 3a33696f00..88765b5575 100644 --- a/Documentation/howto/update-hook-example.txt +++ b/Documentation/howto/update-hook-example.txt @@ -158,11 +158,11 @@ This uses two files, $GIT_DIR/info/allowed-users and allowed-groups, to describe which heads can be pushed into by whom. The format of each file would look like this: - refs/heads/master junio + refs/heads/master junio refs/heads/cogito$ pasky - refs/heads/bw/ linus - refs/heads/tmp/ * - refs/tags/v[0-9]* junio + refs/heads/bw/.* linus + refs/heads/tmp/.* .* + refs/tags/v[0-9].* junio With this, Linus can push or create "bw/penguin" or "bw/zebra" or "bw/panda" branches, Pasky can do only "cogito", and JC can