source: tailor/vcpx/repository/darcs/__init__.py @ 1558

Revision 1558, 4.6 KB checked in by lele@…, 5 years ago (diff)

New option 'split-initial-changeset-level' on darcs target
This let's avoid building a single huge patch at bootstrap, and
instead having a set of smaller changesets, one per directory, with a
tag to collect them as a whole.

Line 
1# -*- mode: python; coding: utf-8 -*-
2# :Progetto: vcpx -- Darcs details
3# :Creato:   ven 18 giu 2004 14:45:28 CEST
4# :Autore:   Lele Gaifax <lele@nautilus.homeip.net>
5# :Licenza:  GNU General Public License
6#
7
8"""
9This module contains supporting classes for the ``darcs`` versioning system.
10"""
11
12__docformat__ = 'reStructuredText'
13
14import re
15
16from vcpx.repository import Repository
17from vcpx.shwrap import ExternalCommand
18from vcpx.target import TargetInitializationFailure
19
20
21class DarcsRepository(Repository):
22    METADIR = '_darcs'
23
24    def _load(self, project):
25        Repository._load(self, project)
26        cget = project.config.get
27        self.EXECUTABLE = cget(self.name, 'darcs-command', 'darcs')
28        init_options = cget(self.name, 'init-options', '')
29        if init_options:
30            self.init_options = tuple(init_options.split(' '))
31        else:
32            self.init_options = None
33        self.use_look_for_adds = cget(self.name, 'look-for-adds', 'False')
34        self.split_initial_import_level = int(
35            cget(self.name, 'split-initial-changeset-level', '0'))
36        self.replace_badchars = eval(cget(self.name, 'replace-badchars',
37                                          "{"
38                                          "'\xb4': '&#180;',"
39                                          "'\xc1': '&#193;',"
40                                          "'\xc4': '&#196;',"
41                                          "'\xc5': '&#197;',"
42                                          "'\xc9': '&#201;',"
43                                          "'\xcd': '&#205;',"
44                                          "'\xd3': '&#211;',"
45                                          "'\xd5': '&#336;',"
46                                          "'\xd6': '&#214;',"
47                                          "'\xda': '&#218;',"
48                                          "'\xdb': '&#368;',"
49                                          "'\xdc': '&#220;',"
50                                          "'\xdf': '&#223;',"
51                                          "'\xe1': '&#225;',"
52                                          "'\xe5': '&#229;',"
53                                          "'\xe9': '&#233;',"
54                                          "'\xed': '&#237;',"
55                                          "'\xf1': '&#241;',"
56                                          "'\xf3': '&#243;',"
57                                          "'\xf5': '&#337;',"
58                                          "'\xf6': '&#246;',"
59                                          "'\xfa': '&#250;',"
60                                          "'\xfb': '&#369;',"
61                                          "'\xfc': '&#252;',"
62                                          "}"))
63
64    def command(self, *args, **kwargs):
65        if args[0] == 'record' and self.use_look_for_adds:
66            args = args + ('--look-for-adds',)
67        elif args[0] == 'initialize' and self.init_options:
68            args = args + self.init_options
69        return Repository.command(self, *args, **kwargs)
70
71    def create(self):
72        from vcpx.dualwd import IGNORED_METADIRS
73        from os.path import join
74
75        cmd = self.command("initialize")
76        init = ExternalCommand(cwd=self.basedir, command=cmd)
77        init.execute()
78
79        if init.exit_status:
80            raise TargetInitializationFailure(
81                "%s returned status %s" % (str(init), init.exit_status))
82
83        metadir = join(self.basedir, '_darcs')
84        prefsdir = join(metadir, 'prefs')
85        prefsname = join(prefsdir, 'prefs')
86        boringname = join(prefsdir, 'boring')
87
88        boring = open(boringname, 'rU')
89        ignored = boring.read().rstrip().split('\n')
90        boring.close()
91
92        # Augment the boring file, that contains a regexp per line
93        # with all known VCs metadirs to be skipped.
94        ignored.extend(['(^|/)%s($|/)' % re.escape(md)
95                        for md in IGNORED_METADIRS])
96
97        # Eventually omit our own log...
98        logfile = self.projectref().logfile
99        if logfile.startswith(self.basedir):
100            ignored.append('^%s$' %
101                           re.escape(logfile[len(self.basedir)+1:]))
102
103        # ... and state file
104        sfname = self.projectref().state_file.filename
105        if sfname.startswith(self.basedir):
106            sfrelname = sfname[len(self.basedir)+1:]
107            ignored.append('^%s$' % re.escape(sfrelname))
108            ignored.append('^%s$' % re.escape(sfrelname+'.old'))
109            ignored.append('^%s$' % re.escape(sfrelname+'.journal'))
110
111        boring = open(boringname, 'w')
112        boring.write('\n'.join(ignored))
113        boring.write('\n')
114        boring.close()
Note: See TracBrowser for help on using the repository browser.