FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

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