]> git.uio.no Git - usit-rt.git/blame - docs/hacking.pod
Master to 4.2.8
[usit-rt.git] / docs / hacking.pod
CommitLineData
84fb5b46
MKG
1=head1 Development of RT
2
3RT's source code is stored in a C<git> repository. If you are not
4familiar with git, see L</git quickstart>, below, for a short tutorial
5which will give you enough information to get started submitting patches
6to RT.
7
8The rest of this document details conventions and tips surrounding the
9organization of RT's version control, source code conventions, and how
10to submit patches.
11
12
13
14=head1 Organization of rt.git
15
16The RT source repository is available via git from GitHub; you can
17browse it at L<http://github.com/bestpractical/rt/> or obtain a local
18copy via:
19
20 git clone git://github.com/bestpractical/rt.git
21
22The bleeding-edge development happens in the C<master> branch. When a
23major release is anticipated, a "trunk" branch will be branched from
24this -- for example, C<4.0-trunk>. This will allow the trunk to
25stabilize while feature development continues on C<master>.
26Additionally, as a release is impending for a particular series, a
27release engineering branch will be created, named, for example
28C<4.0.0-releng>.
29
30New feature development should always be based off of the C<master>
31branch. Branches to fix bugs should be based off of whichever trunk the
32bug was first found in. If you found the bug in your RT 4.0.0 install,
33you'd branch from 4.0-trunk.
34
35Branches should be named based on the trunk they are branched
36from -- which is to say, the earliest branch they might be merged into.
37For example, a bugfix branched from C<4.0-trunk> might be named
38C<4.0/fail-taint-mode-early>. A feature branched from C<master> when
39there exists a C<4.0-trunk> but no C<4.2-trunk> might be named
40C<4.2/rename-LogToScreen>. For consistency, branches should use dashes,
403d7b0b
MKG
41not underscores, to separate words. Branches which are destined for
424.2, but which are branched from 4.0 (to provide for easy extraction as
43a 4.0 extension) should be named 4.2-on-4.0/branch-name.
84fb5b46
MKG
44
45Branches should be reviewed by another developer before being merged.
46Reviewers should make sure that the branch accomplishes what it claims
47to, and does not introduce any unwanted behavior in doing so. Commit
48messages explain the B<why> as much as the B<what> of each commit, and
49not include extranous changes.
50
51
52=head1 Code conventions
53
54The RT codebase is more than ten years old; as such, there are sections
55which do not (yet) conform to the guidelines below. Please attempt to
56follow the guidelines, even if the code surrounding your changes does
57not yet.
58
59RT also includes a F<.perltidyrc> in its top-level which encodes many of
60the conventions.
61
62=over
63
64=item Indentation
65
66Each level of indentation should be four spaces; tabs should never be
67used for indentation.
68
69=back
70
71=head1 Internationalization
72
73RT has been translated into several dozen languages. We use Launchpad
74( https://translations.launchpad.net/rt ) to crowdsource our
75translations into C<po> files. RT uses L<Locale::Maketext> to
76localize its user interface.
77
78Your first stop on this magical journey of internationalization
79is L<Locale::Maketext::TPJ13>, which explains the whys of
80L<Locale::Maketext>. RT uses most of the features developed in that
81article.
82
83Strings that are displayed to users should be passed through the
84C<loc("...")> function or the C<< <&|/l&>...</&> >> Mason template.
85C<loc> and C</l> both take parameters, which are used in place of
86string interpolation (much like C<sprintf>). It's acceptable to use
87HTML in C</l> calls, especially for bold and emphasis. However, you
88should limit the amount of HTML that translators must keep exactly
89correct, which means avoid including tags that wrap the entire
90translatable string, especially C<< <p> >>.
91
92 <p><&|/l, $button &>Do <em>not</em> click [_1]</&></p> # ok
93
94 <&|/l, $button &><p>Do <em>not</em> click [_1]</p></&> # not ok
95
96In a few places in RT we also pass HTML as parameters to C<loc()>
97so that translators do not have to reproduce it exactly, and we can
98also change it more freely. For example:
99
100 <&|/l,
101 '<a href="http://www.gnu.org/licenses/gpl-2.0.html">',
102 '</a>',
103 &>Distributed under [_1]version 2 of the GNU GPL[_2].</&>
104
105F<devel/tools/extract-message-catalog> looks for C<loc("...")> and
106C<< <&|/l&>...</&> >> in our source code to pick out translatable
107strings, clean them up, and put them into F<share/po> files. We use
108our C<.po> files not only to populate L<Locale::Maketext>'s lexicons,
109but also to sync new translatable strings and translations with
110Launchpad. This Launchpad sync is typically done early during the
111freeze of RC releases to give our volunteer translators time to
112translate all the new strings which, because of the RC freeze, won't
113continue changing.
114
115Because C<loc()> and C</l> are used to generate strings for human
116eyes, they generally must be used "close to the browser". These are
117directly in Mason templates, or in functions that return text that
118will be passed through Mason. However, in many places in RT we have
119hardcoded strings which need translations. For example, the C<$RIGHTS>
120hash in F<lib/RT/Queue.pm> maps rights' names (which must be
121translatable) to their descriptions (which also must be translatable).
122However, when we're declaring such structures, we do not want to
123translate them straight away. RT uses English internally, including
124in its web forms, so we do not want to localize rights' names except
125for display, otherwise things might break weirdly when you check
126if a user has the "Superusuario" right. Furthermore, when we're
127declaring such data structures at compile time, there is no current
128user to select which language to use for localization. Thus, we
129cannot call C<loc()> when declaring C<$RIGHTS> and other similar
130places.
131
132For this reason, F<devel/tools/extract-message-catalog> lets you
133denote translatable strings with comments. That's what the C<#loc_pair>
134comments in the C<$RIGHTS> hash in F<lib/RT/Queue.pm> indicate.
135Since we have those comments, our toolchain will put the rights'
136names and descriptions into F<share/po> files, which enables
137translation by our lovely volunteers. Later on, when RT displays
138information about rights in the web UI, we'll pass the right's name
139through C<loc>, and L<Locale::Maketext> will then be able to find
140our "Superusuario". So although we never used a literal
141C<loc("SuperUser")>, we still get its effects thanks to the
142C<#loc_pair> comments and using C<loc($RightName)>.
143
144C<#loc_pair> is used for declaring that the both the key and value
145of a particular C<< key => value >> pair are translatable. There
146are other markers that you can use.
147
148C<#loc> is used for declaring that a particular string is translatable.
149Its parsing is pretty strict so you can use it to declare that only
150the value of a particular C<< key => value >> pair is translatable.
151
152C<#loc_left_pair> is used for declaring that the I<key> of a
153particular C<< key => value >> pair is translatable. This is of
154very limited usefulness.
155
c33a4027
MKG
156C<#loc_right_pair> does NOT exist. C<#loc> works in such cases since its
157parser does not extend beyond the string at the end of a line. However,
158if the string is I<not> at the end of the line, C<#loc{word}> declares
159that the value associated with the key I<word> (earlier on the same
160line) is to be loc'd. This is useful for inline hashes:
161
162 # Note the string "baz" is to be loc'd
163 foo => { bar => "baz", troz => "zort" }, # loc{bar}
84fb5b46
MKG
164
165=head1 Development tips
166
167=head2 Setting up a development environment
168
169=head2 Test suite
170
171RT also comes with a fairly complete test suite. To run it, you will
172need to set environment variables to a database user and password which
173can create and drop databases:
174
175 export RT_DBA_USER=root
176 export RT_DBA_PASSWORD=
177
178You'll need to configure RT and make sure you have all the dependencies
179before running tests. To do this in place without installing:
180
af59614d 181 ./configure.ac --with-my-user-group --enable-layout=inplace --enable-developer
84fb5b46
MKG
182 make testdeps
183 make fixdeps
184
185Adjust the relevant database options as necessary if you want to test on
186Postgres, Oracle, or SQLite. The default is MySQL.
187
188To run the test suite:
189
190 make test
191
192If you have multiple processors, you can run the test suite in parallel,
193which will be significantly faster:
194
195 make test-parallel
196
b5747ff2
MKG
197The C<*-trunk> and C<master> branches are expected to always be passing
198all tests. While it is acceptable to break tests in an intermediate
199commit, a branch which does not pass tests will not be merged. Ideally,
200commits which fix a bug should also include a testcase which fails
201before the fix and succeeds after.
84fb5b46
MKG
202
203
204
205=head1 git quickstart
206
207=over
208
209=item 1.
210
211You will first need to obtain a copy of git; this is accomplished via
212C<sudo yum install git> in RedHat and derivatives, or C<sudo apt-get
213install git> for Debian or Ubuntu.
214
215=item 2.
216
217Next, obtain a copy of the RT source from git:
218
219 git clone git://github.com/bestpractical/rt.git
220 cd rt
221
222=item 3.
223
224Configure git to know your name and email address; git uses these when
225it makes commits.
226
227 git config user.email your.email@example.com
228 git config user.name Examp L. Name
229
230=item 4.
231
232Switch to the appropriate point to base your work on; this is generally
233C<origin/> followed by the major version, followed by C<-trunk>. For
234example, if your bug was observed in version 3.8.9, you would choose
235C<origin/3.8-trunk>; if it was in 4.0.0, you would choose
236C<origin/4.0-trunk>. New features should be based on C<origin/master>.
237
238 git checkout --track origin/4.0-trunk
239
240=item 5.
241
242Give your branch a name based on what you are attempting to accomplish.
243We suggest that branch names be lower-case and separate words with
244dashes, but this branch name is purely for your own reference.
245
246 git branch -m gnupg-encryption
247
248=item 6.
249
250Edit the source tree to make your changes. A few commands you may find
251useful in doing so are listed below.
252
253To see what files you have changed:
254
255 git status
256
257To see a line-by-line list of changes:
258
259 git diff
260
261To revert a file to the original version:
262
263 git checkout path/to/file
264
265To revert only individual parts of a file:
266
267 git checkout -p path/to/file
268
269See L</Development tips> for more tips for working with the RT codebase.
270
271=item 7.
272
273Check that you have no extraneous changes using C<git diff>, then commit
274your changes:
275
276 git commit -a
277
278You will be prompted to type your commit message. The first line should
279be a short (E<lt> 80 character) summary of the changes, followed by a
280blank line, followed by a longer description, if necessary. The commit
281message should not simply restate the diff of which lines were added and
282subtracted, but should rather explain B<what> those changes accomplish,
283and B<why> they are desired.
284
285If your changes are easily split into multiple components, you may wish
286to split your changes into more than one commit; simply return to step 6
287and repeat the with the next related change. If your changes are B<not>
288related to each other, you should submit them separately; finish step 9,
289then start over from step 4.
290
291=item 8.
292
293Save your commits to patch files:
294
295 git format-patch @{u}
296
297This will print out the names of the files as it creates them.
298
299=item 9.
300
301Attach these files to an email using your standard email client, and
302send it to C<rt-devel@bestpractical.com>.
303
304=back
305
306If you have another bug or feature to implement, simply restart the
307process at step 4.
308
309=cut