Fix rev-list when showing objects involving submodules
The function mark_tree_uninteresting() assumed that the tree entries are blob when they are not trees. This is not so. Since we do not traverse into submodules (yet), the gitlinks should be ignored. In general, we should try to start moving away from using the "S_ISLNK()" like things for internal git state. It was a mistake to just assume the numbers all were same across all systems in the first place. This implementation converts to the "object_type", and then uses a case statement. Noticed by Ilari on IRC. Test script taken from an earlier version by Dscho. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Linus Torvalds committed
Nov 11, 2007 at 23:35 UTC
4d1012c3709e356107d0fb0e3bf5a39e0d5c209d
4 files changed
+59
-3
builtin-pack-objects.c
+1
-1
@@ -990,7 +990,7 @@ static void add_pbase_object(struct tree_desc *tree,
990
return;
991
if (name[cmplen] != '/') {
992
add_object_entry(entry.sha1,
993
- S_ISDIR(entry.mode) ? OBJ_TREE : OBJ_BLOB,
993
+ object_type(entry.mode),
994
fullname, 1);
995
return;
996
}
revision.c
+9
-2
@@ -65,10 +65,17 @@ void mark_tree_uninteresting(struct tree *tree)
65
66
init_tree_desc(&desc, tree->buffer, tree->size);
67
while (tree_entry(&desc, &entry)) {
68
- if (S_ISDIR(entry.mode))
68
+ switch (object_type(entry.mode)) {
69
+ case OBJ_TREE:
70
mark_tree_uninteresting(lookup_tree(entry.sha1));
70
- else
71
+ break;
72
+ case OBJ_BLOB:
73
mark_blob_uninteresting(lookup_blob(entry.sha1));
74
+ break;
75
+ default:
76
+ /* Subproject commit - not in this repository */
77
+ break;
78
+ }
79
}
80
81
/*
t/t6008-rev-list-submodule.sh
new
+42
@@ -0,0 +1,42 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2007 Johannes E. Schindelin
4
+#
5
+
6
+test_description='git rev-list involving submodules that this repo has'
7
+
8
+. ./test-lib.sh
9
+
10
+test_expect_success 'setup' '
11
+ : > file &&
12
+ git add file &&
13
+ test_tick &&
14
+ git commit -m initial &&
15
+ echo 1 > file &&
16
+ test_tick &&
17
+ git commit -m second file &&
18
+ echo 2 > file &&
19
+ test_tick &&
20
+ git commit -m third file &&
21
+
22
+ rm .git/index &&
23
+
24
+ : > super-file &&
25
+ git add super-file &&
26
+ git submodule add . sub &&
27
+ git symbolic-ref HEAD refs/heads/super &&
28
+ test_tick &&
29
+ git commit -m super-initial &&
30
+ echo 1 > super-file &&
31
+ test_tick &&
32
+ git commit -m super-first super-file &&
33
+ echo 2 > super-file &&
34
+ test_tick &&
35
+ git commit -m super-second super-file
36
+'
37
+
38
+test_expect_success "Ilari's test" '
39
+ git rev-list --objects super master ^super^
40
+'
41
+
42
+test_done
tree-walk.h
+7
@@ -7,6 +7,13 @@ struct name_entry {
7
unsigned int mode;
8
};
9
10
+static inline enum object_type object_type(unsigned int mode)
11
+{
12
+ return S_ISDIR(mode) ? OBJ_TREE :
13
+ S_ISGITLINK(mode) ? OBJ_COMMIT :
14
+ OBJ_BLOB;
15
+}
16
+
17
struct tree_desc {
18
const void *buffer;
19
struct name_entry entry;