Skip to content

Commit

Permalink
Merge branch 'lt/objlist' into next
Browse files Browse the repository at this point in the history
* lt/objlist:
  Add "named object array" concept
  xdiff: minor changes to match libxdiff-0.21
  fix rfc2047 formatter.
  Fix t8001-annotate and t8002-blame for ActiveState Perl
  Add specialized object allocator
  • Loading branch information
Junio C Hamano committed Jun 20, 2006
2 parents 474bc4e + 1f1e895 commit b19beec
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 148 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ LIB_OBJS = \
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 \
fetch-clone.o revision.o pager.o tree-walk.o xdiff-interface.o \
$(DIFF_OBJS)
alloc.o $(DIFF_OBJS)

BUILTIN_OBJS = \
builtin-log.o builtin-help.o builtin-count.o builtin-diff.o builtin-push.o \
Expand Down
51 changes: 51 additions & 0 deletions alloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* alloc.c - specialized allocator for internal objects
*
* Copyright (C) 2006 Linus Torvalds
*
* The standard malloc/free wastes too much space for objects, partly because
* it maintains all the allocation infrastructure (which isn't needed, since
* we never free an object descriptor anyway), but even more because it ends
* up with maximal alignment because it doesn't know what the object alignment
* for the new allocation is.
*/
#include "cache.h"
#include "object.h"
#include "blob.h"
#include "tree.h"
#include "commit.h"
#include "tag.h"

#define BLOCKING 1024

#define DEFINE_ALLOCATOR(name) \
static unsigned int name##_allocs; \
struct name *alloc_##name##_node(void) \
{ \
static int nr; \
static struct name *block; \
\
if (!nr) { \
nr = BLOCKING; \
block = xcalloc(BLOCKING, sizeof(struct name)); \
} \
nr--; \
name##_allocs++; \
return block++; \
}

DEFINE_ALLOCATOR(blob)
DEFINE_ALLOCATOR(tree)
DEFINE_ALLOCATOR(commit)
DEFINE_ALLOCATOR(tag)

#define REPORT(name) \
fprintf(stderr, "%10s: %8u (%zu kB)\n", #name, name##_allocs, name##_allocs*sizeof(struct name) >> 10)

void alloc_report(void)
{
REPORT(blob);
REPORT(tree);
REPORT(commit);
REPORT(tag);
}
2 changes: 1 addition & 1 deletion blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ struct blob *lookup_blob(const unsigned char *sha1)
{
struct object *obj = lookup_object(sha1);
if (!obj) {
struct blob *ret = xcalloc(1, sizeof(struct blob));
struct blob *ret = alloc_blob_node();
created_object(sha1, &ret->object);
ret->object.type = TYPE_BLOB;
return ret;
Expand Down
2 changes: 1 addition & 1 deletion builtin-diff-files.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int cmd_diff_files(int argc, const char **argv, char **envp)
* rev.max_count is reasonable (0 <= n <= 3),
* there is no other revision filtering parameters.
*/
if (rev.pending_objects ||
if (rev.pending.nr ||
rev.min_age != -1 || rev.max_age != -1)
usage(diff_files_usage);
/*
Expand Down
2 changes: 1 addition & 1 deletion builtin-diff-index.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int cmd_diff_index(int argc, const char **argv, char **envp)
* Make sure there is one revision (i.e. pending object),
* and there is no revision filtering parameters.
*/
if (!rev.pending_objects || rev.pending_objects->next ||
if (rev.pending.nr != 1 ||
rev.max_count != -1 || rev.min_age != -1 || rev.max_age != -1)
usage(diff_cache_usage);
return run_diff_index(&rev, cached);
Expand Down
42 changes: 12 additions & 30 deletions builtin-diff-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ int cmd_diff_tree(int argc, const char **argv, char **envp)
char line[1000];
struct object *tree1, *tree2;
static struct rev_info *opt = &log_tree_opt;
struct object_list *list;
int read_stdin = 0;

git_config(git_diff_config);
Expand All @@ -86,45 +85,28 @@ int cmd_diff_tree(int argc, const char **argv, char **envp)
}

/*
* NOTE! "setup_revisions()" will have inserted the revisions
* it parsed in reverse order. So if you do
*
* git-diff-tree a b
*
* the commit list will be "b" -> "a" -> NULL, so we reverse
* the order of the objects if the first one is not marked
* UNINTERESTING.
* NOTE! We expect "a ^b" to be equal to "a..b", so we
* reverse the order of the objects if the second one
* is marked UNINTERESTING.
*/
nr_sha1 = 0;
list = opt->pending_objects;
if (list) {
nr_sha1++;
tree1 = list->item;
list = list->next;
if (list) {
nr_sha1++;
tree2 = tree1;
tree1 = list->item;
if (list->next)
usage(diff_tree_usage);
/* Switch them around if the second one was uninteresting.. */
if (tree2->flags & UNINTERESTING) {
struct object *tmp = tree2;
tree2 = tree1;
tree1 = tmp;
}
}
}

nr_sha1 = opt->pending.nr;
switch (nr_sha1) {
case 0:
if (!read_stdin)
usage(diff_tree_usage);
break;
case 1:
tree1 = opt->pending.objects[0].item;
diff_tree_commit_sha1(tree1->sha1);
break;
case 2:
tree1 = opt->pending.objects[0].item;
tree2 = opt->pending.objects[1].item;
if (tree2->flags & UNINTERESTING) {
struct object *tmp = tree2;
tree2 = tree1;
tree1 = tmp;
}
diff_tree_sha1(tree1->sha1,
tree2->sha1,
"", &opt->diffopt);
Expand Down
26 changes: 14 additions & 12 deletions builtin-diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static int builtin_diff_files(struct rev_info *revs,
* specified rev.max_count is reasonable (0 <= n <= 3), and
* there is no other revision filtering parameter.
*/
if (revs->pending_objects ||
if (revs->pending.nr ||
revs->min_age != -1 ||
revs->max_age != -1 ||
3 < revs->max_count)
Expand Down Expand Up @@ -172,7 +172,7 @@ static int builtin_diff_index(struct rev_info *revs,
* Make sure there is one revision (i.e. pending object),
* and there is no revision filtering parameters.
*/
if (!revs->pending_objects || revs->pending_objects->next ||
if (revs->pending.nr != 1 ||
revs->max_count != -1 || revs->min_age != -1 ||
revs->max_age != -1)
usage(builtin_diff_usage);
Expand All @@ -181,10 +181,10 @@ static int builtin_diff_index(struct rev_info *revs,

static int builtin_diff_tree(struct rev_info *revs,
int argc, const char **argv,
struct object_list *ent)
struct object_array_entry *ent)
{
const unsigned char *(sha1[2]);
int swap = 1;
int swap = 0;
while (1 < argc) {
const char *arg = argv[1];
if (!strcmp(arg, "--raw"))
Expand All @@ -195,10 +195,10 @@ static int builtin_diff_tree(struct rev_info *revs,
}

/* We saw two trees, ent[0] and ent[1].
* unless ent[0] is unintesting, they are swapped
* if ent[1] is unintesting, they are swapped
*/
if (ent[0].item->flags & UNINTERESTING)
swap = 0;
if (ent[1].item->flags & UNINTERESTING)
swap = 1;
sha1[swap] = ent[0].item->sha1;
sha1[1-swap] = ent[1].item->sha1;
diff_tree_sha1(sha1[0], sha1[1], "", &revs->diffopt);
Expand All @@ -208,7 +208,7 @@ static int builtin_diff_tree(struct rev_info *revs,

static int builtin_diff_combined(struct rev_info *revs,
int argc, const char **argv,
struct object_list *ent,
struct object_array_entry *ent,
int ents)
{
const unsigned char (*parent)[20];
Expand Down Expand Up @@ -242,13 +242,14 @@ void add_head(struct rev_info *revs)
obj = parse_object(sha1);
if (!obj)
return;
add_object(obj, &revs->pending_objects, NULL, "HEAD");
add_pending_object(revs, obj, "HEAD");
}

int cmd_diff(int argc, const char **argv, char **envp)
{
int i;
struct rev_info rev;
struct object_list *list, ent[100];
struct object_array_entry ent[100];
int ents = 0, blobs = 0, paths = 0;
const char *path = NULL;
struct blobinfo blob[2];
Expand Down Expand Up @@ -281,7 +282,7 @@ int cmd_diff(int argc, const char **argv, char **envp)
/* Do we have --cached and not have a pending object, then
* default to HEAD by hand. Eek.
*/
if (!rev.pending_objects) {
if (!rev.pending.nr) {
int i;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
Expand All @@ -294,7 +295,8 @@ int cmd_diff(int argc, const char **argv, char **envp)
}
}

for (list = rev.pending_objects; list; list = list->next) {
for (i = 0; i < rev.pending.nr; i++) {
struct object_array_entry *list = rev.pending.objects+i;
struct object *obj = list->item;
const char *name = list->name;
int flags = (obj->flags & UNINTERESTING);
Expand Down
16 changes: 6 additions & 10 deletions builtin-grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ int cmd_grep(int argc, const char **argv, char **envp)
int cached = 0;
int seen_dashdash = 0;
struct grep_opt opt;
struct object_list *list, **tail, *object_list = NULL;
struct object_array list = { 0, 0, NULL };
const char *prefix = setup_git_directory();
const char **paths = NULL;
int i;
Expand All @@ -677,7 +677,6 @@ int cmd_grep(int argc, const char **argv, char **envp)
* that continues up to the -- (if exists), and then paths.
*/

tail = &object_list;
while (1 < argc) {
const char *arg = argv[1];
argc--; argv++;
Expand Down Expand Up @@ -851,12 +850,9 @@ int cmd_grep(int argc, const char **argv, char **envp)
/* Is it a rev? */
if (!get_sha1(arg, sha1)) {
struct object *object = parse_object(sha1);
struct object_list *elem;
if (!object)
die("bad object %s", arg);
elem = object_list_insert(object, tail);
elem->name = arg;
tail = &elem->next;
add_object_array(object, arg, &list);
continue;
}
if (!strcmp(arg, "--")) {
Expand All @@ -881,16 +877,16 @@ int cmd_grep(int argc, const char **argv, char **envp)
paths[1] = NULL;
}

if (!object_list)
if (!list.nr)
return !grep_cache(&opt, paths, cached);

if (cached)
die("both --cached and trees are given.");

for (list = object_list; list; list = list->next) {
for (i = 0; i < list.nr; i++) {
struct object *real_obj;
real_obj = deref_tag(list->item, NULL, 0);
if (grep_object(&opt, paths, real_obj, list->name))
real_obj = deref_tag(list.objects[i].item, NULL, 0);
if (grep_object(&opt, paths, real_obj, list.objects[i].name))
hit = 1;
}
return !hit;
Expand Down
4 changes: 2 additions & 2 deletions builtin-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ int cmd_format_patch(int argc, const char **argv, char **envp)
output_directory);
}

if (rev.pending_objects && rev.pending_objects->next == NULL) {
rev.pending_objects->item->flags |= UNINTERESTING;
if (rev.pending.nr == 1) {
rev.pending.objects[0].item->flags |= UNINTERESTING;
add_head(&rev);
}

Expand Down
Loading

0 comments on commit b19beec

Please sign in to comment.