@matheusbsbs / matheus-bagliano / commits / 9c5e66e97d
Fork 0

Teach revision machinery about --reverse

The option --reverse reverses the order of the commits. [jc: with comments on rev_info.reverse from Simon 'corecode' Schubert.] Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Jan 20, 2007 at 23:04 UTC 9c5e66e97da8cadcc45a278c4e39a7d25674d4ff
3 files changed +45 -1
Documentation/git-rev-list.txt
+5
@@ -27,6 +27,7 @@ SYNOPSIS
27 [ \--pretty | \--header ]
28 [ \--bisect ]
29 [ \--merge ]
30 + [ \--reverse ]
31 [ \--walk-reflogs ]
32 <commit>... [ \-- <paths>... ]
33
@@ -266,6 +267,10 @@ By default, the commits are shown in reverse chronological order.
267 parent comes before all of its children, but otherwise things
268 are still ordered in the commit timestamp order.
269
270 +--reverse::
271 +
272 + Output the commits in reverse order.
273 +
274 Object Traversal
275 ~~~~~~~~~~~~~~~~
276
revision.c
+38
@@ -1057,6 +1057,10 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1057 git_log_output_encoding = "";
1058 continue;
1059 }
1060 + if (!strcmp(arg, "--reverse")) {
1061 + revs->reverse ^= 1;
1062 + continue;
1063 + }
1064
1065 opts = diff_opt_parse(&revs->diffopt, argv+i, argc-i);
1066 if (opts > 0) {
@@ -1285,6 +1289,40 @@ struct commit *get_revision(struct rev_info *revs)
1289 {
1290 struct commit *c = NULL;
1291
1292 + if (revs->reverse) {
1293 + struct commit_list *list;
1294 +
1295 + /*
1296 + * rev_info.reverse is used to note the fact that we
1297 + * want to output the list of revisions in reverse
1298 + * order. To accomplish this goal, reverse can have
1299 + * different values:
1300 + *
1301 + * 0 do nothing
1302 + * 1 reverse the list
1303 + * 2 internal use: we have already obtained and
1304 + * reversed the list, now we only need to yield
1305 + * its items.
1306 + */
1307 +
1308 + if (revs->reverse == 1) {
1309 + revs->reverse = 0;
1310 + list = NULL;
1311 + while ((c = get_revision(revs)))
1312 + commit_list_insert(c, &list);
1313 + revs->commits = list;
1314 + revs->reverse = 2;
1315 + }
1316 +
1317 + if (!revs->commits)
1318 + return NULL;
1319 + c = revs->commits->item;
1320 + list = revs->commits->next;
1321 + free(revs->commits);
1322 + revs->commits = list;
1323 + return c;
1324 + }
1325 +
1326 if (0 < revs->skip_count) {
1327 while ((c = get_revision_1(revs)) != NULL) {
1328 if (revs->skip_count-- <= 0)
revision.h
+2 -1
@@ -42,7 +42,8 @@ struct rev_info {
42 unpacked:1, /* see also ignore_packed below */
43 boundary:1,
44 left_right:1,
45 - parents:1;
45 + parents:1,
46 + reverse:2;
47
48 /* Diff flags */
49 unsigned int diff:1,