source: tailor/README @ 506

Revision 506, 16.1 KB checked in by lele@…, 8 years ago (diff)

Some notes about using Python scripts for the configuration

Line 
1About
2=====
3
4Tailor is a tool to migrate changesets between CVS, Subversion_,
5darcs_, ArX_, monotone_, Codeville_, Mercurial_ and `Baazar-NG`_ [#]_
6repositories.
7
8This script makes it easier to keep the upstream changes merged in
9a branch of a product, storing needed information such as the upstream
10URI and revision in special properties on the branched directory.
11
12The following ascii-art illustrates the usual scenario::
13
14                           +------------+            +------------+
15  +--------------+         | Immutable  |            | Working    |
16  | Upstream CVS |-------->| darcs      |----------->| darcs      |
17  | repository   | tailor  | repository | darcs pull | repository |
18  +--------------+         +------------+            +------------+
19                                                           |^         
20                                                           ||
21                                                           ||
22                                                           v|
23                                                          User
24
25Ideally you should be able to swap and replace "CVS server" and "darcs
26repository" with any combination of the supported systems.
27
28A more convoluted setup shows how brave people are using it to get a
29two way sync::
30
31  +----------+        +--------+        +--------+       +---------+
32  |          | -----> | hybrid | darcs  |        | ----> |   my    |
33  | upstream | tailor |  CVS   | -----> | master | darcs | working |
34  |   CVS    | <----- | darcs  | <----- | darcs  | <---- |  darcs  |
35  |          |        |  sync  | tailor |        |       |         |
36  +----------+        +--------+        +--------+       +---------+
37               (cron)            (cron)
38
39
40.. [#] ArX, Monotone, Codeville, Mercurial and Baazar-NG systems may be
41       used only as the `target` backend, since the `source` support
42       isn't coded yet. Contributions on these backends will be very
43       appreciated, since I do not use them enough to figure out the
44       best way to get pending changes and build tailor ChangeSets out
45       of them.
46
47.. _subversion: http://subversion.tigris.org/
48.. _darcs: http://www.darcs.net/
49.. _codeville: http://www.codeville.org/
50.. _baazar-ng: http://www.bazaar-ng.org/
51.. _mercurial: http://www.selenic.com/mercurial/
52.. _arx: http://www.nongnu.org/arx/
53
54
55Installation
56============
57
58tailor is written in Python, and thus Python must be installed on
59your system to use it.  It has been successfully used with Python 2.3
60and 2.4.
61
62Since it relies on external tools to do the real work such as `cvs`,
63`darcs` and `svn`, they need to be installed as well, although only
64those you will actually use.
65
66Make tailor executable::
67
68 $ chmod +x tailor
69
70You can either run tailor where it is currently located, or move it
71along with the vcpx directory to a location in your PATH.
72
73There's even a standard setup.py that you may use to install the
74script using Python conventional distutils.
75
76
77Examples
78========
79
801. Bootstrap a new tailored project, starting at upstream revision 10::
81
82    $ tailor -b -s svn -R http://svn.server/path/to/svnrepo \
83      --module /Product/trunk -r 10 --subdir Product ~/darcs/MyProduct
84
852. Bootstrap a new product, fetching its whole CVS repository and
86   storing under SVN
87
88   a. First create a SVN repository and extract a working copy out of
89      it. This is needed also when using a CVS or a Monotone target::
90
91       $ cd $HOME
92       $ svnadmin create --fs-type fsfs svn_repo
93       $ svn co file://$HOME/svn_repo svnwc
94
95   b. Then run tailor once to set up the repository::
96
97       $ cd $HOME/svnwc
98       $ tailor --source-kind cvs --target-kind svn --bootstrap \
99                --repository :pserver:cvs.zope.org:/cvs-repository \
100                --module CMF/CMFCore --revision INITIAL cmfcore
101
102   c. Finally run it again without --bootstrap to bring the repository
103      in sync with latest CVS version::
104
105      $ tailor -D -v $HOME/svnwc/cmfcore
106
107   .. note:: In the step a) above, you may want to install an
108             appropriate hook in the repository to enable the
109             propset command to operate on unversioned properties,
110             as described in the `svn manual`__. Then you can
111             specify '--use-svn-propset' option, and tailor will
112             put the original author and timestamp in the proper
113             svn metadata instead of appending them to the changelog.
114
115             Other than the annoying repository manual intervention,
116             this thread__ and this other__ explain why using
117             ``-r{DATE}`` may produce strange results with this setup.
118
119__ http://svn.haxx.se/users/archive-2005-07/0605.shtml
120__ http://svn.haxx.se/users/archive-2005-03/0596.shtml
121
122
1233. Showing each command bootstrap a new DARCS repos in
124   "~/darcs/cmftopic" under which the upstream module will be
125   extracted as "CMFTopic" (ie, the last component of the module
126   name)::
127
128    $ tailor -D -b -R :pserver:anonymous@cvs.zope.org:/cvs-repository/ \
129                -m CMF/CMFTopic ~/darcs/cmftopic
130             
1314. Merge upstream changes since last update/bootstrap::
132
133    $ tailor ~/svnwc/MyProduct
134
1355. Migrate a whole SVN repository, starting from the beginning::
136
137    $ tailor -b -s svn -R svn+ssh://caia/tmp/svn/repo --module / \
138      --subdir testsvn --revision 1 testdir
139
140   .. warning:: When using --revision with a SVN source repository, be
141                sure that the path your are tracking was there at that
142                revision, otherwise svn will exit with an error.
143
1446. Bootstrap from a CVS branch, starting from a given point in time::
145
146    $ tailor -b -s cvs -R :pserver:anonymous@server.org:/cvsroot/ \
147                --revision 'unstable-branch 2001-12-25 23:26:48 UTC' \
148                --module something new-darcs-repository
149
1507. Bootstrap from a CVS branch, starting from the beginning of time::
151
152    $ tailor.py -b -s cvs -R :pserver:anonymous@server.org:/cvsroot/ \
153                --revision 'unstable-branch INITIAL' \
154                --module something new-darcs-repository
155
1568. Bootstrap a new SVN repository with tailor's master one. This
157   demonstrate the new --target-repository feature::
158
159    $ tailor -D -v -b -R http://nautilus.homeip.net/~lele/projects/tailor \
160            -s darcs -t svn --target-repository file:///tmp/svnrepo \
161            --target-module / /tmp/wc
162    $ svn info file:///tmp/svnrepo [Status 1]
163    $ svnadmin create --fs-type fsfs /tmp/svnrepo [Ok]
164    $ svn co --quiet file:///tmp/svnrepo/ /tmp/wc [Ok]
165    /tmp/wc $ darcs get --partial --verbose http://.../tailor tailor [Ok]
166    /tmp/wc/tailor $ darcs changes --last 1 --xml-output [Ok]
167    /tmp/wc $ svn add --quiet --no-auto-props --non-recursive tailor [Ok]
168    ...
169
1709. Given the configuration file shown below in `Config file format`_,
171   the following command::
172
173    $ tailor --configfile example.tailor --bootstrap
174
175   is equivalent to this one::
176
177    $ tailor --configfile example.tailor --bootstrap tailor
178
179   in that they bootstrap respectively the default project(s) or
180   the ones specified on the command line (and in this case there
181   is just a single default project, tailor).
182
183   This one instead::
184
185    $ tailor --configfile example.tailor tailor tailor-reverse
186
187   executes an update on both projects.
188
189
190Resolving conflicts
191===================
192
193Should one of the replayed changes generate any conflict, tailor
194will prompt the user to correct them. This is done after the upstream
195patch has been applied and before the final commit on the target
196system, so that manually tweaking the conflict can produce a clean
197patch.
198
199
200Shortcomings
201============
202
203Tailor currently suffers of the following reported problems:
204
205a) It does not handle "empty" CVS checkouts, in other words you cannot
206   bootstrap a project that has nothing in its CVS upstream
207   repository, or from a point in time where this condition was true.
208
209b) It's completely unsupported under Windows, evenif it now uses
210   2.4's subprocess_ that seems able to hide Windows crazyness...
211
212c) Monotone, Codeville and Baazar-NG are (currently) only supported as
213   *target*
214
215d) Specifying ``--subdir .`` may not work, in particular when dealing
216   with remote CVS repositories (it does when the CVS repository is
217   on local machine).
218   
219This list will always be incomplete, but I'll do my best to keep it
220short :-)
221
222.. _subprocess: http://www.lysator.liu.se/~astrand/popen5/
223
224
225Config file format
226==================
227
228When your project is composed by multiple upstream modules, it is
229easier to collect such information in a single file. This is done by
230specifying the `--configfile` option with a file name as argument. In
231this case, tailor will read the above information from a
232standard Python ConfigParser file.
233
234For example::
235
236    [DEFAULT]
237    verbose = Yes
238    target-module = None
239    projects = tailor
240
241    [tailor]
242    root = /tmp/n9
243    source = darcs:tailor
244    target = svn:tailor
245    refill-changelogs = Yes
246    state-file = tailor.state
247
248    [tailor-reverse]
249    root = /tmp/n9
250    source = svn:tailor
251    target = darcs:tailor
252    refill-changelogs = Yes
253    state-file = reverse.state
254   
255    [svn:tailor]
256    repository = file:///tmp/testtai
257    module = /project1
258
259    [darcs:tailor]
260    repository = /home/lele/WiP/cvsync
261
262.. hint:: If you execute the examples above with ``--verbose --debug``
263          **and without** ``--configfile``, tailor will write a
264          template config filled with the values specified by the
265          other options. You can redirect
266
267
268Using a Python script as configuration file
269-------------------------------------------
270
271Instead of executing ``tailor --configfile project.tailor.conf``
272you can prepend the following signature to the config itself::
273
274  #!/usr/bin/env /path/to/tailor
275
276Giving execute mode to it will permit the launch of the tailor
277process by running the config script directly::
278
279  $ ./project.tailor.conf
280
281When a config file is signed in this way [#]_, either you pass it as
282argument to ``--configfile`` or executed as above, tailor will
283actually execute it as a full fledged Python script, that may define
284functions that alter the behaviour of tailor itself.
285
286A common usage of this functionality is to define so called `hooks`,
287sequences of functions that are executed at particular points in
288the tailorization process.
289
290For example::
291
292    #!/usr/bin/env /home/lele/WiP/tailor/tailor
293    """
294    [project]
295    source = svn:repository
296    target = darcs:repository
297    before-commit = transform_crlf_to_lf
298    ...
299    """
300
301    def transform_crlf_to_lf(context, changeset):
302        for e in changeset.entries:
303            ....
304
305.. [#] Tailor does actually read just the first two bytes from the
306       file, and compare them with "#!", so you are free to choose
307       whatever syntax works in your environment.
308
309
310State file
311----------
312
313The state file stores two things: the last upstream revision that
314has been applied to the tree, and a sequence of pending (not yet
315applied) changesets, that may be empty. In the latter case, tailor
316will fetch latest changes from the upstream repository.
317
318Interactive sessions
319--------------------
320
321Tailor offers an alternative way of driving its activity by using an
322interactive session, bringing the configuration more similar to a
323script.
324
325Although this is still a work-in-progress, it's quickly becoming my
326preferred usage, as its functionality cover the underlying tailor
327features.
328
329For example, this is the script I'm using to test it::
330
331    cd /tmp
332    state_file tailor.state
333    source_kind darcs
334    target_kind svn
335    source_repository /home/lele/WiP/cvsync
336    sub_directory cvsync
337    refill_changelogs no
338    patch_name_format [%(module)s] Changeset %(revision)s by %(author)s
339
340that, as you can see, specifies the context needed by tailor to do its
341work. With the following command line::
342
343    $ tailor --verbose --interactive tailor.cmds
344    Welcome to the Tailor interactive session: you can issue several commands
345    with the usual `readline` facilities. With "help" you'll get a list of
346    available commands.
347
348    Current directory: /tmp
349    Current state file: /tmp/tailor.state
350    Current source kind: darcs
351    Current target kind: svn
352    Current source repository: /home/lele/WiP/cvsync
353    Sub directory: cvsync
354    Refill changelogs: False
355    Patch name format: [%(module)s] Changeset %(revision)s by %(author)s
356    tailor $ help
357   
358    Documented commands (type help <topic>):
359    ========================================
360    EOF                print_executed_commands  state_file
361    bootstrap          refill_changelogs        sub_directory
362    cd                 remove_first_log_line    target_kind
363    current_directory  save                     target_module
364    exit               source_kind              target_repository
365    logfile            source_module
366    patch_name_format  source_repository
367
368    Undocumented commands:
369    ======================
370    help
371
372    tailor $ help bootstrap
373   
374        Usage: bootstrap [revision]
375
376        Checkout the initial upstream revision, by default HEAD (or
377        specified by argument), then import the subtree into the
378        target repository.
379
380As another example, consider the following commands::
381
382    cd /tmp/wc
383    state_file tailor.state
384    source_kind cvs
385    target_kind darcs
386    source_repository :pserver:anonymous@cvs.sourceforge.net:/cvsroot/buildbot
387    source_module buildbot
388    refill_changelogs false
389    patch_name_format %(firstlogline)s
390    print_executed_commands true
391    bootstrap 2004/01/01 20:05:24
392    update ask
393
394Assuming ``/tmp/wc`` exists, executing them will first bootstrap a new
395darcs repository with a snapshot at the given date of the upstream
396sources, then will proceed with the update, asking confirmation about
397any single changeset::
398
399    ...
400    Collected 586 upstream changesets
401    Changeset 2004-01-07 00:42:07 by warner:
402    * buildbot/changes/mail.py (parseFreshCVSMail): ....
403    * test/test_mailparse.py (Test1.testMsg9): test for same
404
405    Apply [Y/n/v/h/q]? h
406    y: yes, apply it and keep going
407    n: no, skip the current changeset
408    v: view more detailed information
409    q: do not apply the current changeset and stop iterating
410
411    Apply [Y/n/v/h/q]? v
412    Revision: 2004-01-07 00:42:07 by warner
413    Date: 2004-01-07 00:42:07
414    Author: warner
415    Modified: ChangeLog,buildbot/changes/mail.py,test/test_mailparse.py
416    Added: test/mail/msg9
417    Log: * buildbot/changes/mail.py (parseFreshCVSMail): ...
418    * test/test_mailparse.py (Test1.testMsg9): test for same
419   
420    Apply [Y/n/v/h/q]?
421
422       
423Further help
424============
425
426See the output of ``tailor -h`` for some further tips.  There's
427also a `wiki page`_ that may give you some other hints.  The
428development of Tailor is mainly driven by user requests at this point,
429and the preferred comunication media is the dedicated `mailing list`_
430[#]_.
431
432.. _wiki page:
433   http://www.darcs.net/DarcsWiki/Tailor
434
435.. _mailing list:
436   http://lists.zooko.com/mailman/listinfo/tailor
437   
438I will be more than happy to answer any doubt, question or suggestion
439you may have on it. I'm usually hanging as "lelit" on the IRC channel
440devoted to darcs on the `freenode.net` network. Do not hesitate to
441contact me either by email or chatting there.
442
443.. [#] I wish to say a big `Thank you` to `Zooko <zooko@zooko.com>`_,
444       for hosting the ML and for supporting Tailor in several ways,
445       from suggestions to bug reporting and fixing.
446
447
448Author
449======
450
451Lele Gaifax <lele@nautilus.homeip.net>
452
453
454Monotone support
455----------------
456
457Monotone_ support was kindly contributed by `Markus Schiltknecht
458<markus@bluegap.ch>`_ and further developed by `rghetta
459<birrachiara@tin.it>`_.  Since I'm not currently using monotone (so
460little time, so many VCSs...) I'm not in position to test it out
461properly, but I'll do my best to keep it in sync, maybe with your
462support :-)
463
464.. _monotone: http://www.venge.net/monotone/
465
466
467License
468=======
469
470Tailor is distribuited under the `GNU General Public License`__.
471
472__ http://www.fsf.org/licensing/licenses/gpl.html
473
474
475About this document
476===================
477
478This document and most of the internal documention use the
479reStructuredText format so that it can be easily converted into other
480formats, such as HTML.  For more information about this, please see:
481
482  http://docutils.sourceforge.net/rst.html
483
484
485.. vim:ft=rest
486.. Local Variables:
487.. mode: rst
488.. End:
Note: See TracBrowser for help on using the repository browser.