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"
|
2007-10-15 22:57:59 +02:00
|
|
|
#include "parse-options.h"
|
2013-07-07 23:14:22 +02:00
|
|
|
#include "sha1-lookup.h"
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2007-05-24 21:20:42 +02:00
|
|
|
#define CUTOFF_DATE_SLOP 86400 /* one day */
|
|
|
|
|
2005-10-26 15:10:20 +02:00
|
|
|
typedef struct rev_name {
|
|
|
|
const char *tip_name;
|
|
|
|
int generation;
|
2007-08-27 13:37:33 +02:00
|
|
|
int distance;
|
2005-10-26 15:10:20 +02:00
|
|
|
} rev_name;
|
|
|
|
|
|
|
|
static long cutoff = LONG_MAX;
|
|
|
|
|
2007-08-27 13:37:33 +02:00
|
|
|
/* How many generations are maximally preferred over _one_ merge traversal? */
|
|
|
|
#define MERGE_TRAVERSAL_WEIGHT 65535
|
|
|
|
|
2005-10-26 15:10:20 +02:00
|
|
|
static void name_rev(struct commit *commit,
|
2007-08-27 13:37:33 +02:00
|
|
|
const char *tip_name, int generation, int distance,
|
2005-10-26 15:10:20 +02:00
|
|
|
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
|
|
|
|
2013-10-24 10:53:01 +02:00
|
|
|
parse_commit(commit);
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
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;
|
2007-08-27 13:37:33 +02:00
|
|
|
} else if (name->distance > distance) {
|
2005-10-26 15:10:20 +02:00
|
|
|
copy_data:
|
|
|
|
name->tip_name = tip_name;
|
|
|
|
name->generation = generation;
|
2007-08-27 13:37:33 +02:00
|
|
|
name->distance = distance;
|
2005-10-26 15:10:20 +02:00
|
|
|
} 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
|
|
|
|
2007-08-27 13:37:33 +02:00
|
|
|
name_rev(parents->item, new_name, 0,
|
|
|
|
distance + MERGE_TRAVERSAL_WEIGHT, 0);
|
2005-10-26 15:10:20 +02:00
|
|
|
} else {
|
2007-08-27 13:37:33 +02:00
|
|
|
name_rev(parents->item, tip_name, generation + 1,
|
|
|
|
distance + 1, 0);
|
2005-10-26 15:10:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-18 14:35:31 +02:00
|
|
|
static int subpath_matches(const char *path, const char *filter)
|
|
|
|
{
|
|
|
|
const char *subpath = path;
|
|
|
|
|
|
|
|
while (subpath) {
|
|
|
|
if (!fnmatch(filter, subpath, 0))
|
|
|
|
return subpath - path;
|
|
|
|
subpath = strchr(subpath, '/');
|
|
|
|
if (subpath)
|
|
|
|
subpath++;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-07-07 23:13:41 +02:00
|
|
|
static const char *name_ref_abbrev(const char *refname, int shorten_unambiguous)
|
|
|
|
{
|
|
|
|
if (shorten_unambiguous)
|
|
|
|
refname = shorten_unambiguous_ref(refname, 0);
|
|
|
|
else if (!prefixcmp(refname, "refs/heads/"))
|
|
|
|
refname = refname + 11;
|
|
|
|
else if (!prefixcmp(refname, "refs/"))
|
|
|
|
refname = refname + 5;
|
|
|
|
return refname;
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2013-07-07 23:14:22 +02:00
|
|
|
static struct tip_table {
|
|
|
|
struct tip_table_entry {
|
|
|
|
unsigned char sha1[20];
|
|
|
|
const char *refname;
|
|
|
|
} *table;
|
|
|
|
int nr;
|
|
|
|
int alloc;
|
|
|
|
int sorted;
|
|
|
|
} tip_table;
|
|
|
|
|
|
|
|
static void add_to_tip_table(const unsigned char *sha1, const char *refname,
|
|
|
|
int shorten_unambiguous)
|
|
|
|
{
|
|
|
|
refname = name_ref_abbrev(refname, shorten_unambiguous);
|
|
|
|
|
|
|
|
ALLOC_GROW(tip_table.table, tip_table.nr + 1, tip_table.alloc);
|
|
|
|
hashcpy(tip_table.table[tip_table.nr].sha1, sha1);
|
|
|
|
tip_table.table[tip_table.nr].refname = xstrdup(refname);
|
|
|
|
tip_table.nr++;
|
|
|
|
tip_table.sorted = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int tipcmp(const void *a_, const void *b_)
|
|
|
|
{
|
|
|
|
const struct tip_table_entry *a = a_, *b = b_;
|
|
|
|
return hashcmp(a->sha1, b->sha1);
|
|
|
|
}
|
|
|
|
|
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;
|
2013-06-18 14:35:31 +02:00
|
|
|
int can_abbreviate_output = data->tags_only && data->name_only;
|
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;
|
|
|
|
|
2013-06-18 14:35:31 +02:00
|
|
|
if (data->ref_filter) {
|
|
|
|
switch (subpath_matches(path, data->ref_filter)) {
|
|
|
|
case -1: /* did not match */
|
|
|
|
return 0;
|
|
|
|
case 0: /* matched fully */
|
|
|
|
break;
|
|
|
|
default: /* matched subpath */
|
|
|
|
can_abbreviate_output = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2013-07-07 23:14:22 +02:00
|
|
|
add_to_tip_table(sha1, path, can_abbreviate_output);
|
|
|
|
|
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;
|
|
|
|
|
2013-07-07 23:13:41 +02:00
|
|
|
path = name_ref_abbrev(path, can_abbreviate_output);
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-07 23:14:22 +02:00
|
|
|
static const unsigned char *nth_tip_table_ent(size_t ix, void *table_)
|
|
|
|
{
|
|
|
|
struct tip_table_entry *table = table_;
|
|
|
|
return table[ix].sha1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char *get_exact_ref_match(const struct object *o)
|
|
|
|
{
|
|
|
|
int found;
|
|
|
|
|
|
|
|
if (!tip_table.table || !tip_table.nr)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (!tip_table.sorted) {
|
|
|
|
qsort(tip_table.table, tip_table.nr, sizeof(*tip_table.table),
|
|
|
|
tipcmp);
|
|
|
|
tip_table.sorted = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
found = sha1_pos(o->sha1, tip_table.table, tip_table.nr,
|
|
|
|
nth_tip_table_ent);
|
|
|
|
if (0 <= found)
|
|
|
|
return tip_table.table[found].refname;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-10-26 15:10:20 +02:00
|
|
|
/* returns a static buffer */
|
2008-03-02 17:51:57 +01:00
|
|
|
static const char *get_rev_name(const struct object *o)
|
2005-10-26 15:10:20 +02:00
|
|
|
{
|
|
|
|
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)
|
2013-07-07 23:14:22 +02:00
|
|
|
return get_exact_ref_match(o);
|
2006-06-18 03:26:18 +02:00
|
|
|
c = (struct commit *) o;
|
|
|
|
n = c->util;
|
2005-10-26 15:10:20 +02:00
|
|
|
if (!n)
|
2007-12-24 12:18:22 +01:00
|
|
|
return NULL;
|
2005-10-26 15:10:20 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
2008-03-02 17:51:57 +01:00
|
|
|
static void show_name(const struct object *obj,
|
|
|
|
const char *caller_name,
|
|
|
|
int always, int allow_undefined, int name_only)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
const unsigned char *sha1 = obj->sha1;
|
|
|
|
|
|
|
|
if (!name_only)
|
|
|
|
printf("%s ", caller_name ? caller_name : sha1_to_hex(sha1));
|
|
|
|
name = get_rev_name(obj);
|
|
|
|
if (name)
|
|
|
|
printf("%s\n", name);
|
|
|
|
else if (allow_undefined)
|
|
|
|
printf("undefined\n");
|
|
|
|
else if (always)
|
|
|
|
printf("%s\n", find_unique_abbrev(sha1, DEFAULT_ABBREV));
|
|
|
|
else
|
|
|
|
die("cannot describe '%s'", sha1_to_hex(sha1));
|
|
|
|
}
|
|
|
|
|
2007-10-15 22:57:59 +02:00
|
|
|
static char const * const name_rev_usage[] = {
|
2012-08-20 14:32:27 +02:00
|
|
|
N_("git name-rev [options] <commit>..."),
|
|
|
|
N_("git name-rev [options] --all"),
|
|
|
|
N_("git name-rev [options] --stdin"),
|
2007-10-15 22:57:59 +02:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2008-08-02 20:04:22 +02:00
|
|
|
static void name_rev_line(char *p, struct name_ref_data *data)
|
|
|
|
{
|
|
|
|
int forty = 0;
|
|
|
|
char *p_start;
|
|
|
|
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 = NULL;
|
|
|
|
char c = *(p+1);
|
2008-08-03 15:44:33 +02:00
|
|
|
int p_len = p - p_start + 1;
|
2008-08-02 20:04:22 +02:00
|
|
|
|
|
|
|
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 (!name)
|
|
|
|
continue;
|
|
|
|
|
2008-08-03 15:44:33 +02:00
|
|
|
if (data->name_only)
|
|
|
|
printf("%.*s%s", p_len - 40, p_start, name);
|
|
|
|
else
|
|
|
|
printf("%.*s (%s)", p_len, p_start, name);
|
2008-08-02 20:04:22 +02:00
|
|
|
p_start = p + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* flush */
|
|
|
|
if (p_start != p)
|
|
|
|
fwrite(p_start, p - p_start, 1, stdout);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2010-08-29 04:04:17 +02:00
|
|
|
struct object_array revs = OBJECT_ARRAY_INIT;
|
2013-07-18 23:46:51 +02:00
|
|
|
int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
|
2007-05-21 09:20:25 +02:00
|
|
|
struct name_ref_data data = { 0, 0, NULL };
|
2007-10-15 22:57:59 +02:00
|
|
|
struct option opts[] = {
|
2012-08-20 14:32:27 +02:00
|
|
|
OPT_BOOLEAN(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
|
|
|
|
OPT_BOOLEAN(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
|
|
|
|
OPT_STRING(0, "refs", &data.ref_filter, N_("pattern"),
|
|
|
|
N_("only use refs matching <pattern>")),
|
2007-10-15 22:57:59 +02:00
|
|
|
OPT_GROUP(""),
|
2012-08-20 14:32:27 +02:00
|
|
|
OPT_BOOLEAN(0, "all", &all, N_("list all commits reachable from all refs")),
|
|
|
|
OPT_BOOLEAN(0, "stdin", &transform_stdin, N_("read from stdin")),
|
|
|
|
OPT_BOOLEAN(0, "undefined", &allow_undefined, N_("allow to print `undefined` names")),
|
2008-03-02 17:51:57 +01:00
|
|
|
OPT_BOOLEAN(0, "always", &always,
|
2012-08-20 14:32:27 +02:00
|
|
|
N_("show abbreviated commit object as fallback")),
|
2013-07-18 23:46:51 +02:00
|
|
|
{
|
|
|
|
/* A Hidden OPT_BOOL */
|
|
|
|
OPTION_SET_INT, 0, "peel-tag", &peel_tag, NULL,
|
|
|
|
N_("dereference tags in the input (internal use)"),
|
|
|
|
PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1,
|
|
|
|
},
|
2007-10-15 22:57:59 +02:00
|
|
|
OPT_END(),
|
|
|
|
};
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2008-05-14 19:46:53 +02:00
|
|
|
git_config(git_default_config, NULL);
|
2009-05-23 20:53:12 +02:00
|
|
|
argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
|
2007-10-15 22:57:59 +02:00
|
|
|
if (!!all + !!transform_stdin + !!argc > 1) {
|
|
|
|
error("Specify either a list, or --all, not both!");
|
|
|
|
usage_with_options(name_rev_usage, opts);
|
|
|
|
}
|
|
|
|
if (all || transform_stdin)
|
|
|
|
cutoff = 0;
|
2005-10-26 15:10:20 +02:00
|
|
|
|
2007-10-15 22:57:59 +02:00
|
|
|
for (; argc; argc--, argv++) {
|
2005-10-26 15:10:20 +02:00
|
|
|
unsigned char sha1[20];
|
2013-07-18 23:11:35 +02:00
|
|
|
struct object *object;
|
2005-10-26 15:10:20 +02:00
|
|
|
struct commit *commit;
|
|
|
|
|
|
|
|
if (get_sha1(*argv, sha1)) {
|
|
|
|
fprintf(stderr, "Could not get sha1 for %s. Skipping.\n",
|
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-07-18 23:11:35 +02:00
|
|
|
commit = NULL;
|
|
|
|
object = parse_object(sha1);
|
|
|
|
if (object) {
|
|
|
|
struct object *peeled = deref_tag(object, *argv, 0);
|
|
|
|
if (peeled && peeled->type == OBJ_COMMIT)
|
|
|
|
commit = (struct commit *)peeled;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!object) {
|
|
|
|
fprintf(stderr, "Could not get object for %s. Skipping.\n",
|
2005-10-26 15:10:20 +02:00
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-07-18 23:11:35 +02:00
|
|
|
if (commit) {
|
|
|
|
if (cutoff > commit->date)
|
|
|
|
cutoff = commit->date;
|
|
|
|
}
|
2013-07-18 23:46:51 +02:00
|
|
|
|
|
|
|
if (peel_tag) {
|
|
|
|
if (!commit) {
|
|
|
|
fprintf(stderr, "Could not get commit for %s. Skipping.\n",
|
|
|
|
*argv);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
object = (struct object *)commit;
|
|
|
|
}
|
2013-07-18 23:11:35 +02:00
|
|
|
add_object_array(object, *argv, &revs);
|
2005-10-26 15:10:20 +02:00
|
|
|
}
|
|
|
|
|
2007-05-24 21:20:42 +02:00
|
|
|
if (cutoff)
|
|
|
|
cutoff = cutoff - CUTOFF_DATE_SLOP;
|
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];
|
|
|
|
|
|
|
|
while (!feof(stdin)) {
|
2008-08-02 20:04:22 +02:00
|
|
|
char *p = fgets(buffer, sizeof(buffer), stdin);
|
2005-10-26 15:10:20 +02:00
|
|
|
if (!p)
|
|
|
|
break;
|
2008-08-02 20:04:22 +02:00
|
|
|
name_rev_line(p, &data);
|
2005-10-26 15:10:20 +02:00
|
|
|
}
|
|
|
|
} 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();
|
2008-06-06 01:31:55 +02:00
|
|
|
for (i = 0; i < max; i++) {
|
|
|
|
struct object *obj = get_indexed_object(i);
|
2011-11-16 00:51:05 +01:00
|
|
|
if (!obj || obj->type != OBJ_COMMIT)
|
2008-06-06 01:31:55 +02:00
|
|
|
continue;
|
|
|
|
show_name(obj, NULL,
|
2008-03-02 17:51:57 +01:00
|
|
|
always, allow_undefined, data.name_only);
|
2008-06-06 01:31: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;
|
2008-03-02 17:51:57 +01:00
|
|
|
for (i = 0; i < revs.nr; i++)
|
|
|
|
show_name(revs.objects[i].item, revs.objects[i].name,
|
|
|
|
always, allow_undefined, data.name_only);
|
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;
|
|
|
|
}
|