Skip to content

Commit 337cb3f

Browse files
author
Linus Torvalds
committed
git-rev-list: allow arbitrary head selections, use git-rev-tree syntax
This makes git-rev-list use the same command line syntax to mark the commits as git-rev-tree does, and instead of just allowing a start and end commit, it allows an arbitrary list of "interesting" and "uninteresting" commits. For example, imagine that you had three branches (a, b and c) that you are interested in, but you don't want to see stuff that already exists in another persons three releases (x, y and z). You can do git-rev-list a b c ^x ^y ^z (order doesn't matter, btw - feel free to put the uninteresting ones first or otherwise swithc them around), and it will show all the commits that are reachable from a/b/c but not reachable from x/y/z. The old syntax "git-rev-list start end" would not be written as "git-rev-list start ^end", or "git-rev-list ^end start". There's no limit to the number of heads you can specify (unlike git-rev-tree, which can handle a maximum of 16 heads).
1 parent dba385b commit 337cb3f

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

rev-list.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ static int everybody_uninteresting(struct commit_list *list)
8484
return 1;
8585
}
8686

87-
struct commit_list *limit_list(struct commit_list *list, struct commit *end)
87+
struct commit_list *limit_list(struct commit_list *list)
8888
{
8989
struct commit_list *newlist = NULL;
9090
struct commit_list **p = &newlist;
9191
do {
9292
struct commit *commit = pop_most_recent_commit(&list, SEEN);
9393
struct object *obj = &commit->object;
9494

95-
if (commit == end || (obj->flags & UNINTERESTING)) {
95+
if (obj->flags & UNINTERESTING) {
9696
mark_parents_uninteresting(commit);
9797
if (everybody_uninteresting(list))
9898
break;
@@ -105,15 +105,14 @@ struct commit_list *limit_list(struct commit_list *list, struct commit *end)
105105

106106
int main(int argc, char **argv)
107107
{
108-
int nr_sha;
109-
unsigned char sha1[2][20];
110108
struct commit_list *list = NULL;
111-
struct commit *commit, *end;
112-
int i;
109+
int i, limited = 0;
113110

114-
nr_sha = 0;
115111
for (i = 1 ; i < argc; i++) {
112+
int flags;
116113
char *arg = argv[i];
114+
unsigned char sha1[20];
115+
struct commit *commit;
117116

118117
if (!strncmp(arg, "--max-count=", 12)) {
119118
max_count = atoi(arg + 12);
@@ -143,28 +142,26 @@ int main(int argc, char **argv)
143142
continue;
144143
}
145144

146-
if (nr_sha > 2 || get_sha1(arg, sha1[nr_sha]))
145+
flags = 0;
146+
if (*arg == '^') {
147+
flags = UNINTERESTING;
148+
arg++;
149+
limited = 1;
150+
}
151+
if (get_sha1(arg, sha1))
147152
usage(rev_list_usage);
148-
nr_sha++;
153+
commit = lookup_commit_reference(sha1);
154+
if (!commit || parse_commit(commit) < 0)
155+
die("bad commit object %s", arg);
156+
commit->object.flags |= flags;
157+
commit_list_insert(commit, &list);
149158
}
150159

151-
if (!nr_sha)
160+
if (!list)
152161
usage(rev_list_usage);
153162

154-
commit = lookup_commit_reference(sha1[0]);
155-
if (!commit || parse_commit(commit) < 0)
156-
die("bad starting commit object");
157-
158-
end = NULL;
159-
if (nr_sha > 1) {
160-
end = lookup_commit_reference(sha1[1]);
161-
if (!end || parse_commit(end) < 0)
162-
die("bad ending commit object");
163-
}
164-
165-
commit_list_insert(commit, &list);
166-
if (end)
167-
list = limit_list(list, end);
163+
if (limited)
164+
list = limit_list(list);
168165

169166
show_commit_list(list);
170167
return 0;

0 commit comments

Comments
 (0)