FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:35:07 2017 +0000
Revision:
0:a2cb7295a1f7
Initial commit

Who changed what in which revision?

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