Simulated product dispenser

Dependencies:   HTS221

Fork of mbed-cloud-workshop-connect-HTS221 by Jim Carver

Committer:
JimCarver
Date:
Thu Oct 25 14:00:12 2018 +0000
Revision:
4:e518dde96e59
Parent:
0:6b753f761943
Simulated dispenser

Who changed what in which revision?

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