| 1 | Darcs backend for Trac |
|---|
| 2 | ====================== |
|---|
| 3 | |
|---|
| 4 | This package implements a darcs backend for trac 0.11. |
|---|
| 5 | |
|---|
| 6 | To use the module you can either install it or make an egg and copy |
|---|
| 7 | it in the right place. |
|---|
| 8 | |
|---|
| 9 | Installation |
|---|
| 10 | ------------ |
|---|
| 11 | |
|---|
| 12 | You can install the module the usual way:: |
|---|
| 13 | |
|---|
| 14 | $ python setup.py install [--prefix /usr/local] |
|---|
| 15 | |
|---|
| 16 | Otherwise you can make an egg:: |
|---|
| 17 | |
|---|
| 18 | $ python setup.py bdist_egg |
|---|
| 19 | |
|---|
| 20 | and either install it globally with:: |
|---|
| 21 | |
|---|
| 22 | $ easy_install dist/TracDarcs-someversion.egg |
|---|
| 23 | |
|---|
| 24 | or manually copy the egg from the "dist" subdir into the environment's |
|---|
| 25 | "plugins" subdirectory |
|---|
| 26 | |
|---|
| 27 | In general, follow the directions in TracPlugins. |
|---|
| 28 | |
|---|
| 29 | Internals |
|---|
| 30 | --------- |
|---|
| 31 | |
|---|
| 32 | The entire darcs change history is imported into the database, using |
|---|
| 33 | the output of ``darcs changes --xml-output --summary --reverse``. |
|---|
| 34 | |
|---|
| 35 | A check for newer patches is performed everytime the DarcsRepository |
|---|
| 36 | object is created, and any new patches are immediately imported into |
|---|
| 37 | the database. |
|---|
| 38 | |
|---|
| 39 | After that the darcs repository is used only for fetching the contents |
|---|
| 40 | of a file: with darcs 2.x we use ``darcs query contents``, while with |
|---|
| 41 | darcs 1.x we have to do ugly tricks; at the extreme, ``darcs |
|---|
| 42 | annotate`` output is massaged by ann2ascii.py to fetch the contents of |
|---|
| 43 | a file at any given point in time. |
|---|
| 44 | |
|---|
| 45 | Each changeset is assigned a revision number according to their order |
|---|
| 46 | in the output of ``darcs changes --xml-output --summary --reverse``. |
|---|
| 47 | The first patch gets a revision number of 1, and second revision |
|---|
| 48 | number 2 etc... |
|---|
| 49 | |
|---|
| 50 | This assumes that the patches in a darcs repository **NEVER** get |
|---|
| 51 | reordered or deleted. This condition is satisfied as long as commands |
|---|
| 52 | such as ``darcs unpull`` or ``darcs optimize`` are not performed. |
|---|
| 53 | |
|---|
| 54 | Cache |
|---|
| 55 | ~~~~~ |
|---|
| 56 | |
|---|
| 57 | For performance reasons, the backend creates and maintains a few other |
|---|
| 58 | tables, where it keeps darcs specific information. The following |
|---|
| 59 | tables are automatically created at `upgrade` time and populated by |
|---|
| 60 | `sync` (see components.py). |
|---|
| 61 | |
|---|
| 62 | darcs_changesets |
|---|
| 63 | ++++++++++++++++ |
|---|
| 64 | |
|---|
| 65 | Each 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 | |
|---|
| 74 | repo_id |
|---|
| 75 | repository containing this changeset |
|---|
| 76 | |
|---|
| 77 | rev |
|---|
| 78 | the revision number assigned |
|---|
| 79 | |
|---|
| 80 | hash |
|---|
| 81 | the unique patch identifier assigned by darcs |
|---|
| 82 | |
|---|
| 83 | name |
|---|
| 84 | the name of the darcs patch |
|---|
| 85 | |
|---|
| 86 | darcs_nodes |
|---|
| 87 | +++++++++++ |
|---|
| 88 | |
|---|
| 89 | Each row represents a single node: a node is either a file or a |
|---|
| 90 | directory 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 | |
|---|
| 105 | node_type |
|---|
| 106 | is one of (dbutil.NODE_FILE_TYPE, dbutil.NODE_DIR_TYPE) |
|---|
| 107 | |
|---|
| 108 | add_rev |
|---|
| 109 | is the revision that added this node |
|---|
| 110 | |
|---|
| 111 | remove_rev |
|---|
| 112 | is the revision that removed this node (possibly NULL) |
|---|
| 113 | |
|---|
| 114 | darcs_node_changes |
|---|
| 115 | ++++++++++++++++++ |
|---|
| 116 | |
|---|
| 117 | Each row represents a node change for a particular revision. Only one |
|---|
| 118 | entry can exist for a node in each revision. Of course, if there are |
|---|
| 119 | no 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 | |
|---|
| 133 | the_change |
|---|
| 134 | one of following (defined in dbutil.py): CHANGE_ADDED, |
|---|
| 135 | CHANGE_REMOVED, CHANGE_MOVED, CHANGE_EDITED, CHANGE_MOVED_EDITED |
|---|
| 136 | |
|---|
| 137 | parent_id |
|---|
| 138 | the node id for the node's parent directory |
|---|
| 139 | |
|---|
| 140 | path |
|---|
| 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 | |
|---|
| 144 | darcs_cache |
|---|
| 145 | +++++++++++ |
|---|
| 146 | |
|---|
| 147 | A cache of file contents: as soon as the content of any file at any |
|---|
| 148 | particular revision is requested for the first time, it's computed and |
|---|
| 149 | stored here, so succeeding requests won't require executing darcs at |
|---|
| 150 | all. |
|---|
| 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 | |
|---|
| 166 | Some sample queries |
|---|
| 167 | +++++++++++++++++++ |
|---|
| 168 | |
|---|
| 169 | Get 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 | |
|---|
| 182 | Get 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 | |
|---|
| 194 | Get 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 | |
|---|
| 209 | Get 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 | |
|---|
| 218 | Get 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' |
|---|