Now git-topic is a bit more usable and close enough to TO script.
Junio C Hamano committed
Dec 8, 2006 at 14:16 UTC
606e7205a3ff52247a0925fe5836b732836396c3
2 files changed
+50
-11
TO
+3
-2
@@ -111,8 +111,9 @@ Using Topic Branches
111
112
Some important disciplines first.
113
114
- * Once a topic branch forks from "master", never merge "master"
115
- updates into the topic branch.
114
+ * Once a topic branch forks from "master", avoid merging "master"
115
+ updates into the topic branch unless necessary to resolve conflicts
116
+ early.
117
118
* Once a topic branch is fully cooked and merged into "master",
119
delete it. If you need to build on top of it to correct
git-topic.perl
+47
-9
@@ -25,9 +25,9 @@ if (@custom_stage) { @stage = @custom_stage; }
25
if (@custom_mark) { @mark = @custom_mark; }
26
27
sub read_revs_short {
28
- my ($bottom, $top) = @_;
28
+ my (@args) = @_;
29
my @revs;
30
- open(REVS, '-|', qw(git rev-list --no-merges), "$bottom..$top")
30
+ open(REVS, '-|', qw(git rev-list --no-merges), @args)
31
or die;
32
while (<REVS>) {
33
chomp;
@@ -52,12 +52,45 @@ sub read_revs {
52
return @revs;
53
}
54
55
+sub rebase_marker {
56
+ my ($topic, $stage, $in_next) = @_;
57
+ my @not_in_topic = read_revs_short('^master', "^$topic", "$stage");
58
+
59
+ # @$in_next is what is in $stage but not in $base.
60
+ # @not_in_topic excludes what came from $topic from @$in_next.
61
+ # $topic can be rebased if these two set matches, because
62
+ # no commits in $topic has been merged to $stage yet.
63
+ if (@not_in_topic != @$in_next) {
64
+ # we cannot rebase it anymore
65
+ return ' ';
66
+ }
67
+ if (read_revs_short('master', "^$topic")) {
68
+ # there is something that is in master but not in topic.
69
+ return '^';
70
+ }
71
+ # topic is up to date.
72
+ return '*';
73
+}
74
+
75
+sub describe_topic {
76
+ my ($topic) = @_;
77
+ open(CONF, '-|', qw(git repo-config --get),
78
+ "branch.$topic.description")
79
+ or die;
80
+ my $it = join('',<CONF>);
81
+ close(CONF);
82
+ chomp($it);
83
+ if ($it) {
84
+ wrap_print(" $it");
85
+ }
86
+}
87
+
88
sub wrap_print {
56
- my ($prefix, $string) = @_;
89
+ my ($string) = @_;
90
format STDOUT =
58
- @ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
59
- $prefix, $string
60
- ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
91
+~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
92
+ $string
93
+ ~~^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
94
$string
95
.
96
write;
@@ -69,6 +102,8 @@ open(TOPIC, '-|', qw(git for-each-ref),
102
"refs/heads/$topic_pattern")
103
or die;
104
105
+my @in_next = read_revs_short('^master', $stage[0]);
106
+
107
while (<TOPIC>) {
108
chomp;
109
my ($sha1, $date, $topic) = m|^([0-9a-f]{40})\s(.*?)\srefs/heads/(.+)$|
@@ -78,18 +113,21 @@ while (<TOPIC>) {
113
114
my %revs = map { $_->[0] => $_ } @revs; # fast index
115
for (my $i = 0; $i < @stage; $i++) {
81
- for my $item (read_revs_short($stage[$i], $sha1)) {
116
+ for my $item (read_revs_short("^$stage[$i]", $sha1)) {
117
if (exists $revs{$item}) {
118
$revs{$item}[2] &= ~(1 << $i);
119
}
120
}
121
}
87
- print "* $topic ($date)\n";
122
+
123
+ print '*' . rebase_marker($sha1, $stage[0], \@in_next);
124
+ print " $topic ($date)\n";
125
+ describe_topic($topic);
126
for my $item (@revs) {
127
my $mark = $item->[2];
128
if ($mark < @mark) {
129
$mark = $mark[$mark];
130
}
93
- wrap_print($mark, $item->[1]);
131
+ wrap_print("$mark $item->[1]");
132
}
133
}