{"thread":{"id":"5481","subject":"[PATCH 1/2] Separate object listing routines out of rev-list","startedAt":"2006-09-05T07:30:27Z","lastAt":"2006-09-05T07:30:27Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"26348","messageId":"7vd5aakbxo.fsf@assigned-by-dhcp.cox.net","threadId":"5481","inReplyTo":null,"subject":"[PATCH 1/2] Separate object listing routines out of rev-list","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-09-05T07:30:27Z","receivedAt":"2006-09-05T07:30:27Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Create a separate file, list-objects.c, and move object listing\nroutines from rev-list to it.  The next round will use it in\npack-objects directly.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n Makefile           |    4 +-\n builtin-rev-list.c |  110 ++++++----------------------------------------------\n list-objects.c     |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++\n list-objects.h     |    8 ++++\n 4 files changed, 130 insertions(+), 99 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 7b3114f..18cd79e 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -233,7 +233,7 @@ XDIFF_LIB=xdiff/lib.a\n \n LIB_H = \\\n \tblob.h cache.h commit.h csum-file.h delta.h \\\n-\tdiff.h object.h pack.h pkt-line.h quote.h refs.h \\\n+\tdiff.h object.h pack.h pkt-line.h quote.h refs.h list-objects.h \\\n \trun-command.h strbuf.h tag.h tree.h git-compat-util.h revision.h \\\n \ttree-walk.h log-tree.h dir.h path-list.h unpack-trees.h builtin.h\n \n@@ -250,7 +250,7 @@ LIB_OBJS = \\\n \tserver-info.o setup.o sha1_file.o sha1_name.o strbuf.o \\\n \ttag.o tree.o usage.o config.o environment.o ctype.o copy.o \\\n \tfetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \\\n-\twrite_or_die.o trace.o \\\n+\twrite_or_die.o trace.o list-objects.o \\\n \talloc.o merge-file.o path-list.o help.o unpack-trees.o $(DIFF_OBJS)\n \n BUILTIN_OBJS = \\\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 8437454..d6dcba2 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -7,6 +7,7 @@ #include \"blob.h\"\n #include \"tree-walk.h\"\n #include \"diff.h\"\n #include \"revision.h\"\n+#include \"list-objects.h\"\n #include \"builtin.h\"\n \n /* bits #0-15 in revision.h */\n@@ -97,104 +98,19 @@ static void show_commit(struct commit *c\n \tcommit->buffer = NULL;\n }\n \n-static void process_blob(struct blob *blob,\n-\t\t\t struct object_array *p,\n-\t\t\t struct name_path *path,\n-\t\t\t const char *name)\n+static void show_object(struct object_array_entry *p)\n {\n-\tstruct object *obj = &blob->object;\n-\n-\tif (!revs.blob_objects)\n-\t\treturn;\n-\tif (obj->flags & (UNINTERESTING | SEEN))\n-\t\treturn;\n-\tobj->flags |= SEEN;\n-\tname = xstrdup(name);\n-\tadd_object(obj, p, path, name);\n-}\n-\n-static void process_tree(struct tree *tree,\n-\t\t\t struct object_array *p,\n-\t\t\t struct name_path *path,\n-\t\t\t const char *name)\n-{\n-\tstruct object *obj = &tree->object;\n-\tstruct tree_desc desc;\n-\tstruct name_entry entry;\n-\tstruct name_path me;\n-\n-\tif (!revs.tree_objects)\n-\t\treturn;\n-\tif (obj->flags & (UNINTERESTING | SEEN))\n-\t\treturn;\n-\tif (parse_tree(tree) < 0)\n-\t\tdie(\"bad tree object %s\", sha1_to_hex(obj->sha1));\n-\tobj->flags |= SEEN;\n-\tname = xstrdup(name);\n-\tadd_object(obj, p, path, name);\n-\tme.up = path;\n-\tme.elem = name;\n-\tme.elem_len = strlen(name);\n-\n-\tdesc.buf = tree->buffer;\n-\tdesc.size = tree->size;\n-\n-\twhile (tree_entry(&desc, &entry)) {\n-\t\tif (S_ISDIR(entry.mode))\n-\t\t\tprocess_tree(lookup_tree(entry.sha1), p, &me, entry.path);\n-\t\telse\n-\t\t\tprocess_blob(lookup_blob(entry.sha1), p, &me, entry.path);\n-\t}\n-\tfree(tree->buffer);\n-\ttree->buffer = NULL;\n-}\n-\n-static void show_commit_list(struct rev_info *revs)\n-{\n-\tint i;\n-\tstruct commit *commit;\n-\tstruct object_array objects = { 0, 0, NULL };\n-\n-\twhile ((commit = get_revision(revs)) != NULL) {\n-\t\tprocess_tree(commit->tree, &objects, NULL, \"\");\n-\t\tshow_commit(commit);\n-\t}\n-\tfor (i = 0; i < revs->pending.nr; i++) {\n-\t\tstruct object_array_entry *pending = revs->pending.objects + i;\n-\t\tstruct object *obj = pending->item;\n-\t\tconst char *name = pending->name;\n-\t\tif (obj->flags & (UNINTERESTING | SEEN))\n-\t\t\tcontinue;\n-\t\tif (obj->type == OBJ_TAG) {\n-\t\t\tobj->flags |= SEEN;\n-\t\t\tadd_object_array(obj, name, &objects);\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (obj->type == OBJ_TREE) {\n-\t\t\tprocess_tree((struct tree *)obj, &objects, NULL, name);\n-\t\t\tcontinue;\n-\t\t}\n-\t\tif (obj->type == OBJ_BLOB) {\n-\t\t\tprocess_blob((struct blob *)obj, &objects, NULL, name);\n-\t\t\tcontinue;\n-\t\t}\n-\t\tdie(\"unknown pending object %s (%s)\", sha1_to_hex(obj->sha1), name);\n-\t}\n-\tfor (i = 0; i < objects.nr; i++) {\n-\t\tstruct object_array_entry *p = objects.objects + i;\n-\n-\t\t/* An object with name \"foo\\n0000000...\" can be used to\n-\t\t * confuse downstream git-pack-objects very badly.\n-\t\t */\n-\t\tconst char *ep = strchr(p->name, '\\n');\n-\t\tif (ep) {\n-\t\t\tprintf(\"%s %.*s\\n\", sha1_to_hex(p->item->sha1),\n-\t\t\t       (int) (ep - p->name),\n-\t\t\t       p->name);\n-\t\t}\n-\t\telse\n-\t\t\tprintf(\"%s %s\\n\", sha1_to_hex(p->item->sha1), p->name);\n+\t/* An object with name \"foo\\n0000000...\" can be used to\n+\t * confuse downstream git-pack-objects very badly.\n+\t */\n+\tconst char *ep = strchr(p->name, '\\n');\n+\tif (ep) {\n+\t\tprintf(\"%s %.*s\\n\", sha1_to_hex(p->item->sha1),\n+\t\t       (int) (ep - p->name),\n+\t\t       p->name);\n \t}\n+\telse\n+\t\tprintf(\"%s %s\\n\", sha1_to_hex(p->item->sha1), p->name);\n }\n \n /*\n@@ -364,7 +280,7 @@ int cmd_rev_list(int argc, const char **\n \tif (bisect_list)\n \t\trevs.commits = find_bisection(revs.commits);\n \n-\tshow_commit_list(&revs);\n+\ttraverse_commit_list(&revs, show_commit, show_object);\n \n \treturn 0;\n }\ndiff --git a/list-objects.c b/list-objects.c\nnew file mode 100644\nindex 0000000..adaf997\n--- /dev/null\n+++ b/list-objects.c\n@@ -0,0 +1,107 @@\n+#include \"cache.h\"\n+#include \"tag.h\"\n+#include \"commit.h\"\n+#include \"tree.h\"\n+#include \"blob.h\"\n+#include \"diff.h\"\n+#include \"tree-walk.h\"\n+#include \"revision.h\"\n+#include \"list-objects.h\"\n+\n+static void process_blob(struct rev_info *revs,\n+\t\t\t struct blob *blob,\n+\t\t\t struct object_array *p,\n+\t\t\t struct name_path *path,\n+\t\t\t const char *name)\n+{\n+\tstruct object *obj = &blob->object;\n+\n+\tif (!revs->blob_objects)\n+\t\treturn;\n+\tif (obj->flags & (UNINTERESTING | SEEN))\n+\t\treturn;\n+\tobj->flags |= SEEN;\n+\tname = xstrdup(name);\n+\tadd_object(obj, p, path, name);\n+}\n+\n+static void process_tree(struct rev_info *revs,\n+\t\t\t struct tree *tree,\n+\t\t\t struct object_array *p,\n+\t\t\t struct name_path *path,\n+\t\t\t const char *name)\n+{\n+\tstruct object *obj = &tree->object;\n+\tstruct tree_desc desc;\n+\tstruct name_entry entry;\n+\tstruct name_path me;\n+\n+\tif (!revs->tree_objects)\n+\t\treturn;\n+\tif (obj->flags & (UNINTERESTING | SEEN))\n+\t\treturn;\n+\tif (parse_tree(tree) < 0)\n+\t\tdie(\"bad tree object %s\", sha1_to_hex(obj->sha1));\n+\tobj->flags |= SEEN;\n+\tname = xstrdup(name);\n+\tadd_object(obj, p, path, name);\n+\tme.up = path;\n+\tme.elem = name;\n+\tme.elem_len = strlen(name);\n+\n+\tdesc.buf = tree->buffer;\n+\tdesc.size = tree->size;\n+\n+\twhile (tree_entry(&desc, &entry)) {\n+\t\tif (S_ISDIR(entry.mode))\n+\t\t\tprocess_tree(revs,\n+\t\t\t\t     lookup_tree(entry.sha1),\n+\t\t\t\t     p, &me, entry.path);\n+\t\telse\n+\t\t\tprocess_blob(revs,\n+\t\t\t\t     lookup_blob(entry.sha1),\n+\t\t\t\t     p, &me, entry.path);\n+\t}\n+\tfree(tree->buffer);\n+\ttree->buffer = NULL;\n+}\n+\n+void traverse_commit_list(struct rev_info *revs,\n+\t\t\t  void (*show_commit)(struct commit *),\n+\t\t\t  void (*show_object)(struct object_array_entry *))\n+{\n+\tint i;\n+\tstruct commit *commit;\n+\tstruct object_array objects = { 0, 0, NULL };\n+\n+\twhile ((commit = get_revision(revs)) != NULL) {\n+\t\tprocess_tree(revs, commit->tree, &objects, NULL, \"\");\n+\t\tshow_commit(commit);\n+\t}\n+\tfor (i = 0; i < revs->pending.nr; i++) {\n+\t\tstruct object_array_entry *pending = revs->pending.objects + i;\n+\t\tstruct object *obj = pending->item;\n+\t\tconst char *name = pending->name;\n+\t\tif (obj->flags & (UNINTERESTING | SEEN))\n+\t\t\tcontinue;\n+\t\tif (obj->type == OBJ_TAG) {\n+\t\t\tobj->flags |= SEEN;\n+\t\t\tadd_object_array(obj, name, &objects);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (obj->type == OBJ_TREE) {\n+\t\t\tprocess_tree(revs, (struct tree *)obj, &objects,\n+\t\t\t\t     NULL, name);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tif (obj->type == OBJ_BLOB) {\n+\t\t\tprocess_blob(revs, (struct blob *)obj, &objects,\n+\t\t\t\t     NULL, name);\n+\t\t\tcontinue;\n+\t\t}\n+\t\tdie(\"unknown pending object %s (%s)\",\n+\t\t    sha1_to_hex(obj->sha1), name);\n+\t}\n+\tfor (i = 0; i < objects.nr; i++)\n+\t\tshow_object(&objects.objects[i]);\n+}\ndiff --git a/list-objects.h b/list-objects.h\nnew file mode 100644\nindex 0000000..8a5fae6\n--- /dev/null\n+++ b/list-objects.h\n@@ -0,0 +1,8 @@\n+#ifndef LIST_OBJECTS_H\n+#define LIST_OBJECTS_H\n+\n+void traverse_commit_list(struct rev_info *revs,\n+\t\t\t  void (*show_commit)(struct commit *),\n+\t\t\t  void (*show_object)(struct object_array_entry *));\n+\n+#endif\n-- \n1.4.2.g552e5\n"}]}