Skip to content

Commit 042a4ed

Browse files
author
Linus Torvalds
committed
git-rev-parse: add "--not" flag to mark subsequent heads negative
If you have two lists of heads, and you want to see ones reachable from list $a but not from list $b, just do git-rev-list $(git-rev-parse $a --not $b) which is useful for both bisecting (where "b" would be the list of known good revisions, and "a" would be the latest found bad head) and for just seeing what the difference between two sets of heads are if you want to generate a pack-file for the difference.
1 parent 641e1ca commit 042a4ed

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

rev-parse.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ static int revs_only = 0;
1313
static int do_rev_argument = 1;
1414
static int output_revs = 0;
1515

16+
#define NORMAL 0
17+
#define REVERSED 1
18+
static int show_type = NORMAL;
19+
1620
static int get_extended_sha1(char *name, unsigned char *sha1);
1721

1822
/*
@@ -42,20 +46,12 @@ static int is_rev_argument(const char *arg)
4246
}
4347
}
4448

45-
static void show_rev(unsigned char *sha1)
49+
static void show_rev(int type, unsigned char *sha1)
4650
{
4751
if (no_revs)
4852
return;
4953
output_revs++;
50-
puts(sha1_to_hex(sha1));
51-
}
52-
53-
static void show_antirev(unsigned char *sha1)
54-
{
55-
if (no_revs)
56-
return;
57-
output_revs++;
58-
printf("^%s\n", sha1_to_hex(sha1));
54+
printf("%s%s\n", type == show_type ? "" : "^", sha1_to_hex(sha1));
5955
}
6056

6157
static void show_rev_arg(char *rev)
@@ -139,7 +135,7 @@ static void show_default(void)
139135

140136
def = NULL;
141137
if (!get_extended_sha1(s, sha1)) {
142-
show_rev(sha1);
138+
show_rev(NORMAL, sha1);
143139
return;
144140
}
145141
show_arg(s);
@@ -185,6 +181,10 @@ int main(int argc, char **argv)
185181
single_rev = 1;
186182
continue;
187183
}
184+
if (!strcmp(arg, "--not")) {
185+
show_type ^= REVERSED;
186+
continue;
187+
}
188188
show_arg(arg);
189189
continue;
190190
}
@@ -200,8 +200,8 @@ int main(int argc, char **argv)
200200
if (no_revs)
201201
continue;
202202
def = NULL;
203-
show_rev(end);
204-
show_antirev(sha1);
203+
show_rev(NORMAL, end);
204+
show_rev(REVERSED, sha1);
205205
continue;
206206
}
207207
}
@@ -211,14 +211,14 @@ int main(int argc, char **argv)
211211
if (no_revs)
212212
continue;
213213
def = NULL;
214-
show_rev(sha1);
214+
show_rev(NORMAL, sha1);
215215
continue;
216216
}
217217
if (*arg == '^' && !get_extended_sha1(arg+1, sha1)) {
218218
if (no_revs)
219219
continue;
220220
def = NULL;
221-
show_antirev(sha1);
221+
show_rev(REVERSED, sha1);
222222
continue;
223223
}
224224
show_default();

0 commit comments

Comments
 (0)