A metronome using the FRDM K64F board

Committer:
ram54288
Date:
Sun May 14 18:40:18 2017 +0000
Revision:
0:a7a43371b306
Initial commit

Who changed what in which revision?

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