Skip to content

Commit

Permalink
Merge branch 'jc/cache-tree'
Browse files Browse the repository at this point in the history
* jc/cache-tree: (26 commits)
  builtin-rm: squelch compiler warnings.
  git-write-tree writes garbage on sparc64
  Fix crash when reading the empty tree
  fsck-objects: do not segfault on missing tree in cache-tree
  cache-tree: a bit more debugging support.
  read-tree: invalidate cache-tree entry when a new index entry is added.
  Fix test-dump-cache-tree in one-tree disappeared case.
  fsck-objects: mark objects reachable from cache-tree
  cache-tree: replace a sscanf() by two strtol() calls
  cache-tree.c: typefix
  test-dump-cache-tree: validate the cached data as well.
  cache_tree_update: give an option to update cache-tree only.
  read-tree: teach 1-way merege and plain read to prime cache-tree.
  read-tree: teach 1 and 2 way merges about cache-tree.
  update-index: when --unresolve, smudge the relevant cache-tree entries.
  test-dump-cache-tree: report number of subtrees.
  cache-tree: sort the subtree entries.
  Teach fsck-objects about cache-tree.
  index: make the index file format extensible.
  cache-tree: protect against "git prune".
  ...

Conflicts:

	Makefile, builtin.h, git.c: resolved the same way as in next.
  • Loading branch information
Junio C Hamano committed May 29, 2006
2 parents 7d65848 + 7d55561 commit 3f69d40
Show file tree
Hide file tree
Showing 15 changed files with 834 additions and 128 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ git-write-tree
git-core-*/?*
test-date
test-delta
test-dump-cache-tree
common-cmds.h
*.tar.gz
*.dsc
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ DIFF_OBJS = \
diffcore-delta.o log-tree.o

LIB_OBJS = \
blob.o commit.o connect.o csum-file.o base85.o \
blob.o commit.o connect.o csum-file.o cache-tree.o base85.o \
date.o diff-delta.o entry.o exec_cmd.o ident.o index.o \
object.o pack-check.o patch-delta.o path.o pkt-line.o \
quote.o read-cache.o refs.o run-command.o dir.o \
Expand Down Expand Up @@ -626,6 +626,9 @@ test-date$X: test-date.c date.o ctype.o
test-delta$X: test-delta.c diff-delta.o patch-delta.o
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $^

test-dump-cache-tree$X: dump-cache-tree.o $(GITLIBS)
$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)

check:
for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i || exit; done

Expand Down
2 changes: 2 additions & 0 deletions builtin-add.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "cache.h"
#include "builtin.h"
#include "dir.h"
#include "cache-tree.h"

static const char builtin_add_usage[] =
"git-add [-n] [-v] <filepattern>...";
Expand Down Expand Up @@ -117,6 +118,7 @@ static int add_file_to_index(const char *path, int verbose)
die("unable to add %s to index",path);
if (verbose)
printf("add '%s'\n", path);
cache_tree_invalidate_path(active_cache_tree, path);
return 0;
}

Expand Down
5 changes: 4 additions & 1 deletion builtin-apply.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#include <fnmatch.h>
#include "cache.h"
#include "cache-tree.h"
#include "quote.h"
#include "blob.h"
#include "delta.h"
Expand Down Expand Up @@ -1918,6 +1919,7 @@ static void remove_file(struct patch *patch)
if (write_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)
unlink(patch->old_name);
Expand Down Expand Up @@ -2019,8 +2021,9 @@ static void create_file(struct patch *patch)

if (!mode)
mode = S_IFREG | 0644;
create_one_file(path, mode, buf, size);
create_one_file(path, mode, buf, size);
add_index_file(path, mode, buf, size);
cache_tree_invalidate_path(active_cache_tree, path);
}

static void write_out_one_result(struct patch *patch)
Expand Down
62 changes: 59 additions & 3 deletions builtin-read-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "object.h"
#include "tree.h"
#include "cache-tree.h"
#include <sys/time.h>
#include <signal.h>
#include "builtin.h"
Expand Down Expand Up @@ -427,6 +428,12 @@ static void verify_uptodate(struct cache_entry *ce)
die("Entry '%s' not uptodate. Cannot merge.", ce->name);
}

static void invalidate_ce_path(struct cache_entry *ce)
{
if (ce)
cache_tree_invalidate_path(active_cache_tree, ce->name);
}

/*
* We do not want to remove or overwrite a working tree file that
* is not tracked.
Expand Down Expand Up @@ -457,10 +464,13 @@ static int merged_entry(struct cache_entry *merge, struct cache_entry *old)
*merge = *old;
} else {
verify_uptodate(old);
invalidate_ce_path(old);
}
}
else
else {
verify_absent(merge->name, "overwritten");
invalidate_ce_path(merge);
}

merge->ce_flags &= ~htons(CE_STAGEMASK);
add_cache_entry(merge, ADD_CACHE_OK_TO_ADD);
Expand All @@ -475,6 +485,7 @@ static int deleted_entry(struct cache_entry *ce, struct cache_entry *old)
verify_absent(ce->name, "removed");
ce->ce_mode = 0;
add_cache_entry(ce, ADD_CACHE_OK_TO_ADD);
invalidate_ce_path(ce);
return 1;
}

Expand Down Expand Up @@ -750,6 +761,7 @@ static int read_cache_unmerged(void)
struct cache_entry *ce = active_cache[i];
if (ce_stage(ce)) {
deleted++;
invalidate_ce_path(ce);
continue;
}
if (deleted)
Expand All @@ -760,6 +772,39 @@ static int read_cache_unmerged(void)
return deleted;
}

static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
{
struct tree_entry_list *ent;
int cnt;

memcpy(it->sha1, tree->object.sha1, 20);
for (cnt = 0, ent = tree->entries; ent; ent = ent->next) {
if (!ent->directory)
cnt++;
else {
struct cache_tree_sub *sub;
struct tree *subtree = (struct tree *)ent->item.tree;
if (!subtree->object.parsed)
parse_tree(subtree);
sub = cache_tree_sub(it, ent->name);
sub->cache_tree = cache_tree();
prime_cache_tree_rec(sub->cache_tree, subtree);
cnt += sub->cache_tree->entry_count;
}
}
it->entry_count = cnt;
}

static void prime_cache_tree(void)
{
struct tree *tree = (struct tree *)trees->item;
if (!tree)
return;
active_cache_tree = cache_tree();
prime_cache_tree_rec(active_cache_tree, tree);

}

static const char read_tree_usage[] = "git-read-tree (<sha> | -m [--aggressive] [-u | -i] <sha1> [<sha2> [<sha3>]])";

static struct cache_file cache_file;
Expand Down Expand Up @@ -861,10 +906,9 @@ int cmd_read_tree(int argc, const char **argv, char **envp)
fn = twoway_merge;
break;
case 3:
fn = threeway_merge;
break;
default:
fn = threeway_merge;
cache_tree_free(&active_cache_tree);
break;
}

Expand All @@ -875,6 +919,18 @@ int cmd_read_tree(int argc, const char **argv, char **envp)
}

unpack_trees(fn);

/*
* When reading only one tree (either the most basic form,
* "-m ent" or "--reset ent" form), we can obtain a fully
* valid cache-tree because the index must match exactly
* what came from the tree.
*/
if (trees && trees->item && (!merge || (stage == 2))) {
cache_tree_free(&active_cache_tree);
prime_cache_tree();
}

if (write_cache(newfd, active_cache, active_nr) ||
commit_index_file(&cache_file))
die("unable to write new index file");
Expand Down
2 changes: 2 additions & 0 deletions builtin-rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "cache.h"
#include "builtin.h"
#include "dir.h"
#include "cache-tree.h"

static const char builtin_rm_usage[] =
"git-rm [-n] [-v] [-f] <filepattern>...";
Expand Down Expand Up @@ -117,6 +118,7 @@ int cmd_rm(int argc, const char **argv, char **envp)

if (remove_file_from_cache(path))
die("git rm: unable to remove %s", path);
cache_tree_invalidate_path(active_cache_tree, path);
}

/*
Expand Down
Loading

0 comments on commit 3f69d40

Please sign in to comment.