void traverse_commit_list(struct rev_info *revs, show_commit_fn show_commit, show_object_fn show_object, void *data) { int i; struct commit *commit; struct strbuf base; strbuf_init(&base, PATH_MAX); while ((commit = get_revision(revs)) != NULL) { /* * an uninteresting boundary commit may not have its tree * parsed yet, but we are not going to show them anyway */ if (commit->tree) add_pending_tree(revs, commit->tree); show_commit(commit, data); } 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; show_object(obj, NULL, name); continue; } if (obj->type == OBJ_TREE) { process_tree(revs, (struct tree *)obj, show_object, NULL, &base, name); continue; } if (obj->type == OBJ_BLOB) { process_blob(revs, (struct blob *)obj, show_object, NULL, name); continue; } die("unknown pending object %s (%s)", sha1_to_hex(obj->sha1), name); } if (revs->pending.nr) { free(revs->pending.objects); revs->pending.nr = 0; revs->pending.alloc = 0; revs->pending.objects = NULL; } strbuf_release(&base); }
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]); free(objects.objects); if (revs->pending.nr) { free(revs->pending.objects); revs->pending.nr = 0; revs->pending.alloc = 0; revs->pending.objects = NULL; } }
static int get_delta(struct rev_info *revs, struct remote_lock *lock) { int i; struct commit *commit; struct object_list **p = &objects; int count = 0; while ((commit = get_revision(revs)) != NULL) { p = process_tree(commit->tree, p); commit->object.flags |= LOCAL; if (!(commit->object.flags & UNINTERESTING)) count += add_send_request(&commit->object, lock); } for (i = 0; i < revs->pending.nr; i++) { struct object_array_entry *entry = revs->pending.objects + i; struct object *obj = entry->item; const char *name = entry->name; if (obj->flags & (UNINTERESTING | SEEN)) continue; if (obj->type == OBJ_TAG) { obj->flags |= SEEN; p = add_one_object(obj, p); continue; } if (obj->type == OBJ_TREE) { p = process_tree((struct tree *)obj, p); continue; } if (obj->type == OBJ_BLOB) { p = process_blob((struct blob *)obj, p); continue; } die("unknown pending object %s (%s)", oid_to_hex(&obj->oid), name); } while (objects) { if (!(objects->item->flags & UNINTERESTING)) count += add_send_request(objects->item, lock); objects = objects->next; } return count; }
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) die("bad tree object"); 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); init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { if (S_ISDIR(entry.mode)) process_tree(revs, lookup_tree(entry.sha1), p, &me, entry.path); else if (S_ISGITLINK(entry.mode)) process_gitlink(revs, entry.sha1, p, &me, entry.path); else process_blob(revs, lookup_blob(entry.sha1), p, &me, entry.path); } free(tree->buffer); tree->buffer = NULL; }
static void traverse_trees_and_blobs(struct rev_info *revs, struct strbuf *base, show_object_fn show_object, void *show_data, filter_object_fn filter_fn, void *filter_data) { int i; assert(base->len == 0); 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; const char *path = pending->path; if (obj->flags & (UNINTERESTING | SEEN)) continue; if (obj->type == OBJ_TAG) { obj->flags |= SEEN; show_object(obj, name, show_data); continue; } if (!path) path = ""; if (obj->type == OBJ_TREE) { process_tree(revs, (struct tree *)obj, show_object, base, path, show_data, filter_fn, filter_data); continue; } if (obj->type == OBJ_BLOB) { process_blob(revs, (struct blob *)obj, show_object, base, path, show_data, filter_fn, filter_data); continue; } die("unknown pending object %s (%s)", oid_to_hex(&obj->oid), name); } object_array_clear(&revs->pending); }
static void process_tree(struct rev_info *revs, struct tree *tree, show_object_fn show, struct name_path *path, struct strbuf *base, const char *name) { struct object *obj = &tree->object; struct tree_desc desc; struct name_entry entry; struct name_path me; int all_interesting = (revs->diffopt.pathspec.nr == 0); int baselen = base->len; if (!revs->tree_objects) return; if (!obj) die("bad tree object"); if (obj->flags & (UNINTERESTING | SEEN)) return; if (parse_tree(tree) < 0) die("bad tree object %s", sha1_to_hex(obj->sha1)); obj->flags |= SEEN; show(obj, path, name); me.up = path; me.elem = name; me.elem_len = strlen(name); if (!all_interesting) { strbuf_addstr(base, name); if (base->len) strbuf_addch(base, '/'); } init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { if (!all_interesting) { int showit = tree_entry_interesting(&entry, base, 0, &revs->diffopt.pathspec); if (showit < 0) break; else if (!showit) continue; else if (showit == 2) all_interesting = 1; } if (S_ISDIR(entry.mode)) process_tree(revs, lookup_tree(entry.sha1), show, &me, base, entry.path); else if (S_ISGITLINK(entry.mode)) process_gitlink(revs, entry.sha1, show, &me, entry.path); else process_blob(revs, lookup_blob(entry.sha1), show, &me, entry.path); } strbuf_setlen(base, baselen); free(tree->buffer); tree->buffer = NULL; }
static void process_tree(struct rev_info *revs, struct tree *tree, show_object_fn show, struct strbuf *base, const char *name, void *cb_data) { struct object *obj = &tree->object; struct tree_desc desc; struct name_entry entry; enum interesting match = revs->diffopt.pathspec.nr == 0 ? all_entries_interesting: entry_not_interesting; int baselen = base->len; if (!revs->tree_objects) return; if (!obj) die("bad tree object"); if (obj->flags & (UNINTERESTING | SEEN)) return; if (parse_tree_gently(tree, revs->ignore_missing_links) < 0) { if (revs->ignore_missing_links) return; die("bad tree object %s", oid_to_hex(&obj->oid)); } obj->flags |= SEEN; strbuf_addstr(base, name); show(obj, base->buf, cb_data); if (base->len) strbuf_addch(base, '/'); init_tree_desc(&desc, tree->buffer, tree->size); while (tree_entry(&desc, &entry)) { if (match != all_entries_interesting) { match = tree_entry_interesting(&entry, base, 0, &revs->diffopt.pathspec); if (match == all_entries_not_interesting) break; if (match == entry_not_interesting) continue; } if (S_ISDIR(entry.mode)) process_tree(revs, lookup_tree(entry.sha1), show, base, entry.path, cb_data); else if (S_ISGITLINK(entry.mode)) process_gitlink(revs, entry.sha1, show, base, entry.path, cb_data); else process_blob(revs, lookup_blob(entry.sha1), show, base, entry.path, cb_data); } strbuf_setlen(base, baselen); free_tree_buffer(tree); }