Skip to contentSkip to conversation

full integration of rev-cache into git's revision walker, completed test suite

PATCH In review Nick Edelen 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 5/5 full integration of rev-cache into git's revision walker, completed test suite

This last patch provides a working integration of rev-cache into the revision walker, along with some touch-ups:
- integration into revision walker and list-objects
- addition of 'unique' field to commit objects, optionally initialized in rev-cache with the objects introduced in that commit
- tweak of object generation to take advantage of the 'unique' field
- more fluid handling of damaged cache slices
- numerous tests for both features from the previous patch, and the
integration's integrity

'Integration' is rather broad -- a more detailed description follows for each aspect:
- rev-cache
the traversal mechanism is updated to handle many of the non-prune options rev-list does (date limiting, slop-handling, etc.), and is adjusted to allow for non-fatal cache-traversal failures.

- revision walker
both limited and unlimited traversal attempt to use the cache when possible, smoothly falling back if it's not.

- list-objects
object listing does not recurse into cached trees, and has been adjusted to guarantee commit-tag-tree-blob ordering.

---
 builtin-rev-cache.c       |   46 +++++++-
 commit.c                  |    2 +-
 commit.h                  |    1 +
 list-objects.c            |   49 ++++++-
 rev-cache.c               |  303 ++++++++++++++++++++++++++++++++++++++------
 revision.c                |   87 +++++++++++---
 t/t6015-rev-cache-list.sh |  120 ++++++++++++++++--
 7 files changed, 529 insertions(+), 79 deletions(-)
builtin-rev-cache.c +43 -3
index 44916f5..05ee9dd 100755
@@ -3,6 +3,7 @@
 #include "commit.h"
 #include "diff.h"
 #include "revision.h"
+#include "list-objects.h"
 
 #define DEFAULT_IGNORE_SLICE_SIZE		5000000 /* in bytes */
 
@@ -69,6 +70,43 @@ static int handle_add(int argc, const char *argv[]) /* args beyond this command
 	return 0;
 }
 
+static void show_commit(struct commit *commit, void *data)
+{
+	printf("%s\n", sha1_to_hex(commit->object.sha1));
+}
+
+static void show_object(struct object *obj, const struct name_path *path, const char *last)
+{
+	printf("%s\n", sha1_to_hex(obj->sha1));
+}
+
+static int test_rev_list(int argc, const char *argv[])
+{
+	struct rev_info revs;
+	unsigned int flags = 0;
+	int i;
+	
+	init_revisions(&revs, 0);
+	
+	for (i = 0; i < argc; i++) {
+		if (!strcmp(argv[i], "--not"))
+			flags ^= UNINTERESTING;
+		else if (!strcmp(argv[i], "--objects"))
+			revs.tree_objects = revs.blob_objects = 1;
+		else
+			handle_revision_arg(argv[i], &revs, flags, 1);
+	}
+	
+	setup_revisions(0, 0, &revs, 0);
+	revs.topo_order = 1;
+	revs.lifo = 1;
+	prepare_revision_walk(&revs);
+	
+	traverse_commit_list(&revs, show_commit, show_object, 0);
+	
+	return 0;
+}
+
 static int handle_walk(int argc, const char *argv[])
 {
 	struct commit *commit;
@@ -117,17 +155,17 @@ static int handle_walk(int argc, const char *argv[])
 	if (retval < 0)
 		return retval;
 	
-	printf("queue:\n");
+	fprintf(stderr, "queue:\n");
 	while ((commit = pop_commit(&queue)) != 0) {
 		printf("%s\n", sha1_to_hex(commit->object.sha1));
 	}
 	
-	printf("work:\n");
+	fprintf(stderr, "work:\n");
 	while ((commit = pop_commit(&work)) != 0) {
 		printf("%s\n", sha1_to_hex(commit->object.sha1));
 	}
 	
-	printf("pending:\n");
+	fprintf(stderr, "pending:\n");
 	for (i = 0; i < revs.pending.nr; i++) {
 		struct object *obj = revs.pending.objects[i].item;
 		
@@ -235,6 +273,8 @@ int cmd_rev_cache(int argc, const char *argv[], const char *prefix)
 		r = handle_walk(argc, argv);
 	else if (!strcmp(arg, "index"))
 		r = handle_index(argc, argv);
+	else if (!strcmp(arg, "test"))
+		r = test_rev_list(argc, argv);
 	else
 		return handle_help();
 	
commit.c +1 -1
index afe504f..1b710c2 100644
@@ -252,7 +252,7 @@ int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size)
 			     sha1_to_hex(item->object.sha1));
 	item->tree = lookup_tree(parent);
 	bufptr += 46; /* "tree " + "hex sha1" + "\n" */
- 	pptr = &item->parents;
+	pptr = &item->parents;
 	while (pop_commit(pptr))
 		; /* clear anything from cache */
 
commit.h +1 -0
index 0529fcf..7c50a7f 100644
@@ -20,6 +20,7 @@ struct commit {
 	struct tree *tree;
 	char *buffer;
 	unsigned long size;
+	struct object_list *unique;
 };
 
 extern int save_commit_buffer;
list-objects.c +42 -7

93 lines not on this page · raw message

rev-cache.c +261 -42

525 lines not on this page · raw message

revision.c +71 -16

136 lines not on this page · raw message

t/t6015-rev-cache-list.sh +110 -10

166 lines not on this page · raw message

#1 lore raw
Quoted 3 lines · Nick Edelen

This last patch provides a working integration of rev-cache into the revision walker, along with some touch-ups:

"This last patch" is redundant. You can just write "Integrate rev-cache into the revision walker;"

Quoted 8 lines

- integration into revision walker and list-objects
- addition of 'unique' field to commit objects, optionally initialized in rev-cache with the objects introduced in that commit
- tweak of object generation to take advantage of the 'unique' field
- more fluid handling of damaged cache slices
- numerous tests for both features from the previous patch, and the
integration's integrity

Does it make sense to split this integration up or stage it somehow?

Quoted 7 lines

'Integration' is rather broad -- a more detailed description follows for each aspect:
- rev-cache
the traversal mechanism is updated to handle many of the non-prune options rev-list does (date limiting, slop-handling, etc.), and is adjusted to allow for non-fatal cache-traversal failures.

Quoted 8 lines

- revision walker
both limited and unlimited traversal attempt to use the cache when possible, smoothly falling back if it's not.

- list-objects
object listing does not recurse into cached trees, and has been adjusted to guarantee commit-tag-tree-blob ordering.

Especially given the length of this part of the commit message.

Sam

#2 lore raw
In reply to Nick Edelen

A small patch to eliminate the python dependency in rev-cache's test-suite. This is a holdover for the 'integration' patch until a revised patchset is sent.

---
I've also implemented name caching, but I'd like to cleanup that (and the docs ;-) up a bit before posting it. I'll have everything ready for public display by tonight (I've got an appointment for the next several hours).

 t/t6015-rev-cache-list.sh |   39 +++++++++++++++++++++------------------
 t/t6015-sha1-dump-diff.py |   36 ------------------------------------
 2 files changed, 21 insertions(+), 54 deletions(-)
t/t6015-rev-cache-list.sh +21 -18
index bfd9525..7c3719d 100755
@@ -3,7 +3,11 @@
 test_description='git rev-cache tests'
 . ./test-lib.sh
 
-sha1diff="python $TEST_DIRECTORY/t6015-sha1-dump-diff.py"
+test_cmp_sorted() {
+	grep -io "[a-f0-9]*" $1 | sort >.tmpfile1 && 
+	grep -io "[a-f0-9]*" $2 | sort >.tmpfile2 && 
+	test_cmp .tmpfile1 .tmpfile2
+}
 
 # we want a totally wacked out branch structure...
 # we need branching and merging of sizes up through 3, tree 
@@ -99,49 +103,49 @@ test_expect_success 'remake cache slice' '
 #check core mechanics and rev-list hook for commits
 test_expect_success 'test rev-caches walker directly (limited)' '
 	git-rev-cache walk HEAD --not HEAD~3 >list && 
-	test -z `$sha1diff list proper_commit_list_limited`
+	test_cmp_sorted list proper_commit_list_limited
 '
 
 test_expect_success 'test rev-caches walker directly (unlimited)' '
 	git-rev-cache walk HEAD >list && 
-	test -z `$sha1diff list proper_commit_list`
+	test_cmp_sorted list proper_commit_list
 '
 
 test_expect_success 'test rev-list traversal (limited)' '
 	git-rev-list HEAD --not HEAD~3 >list && 
-	test -z `$sha1diff list proper_commit_list_limited`
+	test_cmp list proper_commit_list_limited
 '
 
 test_expect_success 'test rev-list traversal (unlimited)' '
 	git-rev-list HEAD >list && 
-	test -z `$sha1diff list proper_commit_list`
+	test_cmp list proper_commit_list
 '
 
 #do the same for objects
 test_expect_success 'test rev-caches walker with objects' '
 	git-rev-cache walk --objects HEAD >list && 
-	test -z `$sha1diff list proper_object_list`
+	test_cmp_sorted list proper_object_list
 '
 
 test_expect_success 'test rev-list with objects (topo order)' '
 	git-rev-list --topo-order --objects HEAD >list && 
-	test -z `$sha1diff list proper_object_list`
+	test_cmp_sorted list proper_object_list
 '
 
 test_expect_success 'test rev-list with objects (no order)' '
 	git-rev-list --objects HEAD >list && 
-	test -z `$sha1diff list proper_object_list`
+	test_cmp_sorted list proper_object_list
 '
 
 #verify age limiting
 test_expect_success 'test rev-list date limiting (topo order)' '
 	git-rev-list --topo-order --max-age=$min_date --min-age=$max_date HEAD >list && 
-	test -z `$sha1diff list proper_list_date_limited`
+	test_cmp_sorted list proper_list_date_limited
 '
 
 test_expect_success 'test rev-list date limiting (no order)' '
 	git-rev-list --max-age=$min_date --min-age=$max_date HEAD >list && 
-	test -z `sha1diff list proper_list_date_limited`
+	test_cmp_sorted list proper_list_date_limited
 '
 
 #check partial cache slice
@@ -154,7 +158,7 @@ test_expect_success 'saving old cache and generating partial slice' '
 '
 
 test_expect_success 'rev-list with wholly interesting partial slice' '
-	git-rev-list --topo-order HEAD >list &&
+	git-rev-list --topo-order HEAD >list && 
 	test_cmp list proper_commit_list
 '
 
@@ -199,13 +203,13 @@ test_expect_success 'corrupt slice' '
 '
 
 test_expect_success 'test rev-list traversal (limited) (corrupt slice)' '
-	git-rev-list HEAD --not HEAD~3 >list && 
-	test -z `$sha1diff list proper_commit_list_limited`
+	git-rev-list --topo-order HEAD --not HEAD~3 >list && 
+	test_cmp list proper_commit_list_limited
 '
 
 test_expect_success 'test rev-list traversal (unlimited) (corrupt slice)' '
 	git-rev-list HEAD >list && 
-	test -z `$sha1diff list proper_commit_list`
+	test_cmp_sorted list proper_commit_list
 '
 
 test_expect_success 'corrupt index' '
@@ -213,16 +217,15 @@ test_expect_success 'corrupt index' '
 '
 
 test_expect_success 'test rev-list traversal (limited) (corrupt index)' '
-	git-rev-list HEAD --not HEAD~3 >list && 
-	test -z `$sha1diff list proper_commit_list_limited`
+	git-rev-list --topo-order HEAD --not HEAD~3 >list && 
+	test_cmp list proper_commit_list_limited
 '
 
 test_expect_success 'test rev-list traversal (unlimited) (corrupt index)' '
 	git-rev-list HEAD >list && 
-	test -z `$sha1diff list proper_commit_list`
+	test_cmp_sorted list proper_commit_list
 '
 
 #test --ignore-size in fuse?
 
 test_done
-
t/t6015-sha1-dump-diff.py deleted +0 -36
deleted file mode 100755
index 7fc30e7..0000000
@@ -1,36 +0,0 @@
-
-import sys, re
-
-if len(sys.argv) < 3 : 
-	sys.exit(0)
-
-f = open(sys.argv[1], 'r')
-dict = {}
-for line in f : 
-	if len(line) >= 40 and re.match(r'^[0-9a-fA-F]{40}', line[:40]) != None : 
-		dict[line[:40]] = 1
-
-f.close()
-
-f = open(sys.argv[2], 'r')
-for line in f :
-	if len(line) < 40 : 
-		continue
-	
-	hash = line[:40]
-	if re.match(r'^[0-9a-fA-F]{40}', hash) == None : 
-		continue
-	
-	if hash in dict : 
-		dict[hash] -= 1
-	else : 
-		dict[hash] = -1
-
-f.close()
-
-for k in dict.keys() : 
-	if dict[k] == 0 : 
-		del dict[k]
-
-if len(dict) : 
-	print dict

---