2006-08-03 17:24:35 +02:00
|
|
|
#include "builtin.h"
|
2005-10-26 15:10:20 +02:00
|
|
|
#include "cache.h"
|
|
|
|
#include "commit.h"
|
|
|
|
#include "tag.h"
|
|
|
|
#include "refs.h"
|
|
|
|
|
|
|
|
static const char name_rev_usage[] =
|
2007-02-17 19:22:35 +01:00
|
|
|
"git-name-rev [--tags | --refs=<pattern>] ( --all | --stdin | committish [committish...] )\n";
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
typedef struct rev_name {
|
|
|
|
const char *tip_name;
|
|
|
|
int merge_traversals;
|
|
|
|
int generation;
|
|
|
|
} rev_name;
|
|
|
|
|
|
|
|
static long cutoff = LONG_MAX;
|
|
|
|
|
|
|
|
static void name_rev(struct commit *commit,
|
|
|
|
const char *tip_name, int merge_traversals, int generation,
|
|
|
|
int deref)
|
|
|
|
{
|
2006-06-18 03:26:18 +02:00
|
|
|
struct rev_name *name = (struct rev_name *)commit->util;
|
2005-10-26 15:10:20 +02:00
|
|
|
struct commit_list *parents;
|
2005-11-29 05:51:44 +01:00
|
|
|
int parent_number = 1;
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
if (!commit->object.parsed)
|
|
|
|
parse_commit(commit);
|
|
|
|
|
|
|
|
if (commit->date < cutoff)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (deref) {
|
|
|
|
char *new_name = xmalloc(strlen(tip_name)+3);
|
|
|
|
strcpy(new_name, tip_name);
|
|
|
|
strcat(new_name, "^0");
|
|
|
|
tip_name = new_name;
|
|
|
|
|
|
|
|
if (generation)
|
|
|
|
die("generation: %d, but deref?", generation);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name == NULL) {
|
|
|
|
name = xmalloc(sizeof(rev_name));
|
2006-06-18 03:26:18 +02:00
|
|
|
commit->util = name;
|
2005-10-26 15:10:20 +02:00
|
|
|
goto copy_data;
|
|
|
|
} else if (name->merge_traversals > merge_traversals ||
|
|
|
|
(name->merge_traversals == merge_traversals &&
|
|
|
|
name->generation > generation)) {
|
|
|
|
copy_data:
|
|
|
|
name->tip_name = tip_name;
|
|
|
|
name->merge_traversals = merge_traversals;
|
|
|
|
name->generation = generation;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (parents = commit->parents;
|
|
|
|
parents;
|
|
|
|
parents = parents->next, parent_number++) {
|
2005-11-29 05:51:44 +01:00
|
|
|
if (parent_number > 1) {
|
2007-02-20 01:08:48 +01:00
|
|
|
int len = strlen(tip_name);
|
2007-05-15 18:33:25 +02:00
|
|
|
char *new_name = xmalloc(len +
|
|
|
|
1 + decimal_length(generation) + /* ~<n> */
|
|
|
|
1 + 2 + /* ^NN */
|
|
|
|
1);
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2007-02-20 01:08:48 +01:00
|
|
|
if (len > 2 && !strcmp(tip_name + len - 2, "^0"))
|
|
|
|
len -= 2;
|
2005-10-26 15:10:20 +02:00
|
|
|
if (generation > 0)
|
2007-02-20 01:08:48 +01:00
|
|
|
sprintf(new_name, "%.*s~%d^%d", len, tip_name,
|
2005-10-26 15:10:20 +02:00
|
|
|
generation, parent_number);
|
|
|
|
else
|
2007-02-20 01:08:48 +01:00
|
|
|
sprintf(new_name, "%.*s^%d", len, tip_name,
|
|
|
|
parent_number);
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
name_rev(parents->item, new_name,
|
|
|
|
merge_traversals + 1 , 0, 0);
|
|
|
|
} else {
|
|
|
|
name_rev(parents->item, tip_name, merge_traversals,
|
|
|
|
generation + 1, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-02-17 19:22:35 +01:00
|
|
|
struct name_ref_data {
|
|
|
|
int tags_only;
|
2007-05-21 09:20:25 +02:00
|
|
|
int name_only;
|
2007-02-17 19:22:35 +01:00
|
|
|
const char *ref_filter;
|
|
|
|
};
|
|
|
|
|
2006-09-21 07:02:01 +02:00
|
|
|
static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)
|
2005-10-26 15:10:20 +02:00
|
|
|
{
|
|
|
|
struct object *o = parse_object(sha1);
|
2007-02-17 19:22:35 +01:00
|
|
|
struct name_ref_data *data = cb_data;
|
2005-10-26 15:10:20 +02:00
|
|
|
int deref = 0;
|
|
|
|
|
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when
the parameters match specific patterns, so that they can be verified
easily. Leftover from this will be fixed in a separate step, including
idiotic conversions like
if (!strncmp("foo", arg, 3))
=>
if (!(-prefixcmp(arg, "foo")))
This was done by using this script in px.perl
#!/usr/bin/perl -i.bak -p
if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
}
if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
}
and running:
$ git grep -l strncmp -- '*.c' | xargs perl px.perl
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20 10:53:29 +01:00
|
|
|
if (data->tags_only && prefixcmp(path, "refs/tags/"))
|
2007-02-17 19:22:35 +01:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (data->ref_filter && fnmatch(data->ref_filter, path, 0))
|
2005-10-26 15:10:20 +02:00
|
|
|
return 0;
|
|
|
|
|
2006-07-12 05:45:31 +02:00
|
|
|
while (o && o->type == OBJ_TAG) {
|
2005-10-26 15:10:20 +02:00
|
|
|
struct tag *t = (struct tag *) o;
|
|
|
|
if (!t->tagged)
|
|
|
|
break; /* broken repository */
|
|
|
|
o = parse_object(t->tagged->sha1);
|
|
|
|
deref = 1;
|
|
|
|
}
|
2006-07-12 05:45:31 +02:00
|
|
|
if (o && o->type == OBJ_COMMIT) {
|
2005-10-26 15:10:20 +02:00
|
|
|
struct commit *commit = (struct commit *)o;
|
|
|
|
|
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when
the parameters match specific patterns, so that they can be verified
easily. Leftover from this will be fixed in a separate step, including
idiotic conversions like
if (!strncmp("foo", arg, 3))
=>
if (!(-prefixcmp(arg, "foo")))
This was done by using this script in px.perl
#!/usr/bin/perl -i.bak -p
if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
}
if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
}
and running:
$ git grep -l strncmp -- '*.c' | xargs perl px.perl
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20 10:53:29 +01:00
|
|
|
if (!prefixcmp(path, "refs/heads/"))
|
2006-01-11 23:20:09 +01:00
|
|
|
path = path + 11;
|
2007-05-21 09:20:25 +02:00
|
|
|
else if (data->tags_only
|
|
|
|
&& data->name_only
|
|
|
|
&& !prefixcmp(path, "refs/tags/"))
|
|
|
|
path = path + 10;
|
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when
the parameters match specific patterns, so that they can be verified
easily. Leftover from this will be fixed in a separate step, including
idiotic conversions like
if (!strncmp("foo", arg, 3))
=>
if (!(-prefixcmp(arg, "foo")))
This was done by using this script in px.perl
#!/usr/bin/perl -i.bak -p
if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
}
if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
}
and running:
$ git grep -l strncmp -- '*.c' | xargs perl px.perl
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20 10:53:29 +01:00
|
|
|
else if (!prefixcmp(path, "refs/"))
|
2006-01-11 23:20:09 +01:00
|
|
|
path = path + 5;
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2006-09-02 06:16:31 +02:00
|
|
|
name_rev(commit, xstrdup(path), 0, 0, deref);
|
2005-10-26 15:10:20 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* returns a static buffer */
|
|
|
|
static const char* get_rev_name(struct object *o)
|
|
|
|
{
|
|
|
|
static char buffer[1024];
|
2006-06-18 03:26:18 +02:00
|
|
|
struct rev_name *n;
|
|
|
|
struct commit *c;
|
|
|
|
|
2006-07-12 05:45:31 +02:00
|
|
|
if (o->type != OBJ_COMMIT)
|
2006-06-18 03:26:18 +02:00
|
|
|
return "undefined";
|
|
|
|
c = (struct commit *) o;
|
|
|
|
n = c->util;
|
2005-10-26 15:10:20 +02:00
|
|
|
if (!n)
|
|
|
|
return "undefined";
|
|
|
|
|
|
|
|
if (!n->generation)
|
|
|
|
return n->tip_name;
|
2007-02-20 01:08:48 +01:00
|
|
|
else {
|
|
|
|
int len = strlen(n->tip_name);
|
|
|
|
if (len > 2 && !strcmp(n->tip_name + len - 2, "^0"))
|
|
|
|
len -= 2;
|
|
|
|
snprintf(buffer, sizeof(buffer), "%.*s~%d", len, n->tip_name,
|
|
|
|
n->generation);
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|
2005-10-26 15:10:20 +02:00
|
|
|
}
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 02:42:35 +02:00
|
|
|
|
2006-08-03 17:24:35 +02:00
|
|
|
int cmd_name_rev(int argc, const char **argv, const char *prefix)
|
2005-10-26 15:10:20 +02:00
|
|
|
{
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 02:42:35 +02:00
|
|
|
struct object_array revs = { 0, 0, NULL };
|
2005-10-26 15:10:20 +02:00
|
|
|
int as_is = 0, all = 0, transform_stdin = 0;
|
2007-05-21 09:20:25 +02:00
|
|
|
struct name_ref_data data = { 0, 0, NULL };
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2006-03-24 08:41:18 +01:00
|
|
|
git_config(git_default_config);
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
usage(name_rev_usage);
|
|
|
|
|
|
|
|
for (--argc, ++argv; argc; --argc, ++argv) {
|
|
|
|
unsigned char sha1[20];
|
|
|
|
struct object *o;
|
|
|
|
struct commit *commit;
|
|
|
|
|
|
|
|
if (!as_is && (*argv)[0] == '-') {
|
|
|
|
if (!strcmp(*argv, "--")) {
|
|
|
|
as_is = 1;
|
|
|
|
continue;
|
2007-05-21 09:20:25 +02:00
|
|
|
} else if (!strcmp(*argv, "--name-only")) {
|
|
|
|
data.name_only = 1;
|
|
|
|
continue;
|
2005-10-26 15:10:20 +02:00
|
|
|
} else if (!strcmp(*argv, "--tags")) {
|
2007-02-17 19:22:35 +01:00
|
|
|
data.tags_only = 1;
|
|
|
|
continue;
|
Mechanical conversion to use prefixcmp()
This mechanically converts strncmp() to use prefixcmp(), but only when
the parameters match specific patterns, so that they can be verified
easily. Leftover from this will be fixed in a separate step, including
idiotic conversions like
if (!strncmp("foo", arg, 3))
=>
if (!(-prefixcmp(arg, "foo")))
This was done by using this script in px.perl
#!/usr/bin/perl -i.bak -p
if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) {
s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|;
}
if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) {
s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|;
}
and running:
$ git grep -l strncmp -- '*.c' | xargs perl px.perl
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-20 10:53:29 +01:00
|
|
|
} else if (!prefixcmp(*argv, "--refs=")) {
|
2007-02-17 19:22:35 +01:00
|
|
|
data.ref_filter = *argv + 7;
|
2005-10-26 15:10:20 +02:00
|
|
|
continue;
|
|
|
|
} else if (!strcmp(*argv, "--all")) {
|
|
|
|
if (argc > 1)
|
|
|
|
die("Specify either a list, or --all, not both!");
|
|
|
|
all = 1;
|
|
|
|
cutoff = 0;
|
|
|
|
continue;
|
|
|
|
} else if (!strcmp(*argv, "--stdin")) {
|
|
|
|
if (argc > 1)
|
|
|
|
die("Specify either a list, or --stdin, not both!");
|
|
|
|
transform_stdin = 1;
|
|
|
|
cutoff = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
usage(name_rev_usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_sha1(*argv, sha1)) {
|
|
|
|
fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
|
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-11-03 00:19:13 +01:00
|
|
|
o = deref_tag(parse_object(sha1), *argv, 0);
|
2006-07-12 05:45:31 +02:00
|
|
|
if (!o || o->type != OBJ_COMMIT) {
|
2005-10-26 15:10:20 +02:00
|
|
|
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
|
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
commit = (struct commit *)o;
|
|
|
|
|
|
|
|
if (cutoff > commit->date)
|
|
|
|
cutoff = commit->date;
|
|
|
|
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 02:42:35 +02:00
|
|
|
add_object_array((struct object *)commit, *argv, &revs);
|
2005-10-26 15:10:20 +02:00
|
|
|
}
|
|
|
|
|
2007-02-17 19:22:35 +01:00
|
|
|
for_each_ref(name_ref, &data);
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
if (transform_stdin) {
|
|
|
|
char buffer[2048];
|
|
|
|
char *p, *p_start;
|
|
|
|
|
|
|
|
while (!feof(stdin)) {
|
|
|
|
int forty = 0;
|
|
|
|
p = fgets(buffer, sizeof(buffer), stdin);
|
|
|
|
if (!p)
|
|
|
|
break;
|
|
|
|
|
|
|
|
for (p_start = p; *p; p++) {
|
|
|
|
#define ishex(x) (isdigit((x)) || ((x) >= 'a' && (x) <= 'f'))
|
|
|
|
if (!ishex(*p))
|
|
|
|
forty = 0;
|
|
|
|
else if (++forty == 40 &&
|
|
|
|
!ishex(*(p+1))) {
|
|
|
|
unsigned char sha1[40];
|
|
|
|
const char *name = "undefined";
|
|
|
|
char c = *(p+1);
|
|
|
|
|
|
|
|
forty = 0;
|
|
|
|
|
|
|
|
*(p+1) = 0;
|
|
|
|
if (!get_sha1(p - 39, sha1)) {
|
|
|
|
struct object *o =
|
|
|
|
lookup_object(sha1);
|
|
|
|
if (o)
|
|
|
|
name = get_rev_name(o);
|
|
|
|
}
|
|
|
|
*(p+1) = c;
|
|
|
|
|
|
|
|
if (!strcmp(name, "undefined"))
|
|
|
|
continue;
|
|
|
|
|
2005-11-26 08:36:58 +01:00
|
|
|
fwrite(p_start, p - p_start + 1, 1,
|
|
|
|
stdout);
|
|
|
|
printf(" (%s)", name);
|
2005-10-26 15:10:20 +02:00
|
|
|
p_start = p + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* flush */
|
|
|
|
if (p_start != p)
|
|
|
|
fwrite(p_start, p - p_start, 1, stdout);
|
|
|
|
}
|
|
|
|
} else if (all) {
|
2006-06-30 06:38:55 +02:00
|
|
|
int i, max;
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2006-06-30 06:38:55 +02:00
|
|
|
max = get_max_object_index();
|
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
struct object * obj = get_indexed_object(i);
|
|
|
|
if (!obj)
|
|
|
|
continue;
|
2007-05-21 09:20:25 +02:00
|
|
|
if (!data.name_only)
|
|
|
|
printf("%s ", sha1_to_hex(obj->sha1));
|
|
|
|
printf("%s\n", get_rev_name(obj));
|
2006-06-30 06:38:55 +02:00
|
|
|
}
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 02:42:35 +02:00
|
|
|
} else {
|
|
|
|
int i;
|
2007-05-21 09:20:25 +02:00
|
|
|
for (i = 0; i < revs.nr; i++) {
|
|
|
|
if (!data.name_only)
|
|
|
|
printf("%s ", revs.objects[i].name);
|
|
|
|
printf("%s\n", get_rev_name(revs.objects[i].item));
|
|
|
|
}
|
Add "named object array" concept
We've had this notion of a "object_list" for a long time, which eventually
grew a "name" member because some users (notably git-rev-list) wanted to
name each object as it is generated.
That object_list is great for some things, but it isn't all that wonderful
for others, and the "name" member is generally not used by everybody.
This patch splits the users of the object_list array up into two: the
traditional list users, who want the list-like format, and who don't
actually use or want the name. And another class of users that really used
the list as an extensible array, and generally wanted to name the objects.
The patch is fairly straightforward, but it's also biggish. Most of it
really just cleans things up: switching the revision parsing and listing
over to the array makes things like the builtin-diff usage much simpler
(we now see exactly how many members the array has, and we don't get the
objects reversed from the order they were on the command line).
One of the main reasons for doing this at all is that the malloc overhead
of the simple object list was actually pretty high, and the array is just
a lot denser. So this patch brings down memory usage by git-rev-list by
just under 3% (on top of all the other memory use optimizations) on the
mozilla archive.
It does add more lines than it removes, and more importantly, it adds a
whole new infrastructure for maintaining lists of objects, but on the
other hand, the new dynamic array code is pretty obvious. The change to
builtin-diff-tree.c shows a fairly good example of why an array interface
is sometimes more natural, and just much simpler for everybody.
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2006-06-20 02:42:35 +02:00
|
|
|
}
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|