source: tracdarcs/README @ 133

Revision 133, 6.0 KB checked in by lele@…, 4 years ago (diff)

Aligned README with current schema

Line 
1Darcs backend for Trac
2======================
3
4This package implements a darcs backend for trac 0.11.
5
6To use the module you can either install it or make an egg and copy
7it in the right place.
8
9Installation
10------------
11
12You can install the module the usual way::
13
14  $ python setup.py install [--prefix /usr/local]
15
16Otherwise you can make an egg::
17
18  $ python setup.py bdist_egg
19
20and either install it globally with::
21
22  $ easy_install dist/TracDarcs-someversion.egg
23
24or manually copy the egg from the "dist" subdir into the environment's
25"plugins" subdirectory
26
27In general, follow the directions in TracPlugins.
28
29Internals
30---------
31
32The entire darcs change history is imported into the database, using
33the output of ``darcs changes --xml-output --summary --reverse``.
34
35A check for newer patches is performed everytime the DarcsRepository
36object is created, and any new patches are immediately imported into
37the database.
38
39After that the darcs repository is used only for fetching the contents
40of a file: with darcs 2.x we use ``darcs query contents``, while with
41darcs 1.x we have to do ugly tricks; at the extreme, ``darcs
42annotate`` output is massaged by ann2ascii.py to fetch the contents of
43a file at any given point in time.
44
45Each changeset is assigned a revision number according to their order
46in the output of ``darcs changes --xml-output --summary --reverse``.
47The first patch gets a revision number of 1, and second revision
48number 2 etc...
49
50This assumes that the patches in a darcs repository **NEVER** get
51reordered or deleted. This condition is satisfied as long as commands
52such as ``darcs unpull`` or ``darcs optimize`` are not performed.
53
54Cache
55~~~~~
56
57For performance reasons, the backend creates and maintains a few other
58tables, where it keeps darcs specific information. The following
59tables are automatically created at `upgrade` time and populated by
60`sync` (see components.py).
61
62darcs_changesets
63++++++++++++++++
64
65Each row represents a darcs changeset::
66
67    create table darcs_changesets (
68        repo_id text,
69        rev integer,
70        hash text,
71        name text,
72        primary key (repo_id, rev));
73
74repo_id
75  repository containing this changeset
76
77rev
78  the revision number assigned
79
80hash
81  the unique patch identifier assigned by darcs
82
83name
84  the name of the darcs patch
85
86darcs_nodes
87+++++++++++
88
89Each row represents a single node: a node is either a file or a
90directory which has its history stored in the repository.
91
92.. note:: a node doesn't have a particular name or content but, for a
93          given revision, its name and content will be well defined.
94
95::
96
97    create table darcs_nodes (
98        repo_id text,
99        node_id integer,
100        node_type text,
101        add_rev integer,
102        remove_rev integer,
103        primary key (repo_id, node_id) );
104
105node_type
106  is one of (dbutil.NODE_FILE_TYPE, dbutil.NODE_DIR_TYPE)
107
108add_rev
109  is the revision that added this node
110
111remove_rev
112  is the revision that removed this node (possibly NULL)
113
114darcs_node_changes
115++++++++++++++++++
116
117Each row represents a node change for a particular revision. Only one
118entry can exist for a node in each revision. Of course, if there are
119no changes to the node then no entries will be present! :)
120
121::
122
123    create table darcs_node_changes (
124        repo_id text,
125        node_id integer,
126        rev integer,
127        path text,
128        parent_id integer,
129        the_change text,
130        primary key (repo_id, node_id,rev) );
131
132
133the_change
134  one of following (defined in dbutil.py): CHANGE_ADDED,
135  CHANGE_REMOVED, CHANGE_MOVED, CHANGE_EDITED, CHANGE_MOVED_EDITED
136
137parent_id
138  the node id for the node's parent directory
139
140path
141  the path of the node at the end of revision 'rev': when change is
142  CHANGE_REMOVED then 'path' is the previous path.
143
144darcs_cache
145+++++++++++
146
147A cache of file contents: as soon as the content of any file at any
148particular revision is requested for the first time, it's computed and
149stored here, so succeeding requests won't require executing darcs at
150all.
151
152.. warning:: this may quickly grow in size! OTOH, you can just delete
153             all the rows at any time, the content will be recomputed
154             when reasked.
155
156::
157
158    create table darcs_cache (
159        repo_id text,
160        node_id integer,
161        rev integer,
162        content blob,
163        size integer,
164        primary key (repo_id, node_id,rev) );
165
166Some sample queries
167+++++++++++++++++++
168
169Get all existing nodes as of revision r
170```````````````````````````````````````
171
172::
173
174    select dnc.node_id as node_id, max(dnc.rev) as rev
175    from darcs_node_changes as dnc, darcs_nodes as dn
176    where dnc.node_id = dn.node_id
177      and dnc.rev <= r
178      and dnc.repo_id = dn.repo_id and dnc.repo_id = 'somerepo'
179      and (dn.remove_rev is null or dn.remove_rev > r)
180    group by dnc.node_id
181
182Get all latest nodes
183````````````````````
184
185::
186
187    select dnc.node_id as node_id, max(dnc.rev) as rev
188    from darcs_node_changes as dnc, darcs_nodes as dn
189    where dnc.node_id = dn.node_id
190      and dn.remove_rev is null
191      and dnc.repo_id = dn.repo_id and dnc.repo_id = 'somerepo'
192    group by dnc.node_id
193
194Get node_id of /some/path p, as of revision r
195`````````````````````````````````````````````
196
197.. XXX: here "node_rev(r)" means a subquery, see
198..      ``_nodeid_rev_for_revision()`` in dbutil.py
199
200::
201
202    select dnc.node_id as node_id
203    from darcs_node_changes as dnc, (node_rev(r)) as nr
204    where dnc.node_id = nr.node_id
205      and dnc.rev = nr.rev
206      and dnc.repo_id = nr.repo_id and dnc.repo_id = 'somerepo'
207      and dnc.path = p
208
209Get history of node_id nid, till revision r
210```````````````````````````````````````````
211
212::
213
214    select * from darcs_node_changes as dnc
215    where dnc.node_id = nid and dnc.rev <= r
216      and dnc.repo_id = 'somerepo'
217
218Get children of node_id nid, as of revision r
219`````````````````````````````````````````````
220
221::
222
223    select dnc.node_id as node_id
224    from darcs_node_changes as dnc, (node_rev(r)) as nr
225    where dnc.node_id = nr.node_id
226      and dnc.rev = nr.rev
227      and dnc.parent_id = nid
228      and dnc.repo_id = nr.repo_id and dnc.repo_id = 'somerepo'
Note: See TracBrowser for help on using the repository browser.