9 #include "cache-tree.h"
11 static void process_blob(struct blob
*blob
,
12 struct object_array
*p
,
13 struct name_path
*path
,
16 struct object
*obj
= &blob
->object
;
18 if (obj
->flags
& SEEN
)
21 /* Nothing to do, really .. The blob lookup was the important part */
24 static void process_tree(struct tree
*tree
,
25 struct object_array
*p
,
26 struct name_path
*path
,
29 struct object
*obj
= &tree
->object
;
30 struct tree_desc desc
;
31 struct name_entry entry
;
34 if (obj
->flags
& SEEN
)
37 if (parse_tree(tree
) < 0)
38 die("bad tree object %s", sha1_to_hex(obj
->sha1
));
40 add_object(obj
, p
, path
, name
);
43 me
.elem_len
= strlen(name
);
45 init_tree_desc(&desc
, tree
->buffer
, tree
->size
);
47 while (tree_entry(&desc
, &entry
)) {
48 if (S_ISDIR(entry
.mode
))
49 process_tree(lookup_tree(entry
.sha1
), p
, &me
, entry
.path
);
51 process_blob(lookup_blob(entry
.sha1
), p
, &me
, entry
.path
);
57 static void process_tag(struct tag
*tag
, struct object_array
*p
, const char *name
)
59 struct object
*obj
= &tag
->object
;
62 if (obj
->flags
& SEEN
)
70 if (parse_tag(tag
) < 0)
71 die("bad tag object %s", sha1_to_hex(obj
->sha1
));
72 add_object(tag
->tagged
, p
, NULL
, name
);
75 static void walk_commit_list(struct rev_info
*revs
)
78 struct commit
*commit
;
79 struct object_array objects
= { 0, 0, NULL
};
81 /* Walk all commits, process their trees */
82 while ((commit
= get_revision(revs
)) != NULL
)
83 process_tree(commit
->tree
, &objects
, NULL
, "");
85 /* Then walk all the pending objects, recursively processing them too */
86 for (i
= 0; i
< revs
->pending
.nr
; i
++) {
87 struct object_array_entry
*pending
= revs
->pending
.objects
+ i
;
88 struct object
*obj
= pending
->item
;
89 const char *name
= pending
->name
;
90 if (obj
->type
== OBJ_TAG
) {
91 process_tag((struct tag
*) obj
, &objects
, name
);
94 if (obj
->type
== OBJ_TREE
) {
95 process_tree((struct tree
*)obj
, &objects
, NULL
, name
);
98 if (obj
->type
== OBJ_BLOB
) {
99 process_blob((struct blob
*)obj
, &objects
, NULL
, name
);
102 die("unknown pending object %s (%s)", sha1_to_hex(obj
->sha1
), name
);
106 static int add_one_reflog_ent(unsigned char *osha1
, unsigned char *nsha1
,
107 const char *email
, unsigned long timestamp
, int tz
,
108 const char *message
, void *cb_data
)
110 struct object
*object
;
111 struct rev_info
*revs
= (struct rev_info
*)cb_data
;
113 object
= parse_object(osha1
);
115 add_pending_object(revs
, object
, "");
116 object
= parse_object(nsha1
);
118 add_pending_object(revs
, object
, "");
122 static int add_one_ref(const char *path
, const unsigned char *sha1
, int flag
, void *cb_data
)
124 struct object
*object
= parse_object(sha1
);
125 struct rev_info
*revs
= (struct rev_info
*)cb_data
;
128 die("bad object ref: %s:%s", path
, sha1_to_hex(sha1
));
129 add_pending_object(revs
, object
, "");
134 static int add_one_reflog(const char *path
, const unsigned char *sha1
, int flag
, void *cb_data
)
136 for_each_reflog_ent(path
, add_one_reflog_ent
, cb_data
);
140 static void add_one_tree(const unsigned char *sha1
, struct rev_info
*revs
)
142 struct tree
*tree
= lookup_tree(sha1
);
143 add_pending_object(revs
, &tree
->object
, "");
146 static void add_cache_tree(struct cache_tree
*it
, struct rev_info
*revs
)
150 if (it
->entry_count
>= 0)
151 add_one_tree(it
->sha1
, revs
);
152 for (i
= 0; i
< it
->subtree_nr
; i
++)
153 add_cache_tree(it
->down
[i
]->cache_tree
, revs
);
156 static void add_cache_refs(struct rev_info
*revs
)
161 for (i
= 0; i
< active_nr
; i
++) {
162 lookup_blob(active_cache
[i
]->sha1
);
164 * We could add the blobs to the pending list, but quite
165 * frankly, we don't care. Once we've looked them up, and
166 * added them as objects, we've really done everything
167 * there is to do for a blob
170 if (active_cache_tree
)
171 add_cache_tree(active_cache_tree
, revs
);
174 void mark_reachable_objects(struct rev_info
*revs
, int mark_reflog
)
177 * Set up revision parsing, and mark us as being interested
178 * in all object types, not just commits.
180 revs
->tag_objects
= 1;
181 revs
->blob_objects
= 1;
182 revs
->tree_objects
= 1;
184 /* Add all refs from the index file */
185 add_cache_refs(revs
);
187 /* Add all external refs */
188 for_each_ref(add_one_ref
, revs
);
190 /* Add all reflog info */
192 for_each_reflog(add_one_reflog
, revs
);
195 * Set up the revision walk - this will move all commits
196 * from the pending list to the commit walking list.
198 prepare_revision_walk(revs
);
199 walk_commit_list(revs
);