Rune L / Multichannel_Gas_Sensor
Committer:
runesla
Date:
Sat Mar 20 13:35:03 2021 +0100
Revision:
10:8ace727cec3f
added write addr in ctr

Who changed what in which revision?

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