+ if (max_count != -1 && !max_count--)
+ return STOP;
+ return DO;
+}
+
+static int process_commit(struct commit * commit)
+{
+ int action=filter_commit(commit);
+
+ if (action == STOP) {
+ return STOP;
+ }
+
+ if (action == CONTINUE) {
+ return CONTINUE;
+ }
+
+ show_commit(commit);
+
+ return CONTINUE;
+}
+
+static struct object_list **add_object(struct object *obj, struct object_list **p)
+{
+ struct object_list *entry = xmalloc(sizeof(*entry));
+ entry->item = obj;
+ entry->next = NULL;
+ *p = entry;
+ return &entry->next;
+}
+
+static struct object_list **process_blob(struct blob *blob, struct object_list **p)
+{
+ struct object *obj = &blob->object;
+
+ if (!blob_objects)
+ return p;
+ if (obj->flags & (UNINTERESTING | SEEN))
+ return p;
+ obj->flags |= SEEN;
+ return add_object(obj, p);
+}
+
+static struct object_list **process_tree(struct tree *tree, struct object_list **p)
+{
+ struct object *obj = &tree->object;
+ struct tree_entry_list *entry;
+
+ if (!tree_objects)
+ return p;
+ if (obj->flags & (UNINTERESTING | SEEN))
+ return p;
+ if (parse_tree(tree) < 0)
+ die("bad tree object %s", sha1_to_hex(obj->sha1));
+ obj->flags |= SEEN;
+ p = add_object(obj, p);
+ for (entry = tree->entries ; entry ; entry = entry->next) {
+ if (entry->directory)
+ p = process_tree(entry->item.tree, p);
+ else
+ p = process_blob(entry->item.blob, p);
+ }
+ return p;