Debian Codegraph @

www/privatebranch.html

raw
1 <!DOCTYPE html>
2 <html><head>
3 <meta name="viewport" content="width=device-width, initial-scale=1.0">
4 <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5 <link href="sqlite.css" rel="stylesheet">
6 <title>Maintaining Private Branches Of SQLite</title>
7 <!-- path= -->
8 </head>
9 <body>
10 <div class=nosearch>
11 <a href="index.html">
12 <img class="logo" src="images/sqlite370_banner.gif" alt="SQLite" border="0">
13 </a>
14 <div><!-- IE hack to prevent disappearing logo --></div>
15 <div class="tagline desktoponly">
16 Small. Fast. Reliable.<br>Choose any three.
17 </div>
18 <div class="menu mainmenu">
19 <ul>
20 <li><a href="index.html">Home</a>
21 <li class='mobileonly'><a href="javascript:void(0)" onclick='toggle_div("submenu")'>Menu</a>
22 <li class='wideonly'><a href='about.html'>About</a>
23 <li class='desktoponly'><a href="docs.html">Documentation</a>
24 <li class='desktoponly'><a href="download.html">Download</a>
25 <li class='wideonly'><a href='copyright.html'>License</a>
26 <li class='desktoponly'><a href="support.html">Support</a>
27 <li class='desktoponly'><a href="prosupport.html">Purchase</a>
28 <li class='search' id='search_menubutton'>
29 <a href="javascript:void(0)" onclick='toggle_search()'>Search</a>
30 </ul>
31 </div>
32 <div class="menu submenu" id="submenu">
33 <ul>
34 <li><a href='about.html'>About</a>
35 <li><a href='docs.html'>Documentation</a>
36 <li><a href='download.html'>Download</a>
37 <li><a href='support.html'>Support</a>
38 <li><a href='prosupport.html'>Purchase</a>
39 </ul>
40 </div>
41 <div class="searchmenu" id="searchmenu">
42 <form method="GET" action="search">
43 <select name="s" id="searchtype">
44 <option value="d">Search Documentation</option>
45 <option value="c">Search Changelog</option>
46 </select>
47 <input type="text" name="q" id="searchbox" value="">
48 <input type="submit" value="Go">
49 </form>
50 </div>
51 </div>
52 <script>
53 function toggle_div(nm) {
54 var w = document.getElementById(nm);
55 if( w.style.display=="block" ){
56 w.style.display = "none";
57 }else{
58 w.style.display = "block";
59 }
60 }
61 function toggle_search() {
62 var w = document.getElementById("searchmenu");
63 if( w.style.display=="block" ){
64 w.style.display = "none";
65 } else {
66 w.style.display = "block";
67 setTimeout(function(){
68 document.getElementById("searchbox").focus()
69 }, 30);
70 }
71 }
72 function div_off(nm){document.getElementById(nm).style.display="none";}
73 window.onbeforeunload = function(e){div_off("submenu");}
74 /* Disable the Search feature if we are not operating from CGI, since */
75 /* Search is accomplished using CGI and will not work without it. */
76 if( !location.origin || !location.origin.match || !location.origin.match(/http/) ){
77 document.getElementById("search_menubutton").style.display = "none";
78 }
79 /* Used by the Hide/Show button beside syntax diagrams, to toggle the */
80 function hideorshow(btn,obj){
81 var x = document.getElementById(obj);
82 var b = document.getElementById(btn);
83 if( x.style.display!='none' ){
84 x.style.display = 'none';
85 b.innerHTML='show';
86 }else{
87 x.style.display = '';
88 b.innerHTML='hide';
89 }
90 return false;
91 }
92 var antiRobot = 0;
93 function antiRobotGo(){
94 if( antiRobot!=3 ) return;
95 antiRobot = 7;
96 var j = document.getElementById("mtimelink");
97 if(j && j.hasAttribute("data-href")) j.href=j.getAttribute("data-href");
98 }
99 function antiRobotDefense(){
100 document.body.onmousedown=function(){
101 antiRobot |= 2;
102 antiRobotGo();
103 document.body.onmousedown=null;
104 }
105 document.body.onmousemove=function(){
106 antiRobot |= 2;
107 antiRobotGo();
108 document.body.onmousemove=null;
109 }
110 setTimeout(function(){
111 antiRobot |= 1;
112 antiRobotGo();
113 }, 100)
114 antiRobotGo();
115 }
116 antiRobotDefense();
117 </script>
118 <div class=fancy>
119 <div class=nosearch>
120 <div class="fancy_title">
121 Maintaining Private Branches Of SQLite
122 </div>
123 <div class="fancy_toc">
124 <a onclick="toggle_toc()">
125 <span class="fancy_toc_mark" id="toc_mk">&#x25ba;</span>
126 Table Of Contents
127 </a>
128 <div id="toc_sub"><div class="fancy-toc1"><a href="#_introduction">1. Introduction</a></div>
129 <div class="fancy-toc1"><a href="#_the_basic_idea">2. The Basic Idea</a></div>
130 <div class="fancy-toc1"><a href="#_the_procedure">3. The Procedure</a></div>
131 <div class="fancy-toc2"><a href="#_obtain_the_software">3.1. Obtain The Software</a></div>
132 <div class="fancy-toc2"><a href="#_create_a_project_repository">3.2. Create A Project Repository</a></div>
133 <div class="fancy-toc2"><a href="#_installing_the_sqlite_baseline_in_fossil">3.3. Installing The SQLite Baseline In Fossil</a></div>
134 <div class="fancy-toc2"><a href="#_creating_the_private_branch">3.4. Creating The Private Branch</a></div>
135 <div class="fancy-toc2"><a href="#_adding_customizations_to_the_code_in_the_private_branch">3.5. Adding Customizations To The Code In The Private Branch</a></div>
136 <div class="fancy-toc2"><a href="#_incorporating_new_public_sqlite_releases">3.6. Incorporating New Public SQLite Releases</a></div>
137 <div class="fancy-toc2"><a href="#_merging_public_sqlite_updates_into_the_private_branch">3.7. Merging Public SQLite Updates Into The Private Branch</a></div>
138 <div class="fancy-toc2"><a href="#_further_updates">3.8. Further Updates</a></div>
139 <div class="fancy-toc1"><a href="#_variations">4. Variations</a></div>
140 </div>
141 </div>
142 <script>
143 function toggle_toc(){
144 var sub = document.getElementById("toc_sub")
145 var mk = document.getElementById("toc_mk")
146 if( sub.style.display!="block" ){
147 sub.style.display = "block";
148 mk.innerHTML = "&#x25bc;";
149 } else {
150 sub.style.display = "none";
151 mk.innerHTML = "&#x25ba;";
152 }
153 }
154 </script>
155 </div>
156
157
158
159
160
161 <h1 id="_introduction"><span>1. </span> Introduction</h1>
162
163 <p>SQLite is designed to meet most developer's needs without any
164 changes or customization. When changes are needed, they can normally
165 be accomplished using start-time <a href="c3ref/config.html">(1)</a>
166 or runtime
167 <a href="c3ref/db_config.html">(2)</a>
168 <a href="c3ref/limit.html">(3)</a>
169 <a href="c3ref/vfs_find.html">(4)</a> configuration methods
170 or via <a href="compile.html">compile-time options</a>. It is very rare that an application
171 developer will need to edit the SQLite source code in order to
172 incorporate SQLite into a product.</p><p>
173
174 </p><p>We call custom modifications to the SQLite source code that are held
175 for the use of a single application a "private branch". When a private
176 branch becomes necessary, the application developer must take on the
177 task of keeping the private branch in synchronization with the public
178 SQLite sources. This is tedious. It can also be tricky, since while
179 the SQLite file format and published interfaces are very stable, the
180 internal implementation of SQLite changes quite rapidly. Hundreds or
181 thousands of lines of code might change for any given SQLite point release.
182 </p>
183
184 <p>This article outlines one possible method for keeping a private branch
185 of SQLite in sync with the public SQLite source code.
186 There are many ways of maintaining a private branch, of course.
187 Nobody is compelled to use the method describe here.
188 This article is not trying to impose a particular procedure on
189 maintainers of private branches. The point of this article is to offer
190 an example of one process for maintaining a private branch which can
191 be used as a template for designing processes best suited for the
192 circumstances of each individual project.</p>
193
194 <img src="images/private_branch.gif" align="right">
195 <h1 id="_the_basic_idea"><span>2. </span> The Basic Idea</h1>
196
197
198 <p>We propose to use the
199 <a href="http://www.fossil-scm.org">fossil software configuration management</a>
200 system to set up two branches. One branch (the "public branch" or "trunk")
201 contains the published SQLite sources and the other branch is the
202 private branch which contains the code that is customized for the project.
203 Whenever a new public release of SQLite is made, that release is added to
204 the public branch and then the changes are merged into the private branch.</p>
205
206 <p>This document proposes to use
207 <a href="http://www.fossil-scm.org/">fossil</a>,
208 but any other distributed software configuration management system such as
209 <a href="http://www.monotone.ca/">monotone</a> or
210 <a href="http://www.selenic.com/mercurial/wiki/">mercurial</a> (a.k.a. "hg"), or
211 <a href="http://www.git-scm.org/">git</a> could serve just as well.
212 The concept will be the same,
213 though the specifics of the procedure will vary.</p>
214
215 <p>The diagram at the right illustrates the concept.
216 One begins with a standard SQLite release. For the
217 sake of example, suppose that one intends to create a
218 private branch off of SQLite version 3.6.15. In the
219 diagram this is version (1). The
220 maintainer makes an exact copy of the baseline
221 SQLite into the branch space, shown as version (2).
222 Note that (1) and (2) are exactly the same. Then
223 the maintainer applies the private changes to
224 version (2) resulting in version (3). In other words,
225 version (3) is SQLite version 3.6.15 plus edits.</p>
226
227 <p>Later, SQLite version 3.6.16 is released, as shown
228 by circle (4) in the diagram. At the point, the private
229 branch maintainer does a merge which takes all of the
230 changes going from (1) to (4) and applies those changes to
231 (3). The result is version (5), which is SQLite 3.6.16
232 plus edits.</p>
233
234 <p>There might be merge conflicts. In other words, it might
235 be that the changes from (2) to (3) are incompatible with the
236 changes from (1) to (4). In that case, the maintainer will
237 have to manually resolve the conflicts. Hopefully conflicts
238 will not come up that often. Conflicts are less likely to
239 occur when the private edits are kept to a minimum.</p>
240
241 <p>The cycle above can be repeated many times. The
242 diagram shows a third SQLite release, 3.6.17 in
243 circle (6). The private branch maintainer can do
244 another merge in order to incorporate the changes
245 moving from (4) to (6) into the private branch, resulting
246 in version (7).</p>
247
248 <h1 id="_the_procedure"><span>3. </span> The Procedure</h1>
249
250 <p>The remainder of this document will guide the reader through
251 the steps needed to maintain a private branch. The general idea
252 is the same as outlined above. This section merely provides more
253 detail.</p>
254
255 <p>We emphasize again that these steps are not intended to be the only
256 acceptable method for maintaining private branch. This approach
257 is one of many. Use this document as a baseline for preparing
258 project-specific procedures. Do not be afraid to experiment.</p>
259
260 <h2 id="_obtain_the_software"><span>3.1. </span> Obtain The Software</h2>
261
262 <p><a href="http://www.fossil-scm.org/">Fossil</a> is a computer program
263 that must be installed on your machine before you use it.
264 Fortunately, installing fossil is very easy. Fossil is a single
265 "*.exe" file that you simply download and run. To uninstall fossil,
266 simply delete the exe file.
267 <a href="http://www.fossil-scm.org/index.html/doc/tip/www/quickstart.wiki">Detailed instructions</a> for installing and getting started with
268 fossil are available on the
269 <a href="http://www.fossil-scm.org">fossil website</a>.</p>
270
271 <h2 id="_create_a_project_repository"><span>3.2. </span> Create A Project Repository</h2>
272
273 <p>Create a fossil repository to host the private branch using the
274 following command:</p>
275
276 <blockquote><pre>
277 fossil new private-project.fossil
278 </pre></blockquote>
279
280 <p>You can call your project anything you like. The "<tt>.fossil</tt>"
281 suffix is optional. For this document, we will continue to call the
282 project "<tt>private-project.fossil</tt>". Note that
283 <tt>private-project.fossil</tt> is an ordinary disk file (actually an
284 SQLite database) that will contain your complete project history.
285 You can make a backup of the project simply by making a copy of that
286 one file.</p>
287
288 <p>If you want to configure the new project, type:</p>
289
290 <blockquote><pre>
291 fossil ui private-project.fossil
292 </pre></blockquote>
293
294 <p>The "ui" command will cause fossil to run a miniature built-in webserver
295 and to launch your web-browser pointing
296 at that webserver. You can use your web-browser to configure your project
297 in various ways. See the instructions on the fossil website for additional
298 information.</p>
299
300 <p>Once the project repository is created, create an open checkout of the
301 project by moving to the directory where you want to keep all of the
302 project source code and typing:</p>
303
304 <blockquote><pre>
305 fossil open private-project.fossil
306 </pre></blockquote>
307
308 <p>You can have multiple checkouts of the same project if you want.
309 And you can "clone" the repository to different machines so that multiple
310 developers can use it. See the fossil website for further information.</p>
311
312 <h2 id="_installing_the_sqlite_baseline_in_fossil"><span>3.3. </span> Installing The SQLite Baseline In Fossil</h2>
313
314 <p>The repository created in the previous step is initially empty. The
315 next step is to load the baseline SQLite release - circle (1) in the diagram
316 above.</p>
317
318 <p>Begin by obtaining a copy of SQLite in whatever form you use it.
319 The public SQLite you obtain should be as close to your private edited
320 copy as possible. If your project uses the SQLite amalgamation, then
321 get a copy of the amalgamation. If you use the preprocessed separate
322 source files, get those instead. Put all the source files in the
323 checkout directory created in the previous step.</p>
324
325 <p>The source code in public SQLite releases uses unix line endings
326 (ASCII code 10: "newline" only, NL) and spaces instead of tabs. If you will
327 be changing the line ending to windows-style line endings
328 (ASCII codes 13, 10: "carriage-return" and "newline"; CR-NL) or if you will be
329 changing space indents into tab indents, <b>make that change now</b>
330 before you check in the baseline. The merging process will only work
331 well if the differences between the public and the private branches are
332 minimal. If every single line of the source file is changed in the
333 private branch because you changed from NL to CR-NL line endings, then
334 the merge steps will not work correctly.</p>
335
336 <p>Let us assume that you are using the amalgamation source code.
337 Add the baseline to your project as follows:</p>
338
339 <blockquote><pre>
340 fossil add sqlite3.c sqlite3.h
341 </pre></blockquote>
342
343 <p>If you are using separate source files, name all of the source files instead
344 of just the two amalgamation source files. Once this is done, commit your
345 changes as follows:</p>
346
347 <blockquote><pre>
348 fossil commit
349 </pre></blockquote>
350
351 <p>You will be prompted for a check-in comment. Say whatever you like.
352 After the commit completes, your baseline will be part of the repository.
353 The following command, if you like, to see this on the "timeline":
354 </p>
355
356 <blockquote><pre>
357 fossil ui
358 </pre></blockquote>
359
360 <p>That last command is the same "ui" command that we ran before. It
361 starts a mini-webserver running and points your web browser at it. But
362 this time we didn't have to specify the repository file because we are
363 located inside a checkout and so fossil can figure out the repository for
364 itself. If you want to type in the repository filename as the second
365 argument, you can. But it is optional.</p>
366
367 <p>If you do not want to use your web browser to view the new check-in,
368 you can get some information from the command-line using commands like
369 these:
370
371 </p><blockquote><pre>
372 fossil timeline
373 fossil info
374 fossil status
375 </pre></blockquote>
376
377 <h2 id="_creating_the_private_branch"><span>3.4. </span> Creating The Private Branch</h2>
378
379 <p>The previous step created circle (1) in the diagram above.
380 This step will create circle (2). Run the following command:</p>
381
382 <blockquote><pre>
383 fossil branch new private trunk -bgcolor "#add8e8"
384 </pre></blockquote>
385
386 <p>This command will create a new branch named "private" (you can use
387 a different name if you like) and assign it a background color
388 of light blue ("#add8e8"). You can omit the background color if you want,
389 though having a distinct background does make it easier to tell the
390 branch from the "trunk" (the public branch) on timeline displays. You
391 can change the background color of the private branch or of the public
392 branch (the "trunk") using the web interface if you like.</p>
393
394 <p>The command above created the new branch. But your checkout is
395 still on the trunk - a fact you can see by running the command:</p>
396
397 <blockquote><pre>
398 fossil info
399 </pre></blockquote>
400
401 <p>To change your check-out to the private branch, type:</p>
402
403 <blockquote><pre>
404 fossil update private
405 </pre></blockquote>
406
407 <p>You can run the "info" command again to verify that you are on the
408 private branch. To go back to the public branch, type:</p>
409
410 <blockquote><pre>
411 fossil update trunk
412 </pre></blockquote>
413
414 <p>Normally, fossil will modify all the files in your checkout when switching
415 between the private and the public branches. But at this point, the files
416 are identical in both branches so no modifications need to be made.</p>
417
418 <h2 id="_adding_customizations_to_the_code_in_the_private_branch"><span>3.5. </span> Adding Customizations To The Code In The Private Branch</h2>
419
420 <p>Now it is time to make the private, custom modifications to SQLite
421 which are the whole point of this exercise. Switch to the private branch
422 (if you are not already there) using the "<tt>fossil update private</tt>"
423 command, then bring up the source files in your text editor and make
424 whatever changes you want to make. Once you have finished making
425 changes, commit those changes using this command:</p>
426
427 <blockquote><pre>
428 fossil commit
429 </pre></blockquote>
430
431 <p>You will be prompted once again to enter a commit describing your
432 changes. Then the commit will occur. The commit creates a new checkin
433 in the repository that corresponds to circle (3) in the diagram above.</p>
434
435 <p>Now that the public and private branches are different, you can run
436 the "<tt>fossil update trunk</tt>" and "<tt>fossil update private</tt>"
437 commands and see that fossil really does change the files in the checkout
438 as you switch back and forth between branches.</p>
439
440 <p>Note that in the diagram above, we showed the private edits as a single
441 commit. This was for clarity of presentation only. There is nothing to stop
442 you from doing dozens or hundreds of separate tiny changes and committing
443 each separately. In fact, making many small changes is the preferred way
444 to work. The only reason for doing all the changes in a single commit
445 is that it makes the diagram easier to draw.</p>
446
447 <h2 id="_incorporating_new_public_sqlite_releases"><span>3.6. </span> Incorporating New Public SQLite Releases</h2>
448
449 <p>Suppose that after a while (about a month, usually) a new version of
450 SQLite is released: 3.6.16. You will want to incorporate this new
451 public version of SQLite into your repository in the public branch (the
452 trunk). To do this, first change your repository over to the trunk:</p>
453
454 <blockquote><pre>
455 fossil update trunk
456 </pre></blockquote>
457
458 <p>Then download the new version of the SQLite sources and overwrite the
459 files that are in the checkout.</p><p>
460
461 </p><p>If you made NL to CR-NL line ending changes or space to tab
462 indentation changes in the original baseline, make the same changes
463 to the new source file.</p>
464
465 <p>Once everything is ready, run the "<tt>fossil commit</tt>" command to
466 check in the changes. This creates circle (4) in the diagram above.</p>
467
468 <h2 id="_merging_public_sqlite_updates_into_the_private_branch"><span>3.7. </span> Merging Public SQLite Updates Into The Private Branch</h2>
469
470 <p>The next step is to move the changes in the public branch over into
471 the private branch. In other words, we want to create circle (5) in the
472 diagram above. Begin by changing to the private branch using
473 "<tt>fossil update private</tt>". Then type this command:</p>
474
475 <blockquote><pre>
476 fossil merge trunk
477 </pre></blockquote>
478
479 <p>The "merge" command attempts to apply all the changes between
480 circles (1) and (4) to the files in the local checkout. Note that
481 circle (5) has not been created yet. You will need to run the
482 "commit" to create circle (5).</p>
483
484 <p>It might be that there are conflicts in the merge. Conflicts
485 occur when the same line of code was changed in different ways between
486 circles (1) and (4) versus circles (2) and (3). The merge command will
487 announce any conflicts and will include both versions of the conflicting
488 lines in the output. You will need to bring up the files that contain
489 conflicts and manually resolve the conflicts.</p>
490
491 <p>After resolving conflicts, many users like to compile and test the
492 new version before committing it to the repository. Or you can commit
493 first and test later. Either way, run the "<tt>fossil commit</tt>"
494 command to check-in the circle (5) version.
495
496 </p><h2 id="_further_updates"><span>3.8. </span> Further Updates</h2>
497
498 <p>As new versions of SQLite are released, repeat steps 3.6 and 3.7 to
499 add changes in the new release to the private branch.
500 Additional private changes can be
501 made on the private branch in between releases if desired.</p>
502
503 <h1 id="_variations"><span>4. </span> Variations</h1>
504
505 <p>Since this document was first written, the canonical SQLite source code
506 has been moved from the venerable CVS system into a Fossil repository at
507 <a href="https://www.sqlite.org/src">https://www.sqlite.org/src</a>. This means that if you are working with
508 canonical SQLite source code (as opposed to the <a href="amalgamation.html">amalgamation</a> source code
509 files, sqlite3.c and sqlite3.h) then you can create a private repository
510 simply by cloning the official repository:</p>
511
512 <blockquote><pre>
513 fossil clone https://www.sqlite.org/src private-project.fossil
514 </pre></blockquote>
515
516 <p>This command both creates the new repository and populates it with
517 all the latest SQLite code. You can then create a private branch as
518 described in section 3.4.</p>
519
520 <p>When the private repository is created by cloning, incorporating new
521 public SQLite releases becomes much easier too. To pull in all of the
522 latest changes from the public SQLite repository, simply move into
523 the open check-out and do:</p>
524
525 <blockquote><pre>
526 fossil update
527 </pre></blockquote>
528
529 <p>Then continue to merge the changes in "trunk" with your "private"
530 changes as described in section 3.7.</p>
531
532