/usr/share/doc/monotone/html/Dealing-with-a-Fork.html is in monotone-doc 1.1-7.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Created by GNU Texinfo 6.0, http://www.gnu.org/software/texinfo/ -->
<head>
<title>monotone documentation: Dealing with a Fork</title>
<meta name="description" content="monotone documentation: Dealing with a Fork">
<meta name="keywords" content="monotone documentation: Dealing with a Fork">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="General-Index.html#General-Index" rel="index" title="General Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Tutorial.html#Tutorial" rel="up" title="Tutorial">
<link href="Branching-and-Merging.html#Branching-and-Merging" rel="next" title="Branching and Merging">
<link href="Making-Changes.html#Making-Changes" rel="prev" title="Making Changes">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space: nowrap}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: serif; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
<link rel="stylesheet" type="text/css" href="texinfo.css">
</head>
<body lang="en">
<a name="Dealing-with-a-Fork"></a>
<div class="header">
<p>
Next: <a href="Branching-and-Merging.html#Branching-and-Merging" accesskey="n" rel="next">Branching and Merging</a>, Previous: <a href="Making-Changes.html#Making-Changes" accesskey="p" rel="prev">Making Changes</a>, Up: <a href="Tutorial.html#Tutorial" accesskey="u" rel="up">Tutorial</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="General-Index.html#General-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Dealing-with-a-Fork-1"></a>
<h3 class="section">2.11 Dealing with a Fork</h3>
<p>Careful readers will note that, in the previous section, the JuiceBot
company’s work was perfectly serialized:
</p>
<ol>
<li> Jim did some work
</li><li> Abe synced with Jim
</li><li> Abe did some work
</li><li> Abe synced with Jim
</li><li> Beth synced with Jim
</li><li> Beth did some work
</li><li> Beth synced with Jim
</li></ol>
<p>The result of this ordering is that Jim’s work entirely preceded
Abe’s work, which entirely preceded Beth’s work. Moreover, each
worker was fully informed of the “up-stream” worker’s actions, and
produced purely derivative, “down-stream” work:
</p>
<ol>
<li> Jim made revision 493bd...
</li><li> Abe changed revision 493bd... into revision 42eae...
</li><li> Beth derived revision 42eae... into revision 85573...
</li></ol>
<p>This is a simple, but sadly unrealistic, ordering of events. In real
companies or work groups, people often work in parallel,
<em>diverging</em> from commonly known revisions and <em>merging</em>
their work together, sometime after each unit of work is complete.
</p>
<p>Monotone supports this diverge/merge style of operation naturally; any
time two revisions diverge from a common parent revision, we say that
the revision graph has a <em>fork</em> in it. Forks can happen at any
time, and require no coordination between workers. In fact any
interleaving of the previous events would work equally well; with one
exception: if forks were produced, someone would eventually have to
run the <code>merge</code> command, and possibly resolve any conflicts
in the fork.
</p>
<p>To illustrate this, we return to our workers Beth and Abe. Suppose Jim
sends out an email saying that the current polling juice dispensers
use too much CPU time, and must be rewritten to use the JuiceBot’s
interrupt system. Beth wakes up first and begins working immediately,
basing her work off the revision 85573... which is currently in her
workspace:
</p>
<div class="smallexample">
<pre class="smallexample">$ vi src/banana.c
<i><Beth changes her banana-juice dispenser to use interrupts></i>
</pre></div>
<p>Beth finishes and examines her changes:
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn diff
#
# old_revision [85573a54105cd3220db10aa6a0713643cdf5ce6f]
#
# patch "src/banana.c"
# from [d7e28a01cf6fc0f9ac04c6901dcafd77c2d32fb8]
# to [dd979c3c880e6a7221fcecd7148bd4afcfb3e964]
#
============================================================
--- src/banana.c d7e28a01cf6fc0f9ac04c6901dcafd77c2d32fb8
+++ src/banana.c dd979c3c880e6a7221fcecd7148bd4afcfb3e964
@ -1,10 +1,15 @
#include "jb.h"
+static void
+shut_off_banana()
+{
+ spoutctl(BANANA_SPOUT, SET_INTR, 0);
+ spoutctl(BANANA_SPOUT, FLOW_JUICE, 0);
+}
+
void
dispense_banana_juice()
{
+ spoutctl(BANANA_SPOUT, SET_INTR, &shut_off_banana);
spoutctl(BANANA_SPOUT, FLOW_JUICE, 1);
- while (spoutctl(BANANA_SPOUT, POLL_JUICE, 1) == 0)
- usleep (1000);
- spoutctl(BANANA_SPOUT, FLOW_JUICE, 0);
}
</pre></div>
<p>She commits her work:
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn commit --message="interrupt implementation of src/banana.c"
mtn: beginning commit on branch 'jp.co.juicebot.jb7'
mtn: committed revision 90abe0f1bc354a73d42d3bff1b02946559682bd9
</pre></div>
<p>And she syncs with Jim:
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn sync
</pre></div>
<p>Unfortunately, before Beth managed to sync with Jim, Abe had woken up
and implemented a similar interrupt-based apple juice dispenser, but
his workspace is 42eae..., which is still “upstream” of Beth’s.
</p>
<div class="smallexample">
<pre class="smallexample">$ vi apple.c
<i><Abe changes his apple-juice dispenser to use interrupts></i>
</pre></div>
<p>Thus when Abe commits, he unknowingly creates a fork:
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn commit --message="interrupt implementation of src/apple.c"
</pre></div>
<p>Abe does not see the fork yet; Abe has not actually seen <em>any</em> of
Beth’s work yet, because he has not synchronized with Jim. Since
he has new work to contribute, however, he now syncs:
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn sync
</pre></div>
<p>Now Jim and Abe will be aware of the fork. Jim sees it when he sits
down at his desk and asks monotone for the current set of heads of
the branch:
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn heads
mtn: branch 'jp.co.juicebot.jb7' is currently unmerged:
90abe0f1bc354a73d42d3bff1b02946559682bd9 abe@juicebot.co.jp 2004-10-26T02:53:16
951da88860a4cf7419d66ed9094d8bf24df5fb8b beth@juicebot.co.jp 2004-10-26T02:53:15
</pre></div>
<p>Clearly there are two heads to the branch: it contains an un-merged
fork. Beth will not yet know about the fork, but in this case it
doesn’t matter: anyone can merge the fork, and since there are no
conflicts Jim does so himself:
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn merge
mtn: 2 heads on branch 'jp.co.juicebot.jb7'
mtn: merge 1 / 1:
mtn: calculating best pair of heads to merge next
mtn: [left] 90abe0f1bc354a73d42d3bff1b02946559682bd9
mtn: [right] 951da88860a4cf7419d66ed9094d8bf24df5fb8b
mtn: [merged] 3aca69c7749bde9bd07fe4c92bb868bd69b2e421
mtn: note: your workspaces have not been updated
</pre></div>
<p>The output of this command shows Jim that two heads were found,
combined via a 3-way merge with their ancestor, and saved to a new
revision. This happened automatically, because the changes between the
common ancestor and heads did not conflict. If there had been a
conflict, monotone would have invoked an external merging tool to help
resolve it, or Jim could have used the <code>conflicts</code> set of
commands to resolve it (see <a href="Conflicts.html#Conflicts">Conflicts</a>).
</p>
<p>After merging, the branch has a single head again, and Jim updates
his workspace.
</p>
<div class="smallexample">
<pre class="smallexample">$ mtn update
mtn: updating along branch 'jp.co.juicebot.jb7'
mtn: selected update target 3aca69c7749bde9bd07fe4c92bb868bd69b2e421
mtn: [left] d60c18ec5e0cf1163b276f0bfdd908c1dfd53b4a
mtn: [right] 3aca69c7749bde9bd07fe4c92bb868bd69b2e421
mtn: updating src/apple.c
mtn: updating src/banana.c
mtn: updated to base revision 3aca69c7749bde9bd07fe4c92bb868bd69b2e421
</pre></div>
<p>The update command selected an update target — in this case the newly merged
head — and performed an in-memory merge between Jim’s workspace
and the chosen target. The result was then written to Jim’s workspace. If
Jim’s workspace had any uncommitted changes in it, they would have been
merged with the update in exactly the same manner as the merge of multiple
committed heads.
</p>
<p>Monotone makes very little distinction between a “pre-commit” merge
(an update) and a “post-commit” merge. Both sorts of merge use the
exact same algorithm. The major difference concerns the recoverability
of the pre-merge state: if you commit your work first, and merge after
committing, then even if the merge somehow fails (due to difficulty in a
manual merge step, for instance), your committed state is still safe.
If you update, on the other hand, you are requesting that monotone
directly modify your workspace, and while monotone will try hard not
to break anything, this process is inherently more open to error. It is
therefore recommended that you commit your work <em>first</em>, before
merging.
</p>
<p>If you have previously used another version control system, this may at
first seem surprising; there are some systems where you are
<em>required</em> to update, and risk the above problems, before you can
commit. Monotone, however, was designed with this problem in mind, and
thus <em>always</em> allows you to commit before merging. A good rule of
thumb is to only use <code>update</code> in workspaces with no local
modifications, or when you actually want to work against a different
base revision (perhaps because finishing your change turns out to
require some fixes made in another revision, or because you discover
that you have accidentally started working against a revision that
contains unrelated bugs, and need to back out to a working revision for
testing).
</p>
<hr>
<div class="header">
<p>
Next: <a href="Branching-and-Merging.html#Branching-and-Merging" accesskey="n" rel="next">Branching and Merging</a>, Previous: <a href="Making-Changes.html#Making-Changes" accesskey="p" rel="prev">Making Changes</a>, Up: <a href="Tutorial.html#Tutorial" accesskey="u" rel="up">Tutorial</a> [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="General-Index.html#General-Index" title="Index" rel="index">Index</a>]</p>
</div>
</body>
</html>
|