annotate ffmpeg/.git/hooks/pre-rebase.sample @ 13:844d341cf643 tip

Back up before ISMIR
author Yading Song <yading.song@eecs.qmul.ac.uk>
date Thu, 31 Oct 2013 13:17:06 +0000
parents 6840f77b83aa
children
rev   line source
yading@10 1 #!/bin/sh
yading@10 2 #
yading@10 3 # Copyright (c) 2006, 2008 Junio C Hamano
yading@10 4 #
yading@10 5 # The "pre-rebase" hook is run just before "git rebase" starts doing
yading@10 6 # its job, and can prevent the command from running by exiting with
yading@10 7 # non-zero status.
yading@10 8 #
yading@10 9 # The hook is called with the following parameters:
yading@10 10 #
yading@10 11 # $1 -- the upstream the series was forked from.
yading@10 12 # $2 -- the branch being rebased (or empty when rebasing the current branch).
yading@10 13 #
yading@10 14 # This sample shows how to prevent topic branches that are already
yading@10 15 # merged to 'next' branch from getting rebased, because allowing it
yading@10 16 # would result in rebasing already published history.
yading@10 17
yading@10 18 publish=next
yading@10 19 basebranch="$1"
yading@10 20 if test "$#" = 2
yading@10 21 then
yading@10 22 topic="refs/heads/$2"
yading@10 23 else
yading@10 24 topic=`git symbolic-ref HEAD` ||
yading@10 25 exit 0 ;# we do not interrupt rebasing detached HEAD
yading@10 26 fi
yading@10 27
yading@10 28 case "$topic" in
yading@10 29 refs/heads/??/*)
yading@10 30 ;;
yading@10 31 *)
yading@10 32 exit 0 ;# we do not interrupt others.
yading@10 33 ;;
yading@10 34 esac
yading@10 35
yading@10 36 # Now we are dealing with a topic branch being rebased
yading@10 37 # on top of master. Is it OK to rebase it?
yading@10 38
yading@10 39 # Does the topic really exist?
yading@10 40 git show-ref -q "$topic" || {
yading@10 41 echo >&2 "No such branch $topic"
yading@10 42 exit 1
yading@10 43 }
yading@10 44
yading@10 45 # Is topic fully merged to master?
yading@10 46 not_in_master=`git rev-list --pretty=oneline ^master "$topic"`
yading@10 47 if test -z "$not_in_master"
yading@10 48 then
yading@10 49 echo >&2 "$topic is fully merged to master; better remove it."
yading@10 50 exit 1 ;# we could allow it, but there is no point.
yading@10 51 fi
yading@10 52
yading@10 53 # Is topic ever merged to next? If so you should not be rebasing it.
yading@10 54 only_next_1=`git rev-list ^master "^$topic" ${publish} | sort`
yading@10 55 only_next_2=`git rev-list ^master ${publish} | sort`
yading@10 56 if test "$only_next_1" = "$only_next_2"
yading@10 57 then
yading@10 58 not_in_topic=`git rev-list "^$topic" master`
yading@10 59 if test -z "$not_in_topic"
yading@10 60 then
yading@10 61 echo >&2 "$topic is already up-to-date with master"
yading@10 62 exit 1 ;# we could allow it, but there is no point.
yading@10 63 else
yading@10 64 exit 0
yading@10 65 fi
yading@10 66 else
yading@10 67 not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"`
yading@10 68 /usr/bin/perl -e '
yading@10 69 my $topic = $ARGV[0];
yading@10 70 my $msg = "* $topic has commits already merged to public branch:\n";
yading@10 71 my (%not_in_next) = map {
yading@10 72 /^([0-9a-f]+) /;
yading@10 73 ($1 => 1);
yading@10 74 } split(/\n/, $ARGV[1]);
yading@10 75 for my $elem (map {
yading@10 76 /^([0-9a-f]+) (.*)$/;
yading@10 77 [$1 => $2];
yading@10 78 } split(/\n/, $ARGV[2])) {
yading@10 79 if (!exists $not_in_next{$elem->[0]}) {
yading@10 80 if ($msg) {
yading@10 81 print STDERR $msg;
yading@10 82 undef $msg;
yading@10 83 }
yading@10 84 print STDERR " $elem->[1]\n";
yading@10 85 }
yading@10 86 }
yading@10 87 ' "$topic" "$not_in_next" "$not_in_master"
yading@10 88 exit 1
yading@10 89 fi
yading@10 90
yading@10 91 exit 0
yading@10 92
yading@10 93 ################################################################
yading@10 94
yading@10 95 This sample hook safeguards topic branches that have been
yading@10 96 published from being rewound.
yading@10 97
yading@10 98 The workflow assumed here is:
yading@10 99
yading@10 100 * Once a topic branch forks from "master", "master" is never
yading@10 101 merged into it again (either directly or indirectly).
yading@10 102
yading@10 103 * Once a topic branch is fully cooked and merged into "master",
yading@10 104 it is deleted. If you need to build on top of it to correct
yading@10 105 earlier mistakes, a new topic branch is created by forking at
yading@10 106 the tip of the "master". This is not strictly necessary, but
yading@10 107 it makes it easier to keep your history simple.
yading@10 108
yading@10 109 * Whenever you need to test or publish your changes to topic
yading@10 110 branches, merge them into "next" branch.
yading@10 111
yading@10 112 The script, being an example, hardcodes the publish branch name
yading@10 113 to be "next", but it is trivial to make it configurable via
yading@10 114 $GIT_DIR/config mechanism.
yading@10 115
yading@10 116 With this workflow, you would want to know:
yading@10 117
yading@10 118 (1) ... if a topic branch has ever been merged to "next". Young
yading@10 119 topic branches can have stupid mistakes you would rather
yading@10 120 clean up before publishing, and things that have not been
yading@10 121 merged into other branches can be easily rebased without
yading@10 122 affecting other people. But once it is published, you would
yading@10 123 not want to rewind it.
yading@10 124
yading@10 125 (2) ... if a topic branch has been fully merged to "master".
yading@10 126 Then you can delete it. More importantly, you should not
yading@10 127 build on top of it -- other people may already want to
yading@10 128 change things related to the topic as patches against your
yading@10 129 "master", so if you need further changes, it is better to
yading@10 130 fork the topic (perhaps with the same name) afresh from the
yading@10 131 tip of "master".
yading@10 132
yading@10 133 Let's look at this example:
yading@10 134
yading@10 135 o---o---o---o---o---o---o---o---o---o "next"
yading@10 136 / / / /
yading@10 137 / a---a---b A / /
yading@10 138 / / / /
yading@10 139 / / c---c---c---c B /
yading@10 140 / / / \ /
yading@10 141 / / / b---b C \ /
yading@10 142 / / / / \ /
yading@10 143 ---o---o---o---o---o---o---o---o---o---o---o "master"
yading@10 144
yading@10 145
yading@10 146 A, B and C are topic branches.
yading@10 147
yading@10 148 * A has one fix since it was merged up to "next".
yading@10 149
yading@10 150 * B has finished. It has been fully merged up to "master" and "next",
yading@10 151 and is ready to be deleted.
yading@10 152
yading@10 153 * C has not merged to "next" at all.
yading@10 154
yading@10 155 We would want to allow C to be rebased, refuse A, and encourage
yading@10 156 B to be deleted.
yading@10 157
yading@10 158 To compute (1):
yading@10 159
yading@10 160 git rev-list ^master ^topic next
yading@10 161 git rev-list ^master next
yading@10 162
yading@10 163 if these match, topic has not merged in next at all.
yading@10 164
yading@10 165 To compute (2):
yading@10 166
yading@10 167 git rev-list master..topic
yading@10 168
yading@10 169 if this is empty, it is fully merged to "master".