Mbed Cloud example program for workshop in W27 2018.

Dependencies:   MMA7660 LM75B

Committer:
MACRUM
Date:
Sat Jun 30 01:40:30 2018 +0000
Revision:
0:119624335925
Initial commit

Who changed what in which revision?

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