Separate object listing routines out of rev-list
Create a separate file, list-objects.c, and move object listing routines from rev-list to it. The next round will use it in pack-objects directly. Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
		
							
								
								
									
										4
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								Makefile
									
									
									
									
									
								
							@ -233,7 +233,7 @@ XDIFF_LIB=xdiff/lib.a
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
LIB_H = \
 | 
					LIB_H = \
 | 
				
			||||||
	blob.h cache.h commit.h csum-file.h delta.h \
 | 
						blob.h cache.h commit.h csum-file.h delta.h \
 | 
				
			||||||
	diff.h object.h pack.h pkt-line.h quote.h refs.h \
 | 
						diff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h \
 | 
				
			||||||
	run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
 | 
						run-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \
 | 
				
			||||||
	tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h
 | 
						tree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -250,7 +250,7 @@ LIB_OBJS = \
 | 
				
			|||||||
	server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
 | 
						server-info.o setup.o sha1_file.o sha1_name.o strbuf.o \
 | 
				
			||||||
	tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
 | 
						tag.o tree.o usage.o config.o environment.o ctype.o copy.o \
 | 
				
			||||||
	fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
 | 
						fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
 | 
				
			||||||
	write_or_die.o trace.o \
 | 
						write_or_die.o trace.o list-objects.o \
 | 
				
			||||||
	alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS)
 | 
						alloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
BUILTIN_OBJS = \
 | 
					BUILTIN_OBJS = \
 | 
				
			||||||
 | 
				
			|||||||
@ -7,6 +7,7 @@
 | 
				
			|||||||
#include "tree-walk.h"
 | 
					#include "tree-walk.h"
 | 
				
			||||||
#include "diff.h"
 | 
					#include "diff.h"
 | 
				
			||||||
#include "revision.h"
 | 
					#include "revision.h"
 | 
				
			||||||
 | 
					#include "list-objects.h"
 | 
				
			||||||
#include "builtin.h"
 | 
					#include "builtin.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* bits #0-15 in revision.h */
 | 
					/* bits #0-15 in revision.h */
 | 
				
			||||||
@ -98,104 +99,19 @@ static void show_commit(struct commit *commit)
 | 
				
			|||||||
	commit->buffer = NULL;
 | 
						commit->buffer = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void process_blob(struct blob *blob,
 | 
					static void show_object(struct object_array_entry *p)
 | 
				
			||||||
			 struct object_array *p,
 | 
					 | 
				
			||||||
			 struct name_path *path,
 | 
					 | 
				
			||||||
			 const char *name)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	struct object *obj = &blob->object;
 | 
						/* An object with name "foo\n0000000..." can be used to
 | 
				
			||||||
 | 
						 * confuse downstream git-pack-objects very badly.
 | 
				
			||||||
	if (!revs.blob_objects)
 | 
						 */
 | 
				
			||||||
		return;
 | 
						const char *ep = strchr(p->name, '\n');
 | 
				
			||||||
	if (obj->flags & (UNINTERESTING | SEEN))
 | 
						if (ep) {
 | 
				
			||||||
		return;
 | 
							printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
 | 
				
			||||||
	obj->flags |= SEEN;
 | 
							       (int) (ep - p->name),
 | 
				
			||||||
	name = xstrdup(name);
 | 
							       p->name);
 | 
				
			||||||
	add_object(obj, p, path, name);
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void process_tree(struct tree *tree,
 | 
					 | 
				
			||||||
			 struct object_array *p,
 | 
					 | 
				
			||||||
			 struct name_path *path,
 | 
					 | 
				
			||||||
			 const char *name)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	struct object *obj = &tree->object;
 | 
					 | 
				
			||||||
	struct tree_desc desc;
 | 
					 | 
				
			||||||
	struct name_entry entry;
 | 
					 | 
				
			||||||
	struct name_path me;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (!revs.tree_objects)
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	if (obj->flags & (UNINTERESTING | SEEN))
 | 
					 | 
				
			||||||
		return;
 | 
					 | 
				
			||||||
	if (parse_tree(tree) < 0)
 | 
					 | 
				
			||||||
		die("bad tree object %s", sha1_to_hex(obj->sha1));
 | 
					 | 
				
			||||||
	obj->flags |= SEEN;
 | 
					 | 
				
			||||||
	name = xstrdup(name);
 | 
					 | 
				
			||||||
	add_object(obj, p, path, name);
 | 
					 | 
				
			||||||
	me.up = path;
 | 
					 | 
				
			||||||
	me.elem = name;
 | 
					 | 
				
			||||||
	me.elem_len = strlen(name);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	desc.buf = tree->buffer;
 | 
					 | 
				
			||||||
	desc.size = tree->size;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	while (tree_entry(&desc, &entry)) {
 | 
					 | 
				
			||||||
		if (S_ISDIR(entry.mode))
 | 
					 | 
				
			||||||
			process_tree(lookup_tree(entry.sha1), p, &me, entry.path);
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			process_blob(lookup_blob(entry.sha1), p, &me, entry.path);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	free(tree->buffer);
 | 
					 | 
				
			||||||
	tree->buffer = NULL;
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
static void show_commit_list(struct rev_info *revs)
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
	int i;
 | 
					 | 
				
			||||||
	struct commit *commit;
 | 
					 | 
				
			||||||
	struct object_array objects = { 0, 0, NULL };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	while ((commit = get_revision(revs)) != NULL) {
 | 
					 | 
				
			||||||
		process_tree(commit->tree, &objects, NULL, "");
 | 
					 | 
				
			||||||
		show_commit(commit);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for (i = 0; i < revs->pending.nr; i++) {
 | 
					 | 
				
			||||||
		struct object_array_entry *pending = revs->pending.objects + i;
 | 
					 | 
				
			||||||
		struct object *obj = pending->item;
 | 
					 | 
				
			||||||
		const char *name = pending->name;
 | 
					 | 
				
			||||||
		if (obj->flags & (UNINTERESTING | SEEN))
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		if (obj->type == OBJ_TAG) {
 | 
					 | 
				
			||||||
			obj->flags |= SEEN;
 | 
					 | 
				
			||||||
			add_object_array(obj, name, &objects);
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (obj->type == OBJ_TREE) {
 | 
					 | 
				
			||||||
			process_tree((struct tree *)obj, &objects, NULL, name);
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		if (obj->type == OBJ_BLOB) {
 | 
					 | 
				
			||||||
			process_blob((struct blob *)obj, &objects, NULL, name);
 | 
					 | 
				
			||||||
			continue;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	for (i = 0; i < objects.nr; i++) {
 | 
					 | 
				
			||||||
		struct object_array_entry *p = objects.objects + i;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		/* An object with name "foo\n0000000..." can be used to
 | 
					 | 
				
			||||||
		 * confuse downstream git-pack-objects very badly.
 | 
					 | 
				
			||||||
		 */
 | 
					 | 
				
			||||||
		const char *ep = strchr(p->name, '\n');
 | 
					 | 
				
			||||||
		if (ep) {
 | 
					 | 
				
			||||||
			printf("%s %.*s\n", sha1_to_hex(p->item->sha1),
 | 
					 | 
				
			||||||
			       (int) (ep - p->name),
 | 
					 | 
				
			||||||
			       p->name);
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
		else
 | 
					 | 
				
			||||||
			printf("%s %s\n", sha1_to_hex(p->item->sha1), p->name);
 | 
					 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						else
 | 
				
			||||||
 | 
							printf("%s %s\n", sha1_to_hex(p->item->sha1), p->name);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@ -389,7 +305,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 | 
				
			|||||||
	if (bisect_list)
 | 
						if (bisect_list)
 | 
				
			||||||
		revs.commits = find_bisection(revs.commits);
 | 
							revs.commits = find_bisection(revs.commits);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	show_commit_list(&revs);
 | 
						traverse_commit_list(&revs, show_commit, show_object);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return 0;
 | 
						return 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										107
									
								
								list-objects.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										107
									
								
								list-objects.c
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,107 @@
 | 
				
			|||||||
 | 
					#include "cache.h"
 | 
				
			||||||
 | 
					#include "tag.h"
 | 
				
			||||||
 | 
					#include "commit.h"
 | 
				
			||||||
 | 
					#include "tree.h"
 | 
				
			||||||
 | 
					#include "blob.h"
 | 
				
			||||||
 | 
					#include "diff.h"
 | 
				
			||||||
 | 
					#include "tree-walk.h"
 | 
				
			||||||
 | 
					#include "revision.h"
 | 
				
			||||||
 | 
					#include "list-objects.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void process_blob(struct rev_info *revs,
 | 
				
			||||||
 | 
								 struct blob *blob,
 | 
				
			||||||
 | 
								 struct object_array *p,
 | 
				
			||||||
 | 
								 struct name_path *path,
 | 
				
			||||||
 | 
								 const char *name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct object *obj = &blob->object;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!revs->blob_objects)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						if (obj->flags & (UNINTERESTING | SEEN))
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						obj->flags |= SEEN;
 | 
				
			||||||
 | 
						name = xstrdup(name);
 | 
				
			||||||
 | 
						add_object(obj, p, path, name);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static void process_tree(struct rev_info *revs,
 | 
				
			||||||
 | 
								 struct tree *tree,
 | 
				
			||||||
 | 
								 struct object_array *p,
 | 
				
			||||||
 | 
								 struct name_path *path,
 | 
				
			||||||
 | 
								 const char *name)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						struct object *obj = &tree->object;
 | 
				
			||||||
 | 
						struct tree_desc desc;
 | 
				
			||||||
 | 
						struct name_entry entry;
 | 
				
			||||||
 | 
						struct name_path me;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!revs->tree_objects)
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						if (obj->flags & (UNINTERESTING | SEEN))
 | 
				
			||||||
 | 
							return;
 | 
				
			||||||
 | 
						if (parse_tree(tree) < 0)
 | 
				
			||||||
 | 
							die("bad tree object %s", sha1_to_hex(obj->sha1));
 | 
				
			||||||
 | 
						obj->flags |= SEEN;
 | 
				
			||||||
 | 
						name = xstrdup(name);
 | 
				
			||||||
 | 
						add_object(obj, p, path, name);
 | 
				
			||||||
 | 
						me.up = path;
 | 
				
			||||||
 | 
						me.elem = name;
 | 
				
			||||||
 | 
						me.elem_len = strlen(name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						desc.buf = tree->buffer;
 | 
				
			||||||
 | 
						desc.size = tree->size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (tree_entry(&desc, &entry)) {
 | 
				
			||||||
 | 
							if (S_ISDIR(entry.mode))
 | 
				
			||||||
 | 
								process_tree(revs,
 | 
				
			||||||
 | 
									     lookup_tree(entry.sha1),
 | 
				
			||||||
 | 
									     p, &me, entry.path);
 | 
				
			||||||
 | 
							else
 | 
				
			||||||
 | 
								process_blob(revs,
 | 
				
			||||||
 | 
									     lookup_blob(entry.sha1),
 | 
				
			||||||
 | 
									     p, &me, entry.path);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						free(tree->buffer);
 | 
				
			||||||
 | 
						tree->buffer = NULL;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void traverse_commit_list(struct rev_info *revs,
 | 
				
			||||||
 | 
								  void (*show_commit)(struct commit *),
 | 
				
			||||||
 | 
								  void (*show_object)(struct object_array_entry *))
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						int i;
 | 
				
			||||||
 | 
						struct commit *commit;
 | 
				
			||||||
 | 
						struct object_array objects = { 0, 0, NULL };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while ((commit = get_revision(revs)) != NULL) {
 | 
				
			||||||
 | 
							process_tree(revs, commit->tree, &objects, NULL, "");
 | 
				
			||||||
 | 
							show_commit(commit);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for (i = 0; i < revs->pending.nr; i++) {
 | 
				
			||||||
 | 
							struct object_array_entry *pending = revs->pending.objects + i;
 | 
				
			||||||
 | 
							struct object *obj = pending->item;
 | 
				
			||||||
 | 
							const char *name = pending->name;
 | 
				
			||||||
 | 
							if (obj->flags & (UNINTERESTING | SEEN))
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							if (obj->type == OBJ_TAG) {
 | 
				
			||||||
 | 
								obj->flags |= SEEN;
 | 
				
			||||||
 | 
								add_object_array(obj, name, &objects);
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (obj->type == OBJ_TREE) {
 | 
				
			||||||
 | 
								process_tree(revs, (struct tree *)obj, &objects,
 | 
				
			||||||
 | 
									     NULL, name);
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if (obj->type == OBJ_BLOB) {
 | 
				
			||||||
 | 
								process_blob(revs, (struct blob *)obj, &objects,
 | 
				
			||||||
 | 
									     NULL, name);
 | 
				
			||||||
 | 
								continue;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							die("unknown pending object %s (%s)",
 | 
				
			||||||
 | 
							    sha1_to_hex(obj->sha1), name);
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						for (i = 0; i < objects.nr; i++)
 | 
				
			||||||
 | 
							show_object(&objects.objects[i]);
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										8
									
								
								list-objects.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								list-objects.h
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,8 @@
 | 
				
			|||||||
 | 
					#ifndef LIST_OBJECTS_H
 | 
				
			||||||
 | 
					#define LIST_OBJECTS_H
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void traverse_commit_list(struct rev_info *revs,
 | 
				
			||||||
 | 
								  void (*show_commit)(struct commit *),
 | 
				
			||||||
 | 
								  void (*show_object)(struct object_array_entry *));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
		Reference in New Issue
	
	Block a user