OSDN Git Service

maint: remove r/hfs/DOC,HISTORY,TODO; add VERSION for new library
[android-x86/external-parted.git] / HACKING
1 Parted Contribution Guidelines
2
3
4 Prerequisites
5 =============
6 You will need the "git" version control tools.
7 On Fedora-based systems, do "yum install git".
8 On Debian-based ones install the "git-core" package.
9 Then run "git --version".  If that says it's older than
10 version 1.4.4, then you'd do well to get a newer version.
11 At worst, just download the latest stable release from
12 http://git.or.cz/ and build from source.
13
14 For details on building the programs in this package, see
15 the file, README-hacking.
16
17
18 Use the latest upstream sources
19 ===============================
20 Base any changes you make on the latest upstream sources.
21 You can get a copy of the latest with this command:
22
23     git clone git://git.debian.org/git/parted/parted.git
24
25 That downloads the entire repository, including revision control history
26 dating back to 1991.  The repository (the part you download, and which
27 resides in parted/.git) currently weighs in at about 2.6MB.  So you
28 don't want to download it more often than necessary.  Once downloaded,
29 you can get incremental updates by running one of these commands from
30 inside your new parted/ directory:
31
32 If you have made *no* changes:
33     git pull
34
35 If you *have* made changes and mistakenly committed them to "master",
36 do the following to put your changes on a private branch, "br", and
37 to restore master to its unmodified (relative-to-upstream) state:
38     git checkout -b br
39     git checkout master
40     git reset --hard origin
41
42 Then "git pull" should work.
43
44
45 *Before* you commit changes
46 ===========================
47
48 In this project, we much prefer patches that automatically record
49 authorship.  That is important not just to give credit where due, but
50 also from a legal standpoint (see below).  To create author-annotated
51 patches with git, you must first tell git who you are.  That information
52 is best recorded in your ~/.gitconfig file.  Edit that file, creating
53 it if needed, and put your name and email address in place of these
54 example values:
55
56 [user]
57   name = Joe X. User
58   email = joe.user@example.com
59
60
61 Your first commit: the quick and dirty way
62 ==========================================
63 First of all, realize that to "commit" a change in git is a purely
64 local operation.  It affects only the local repository (the .git/ dir)
65 in your current parted/ hierarchy.
66
67 To try this out, modify a file or two.  If you create a new file, you'll
68 need to tell git about it with "git add new-file.c".  Commit all changes
69 with "git commit -a".  That prompts you for a log message, which should
70 include a one-line summary, a blank line, and ChangeLog-style entries
71 for all affected files.  More on that below.
72
73 Once your change is committed, you can create a proper patch that includes
74 a log message and authorship information as well as any permissions
75 changes.  Use this command to save that single, most-recent change set:
76
77   git format-patch --stdout -1 > DIFF
78
79 The trouble with this approach is that you've just checked in a change
80 (remember, it's only local) on the "master" branch, and that's where new
81 changes would normally appear when you pull the latest from "upstream".
82 When you "pull" from a remote repository to get the latest, your local
83 changes on "master" may well induce conflicts.   For this reason, you
84 may want to keep "master" free of any local changes, so that you can
85 use it to track unadulterated upstream sources.
86
87 However, if your cloned directory is for a one-shot patch submission and
88 you're going to remove it right afterwards, then this approach is fine.
89 Otherwise, for a more sustainable (and more generally useful, IMHO)
90 process, read on about "topic" branches.
91
92
93 Make your changes on a private "topic" branch
94 =============================================
95 So you checked out parted like this:
96
97   git clone git://git.debian.org/git/parted/parted.git
98
99 Now, cd into the parted/ directory and run:
100
101   git checkout -b my-topic
102
103 That creates the my-topic branch and puts you on it.
104 To see which branch you're on, type "git branch".
105 Right after the clone, you were on "master" (aka the trunk).
106 To get back to the trunk, do this:
107
108   git checkout master
109
110 Note 1:
111     Be careful to run "git pull" only when on the "master" branch,
112     not when on a branch.  With newer versions of git, you can't cause
113     trouble if you forget, so this is a good reason to ensure you're
114     using 1.5.3.1 or newer.
115
116 Note 2:
117     It's best not to try to switch from one branch to another if
118     you have pending (uncommitted) changes.  Sometimes it works,
119     sometimes the checkout will fail, telling you that your local
120     modifications conflict with changes required to switch branches.
121     However, in any case, you will *not* lose your uncommitted changes.
122
123 Anyhow, get back onto your just-created branch:
124
125   git checkout my-topic
126
127 Now, modify some file and commit it:
128
129   git commit some-file.c
130
131 Personally, no matter what package I'm working on, I find it useful to
132 put the ChangeLog entries *only* in the commit log, initially, unless
133 I plan to commit/push right away.  Otherwise, I tend to get unnecessary
134 merge conflicts with each rebase (see below).  In parted, I've gone
135 a step further, and no longer maintain an explicit ChangeLog file in
136 version control.  Instead, in a git working directory, you can view
137 ChangeLog information via "git log".  However, each distribution tarball
138 does include a ChangeLog file that is automatically generated from the
139 git logs.
140
141 So, you've committed a change.  But it's only in your local repository,
142 and only on your "my-topic" branch.  Let's say you wait a day, and
143 then see that someone else changed something and pushed it to the
144 public repository.  Now, you want to update your trunk and "rebase"
145 your changes on the branch so that they are once again relative to the
146 tip of the trunk.  Currently, your branch is attached to the trunk at
147 the next-to-last change set.
148
149 First: update the trunk from the public repo:
150 [you've first made sure that "git diff" produces no output]
151
152   git checkout master
153   git pull
154
155 Now, return to your branch, and "rebase" relative to trunk (master):
156
157   git checkout my-topic
158   git rebase master
159
160 If there are no conflicts, this requires no more work from you.
161 However, let's say there was one in ChangeLog, since you didn't
162 follow my advice and modified it anyway.
163 git rebase will tell you there was a conflict and in which
164 file, and instruct you to resolve it and then resume with
165 "git rebase --continue" once that's done.
166
167 So you resolve as usual, by editing ChangeLog (which has the
168 usual conflict markers), then type "git rebase --continue".
169 That will fail, with a diagnostic telling you to mark
170 the file as "conflict resolved" by doing this:
171
172   git add ChangeLog
173
174 Then, finally, you can proceed (possibly onto more conflict resolution,
175 if there are conflicts in other files):
176
177   git rebase --continue
178
179 Once it finishes, your changes on the branch are now relative to
180 the tip of the trunk.
181
182 Now use git format-patch, as above.
183
184
185 Amending the most recent change on your private branch
186 ======================================================
187 Let's say you've just committed a change on your private
188 branch, and then realize that something about it is not right.
189 It's easy to adjust:
190
191   edit your files # this can include running "git add NEW" or "git rm BAD"
192   git commit --amend -a
193   git format-patch --stdout -1 > your-branch.diff
194
195 That replaces the most recent change-set with the revised one.
196
197
198
199 Parted-specific:
200
201 No more ChangeLog files
202 =======================
203 Do not modify any of the ChangeLog files in parted.  Starting in
204 2008, the policy changed.  Before, we would insert the exact same text
205 (or worse, sometimes slightly differing) into both the ChangeLog file
206 and the commit log.  Now we put that information only in the commit log,
207 and generate the top-level ChangeLog file from logs at "make dist" time.
208 As such, there are strict requirements on the form of the commit log
209 messages.
210
211
212 Commit log requirements
213 =======================
214 Your commit log should always start with a one-line summary, the second
215 line should be blank, and the remaining lines are usually ChangeLog-style
216 entries for all affected files.  However, it's fine -- even recommended --
217 to write a few lines of prose describing the change, when the summary
218 and ChangeLog entries don't give enough of the big picture.  Omit the
219 leading TABs that you're used to seeing in a "real" ChangeLog file, but
220 keep the maximum line length at 72 or smaller, so that the generated
221 ChangeLog lines, each with its leading TAB, will not exceed 80 columns.
222 As for the ChangeLog-style content, please follow these guidelines:
223
224   http://www.gnu.org/software/guile/changelogs/guile-changelogs_3.html
225
226 Try to make the summary line fit one of the following forms:
227
228   program_name: change-description
229   prog1, prog2: change-description
230   doc: change-description
231   tests: change-description
232   build: change-description
233   maint: change-description
234
235
236 Curly braces: use judiciously
237 =============================
238 Omit the curly braces around an "if", "while", "for" etc. body only when
239 that body occupies a single line.  In every other case we require the braces.
240 This ensures that it is trivially easy to identify a single-*statement* loop:
241 each has only one *line* in its body.
242
243 Omitting braces with a single-line body is fine:
244
245      while (expr)
246        single_line_stmt ();
247
248 However, the moment your loop/if/else body extends onto a second line,
249 for whatever reason (even if it's just an added comment), then you should
250 add braces.  Otherwise, it would be too easy to insert a statement just
251 before that comment (without adding braces), thinking it is already a
252 multi-statement loop:
253
254      while (true)
255        /* comment... */      // BAD: multi-line body without braces
256        single_line_stmt ();
257
258 Do this instead:
259
260      while (true)
261        {  /* Always put braces around a multi-line body.  */
262          /* explanation... */
263          single_line_stmt ();
264        }
265
266 There is one exception: when the second body line is not at the same
267 indentation level as the first body line.
268
269      if (expr)
270        error (0, 0, _("a diagnostic that would make this line"
271                       " extend past the 80-column limit"));
272
273 It is safe to omit the braces in the code above, since the
274 further-indented second body line makes it obvious that this is still
275 a single-statement body.
276
277 To reiterate, don't do this:
278
279      if (expr)
280        while (expr_2)        // BAD: multi-line body without braces
281          {
282            ...
283          }
284
285 Do this, instead:
286
287      if (expr)
288        {
289          while (expr_2)
290            {
291              ...
292            }
293        }
294
295 However, there is one exception in the other direction, when even a
296 one-line block should have braces.  That occurs when that one-line,
297 brace-less block is an "else" block, and the corresponding "then" block
298 *does* use braces.  In that case, either put braces around the "else"
299 block, or negate the "if"-condition and swap the bodies, putting the
300 one-line block first and making the longer, multi-line block be the
301 "else" block.
302
303     if (expr)
304       {
305         ...
306         ...
307       }
308     else
309       x = y;    // BAD: braceless "else" with braced "then"
310
311 This is preferred, especially when the multi-line body is more than a
312 few lines long, because it is easier to read and grasp the semantics of
313 an if-then-else block when the simpler block occurs first, rather than
314 after the more involved block:
315
316     if (!expr)
317       x = y;                  /* more readable */
318     else
319       {
320         ...
321         ...
322       }
323
324 If you'd rather not negate the condition, then add braces:
325
326     if (expr)
327       {
328         ...
329         ...
330       }
331     else
332       {
333         x = y;
334       }
335
336
337 Use SPACE-only indentation in all[*] files
338 ==========================================
339 We use space-only indentation in nearly all files.
340 If you use Emacs and your parted working directory name matches,
341 this code enables the right mode:
342
343   ;; In parted, indent with spaces everywhere (not TABs).
344   ;; Exceptions: Makefile and ChangeLog modes.
345   (add-hook 'find-file-hook '(lambda ()
346     (if (and buffer-file-name
347              (string-match "/parted\\>" (buffer-file-name))
348              (not (string-equal mode-name "Change Log"))
349              (not (string-equal mode-name "Makefile")))
350         (setq indent-tabs-mode nil))))
351
352 [*] Makefile and ChangeLog files are exempt, of course.
353
354 [FIXME: suggest vim syntax to do same thing, if it can be done safely.
355  Most distros now "set nomodeline" by default for a good reason. ]
356
357
358 Send patches to the address listed in --help output
359 ===================================================
360 Please follow the guidelines in the "Sending your patches." section of
361 git's own SubmittingPatches:
362
363   http://git.kernel.org/?p=git/git.git;a=blob;f=Documentation/SubmittingPatches
364
365
366 Add documentation
367 =================
368 If you add a feature or change some user-visible aspect of a program,
369 document it.  If you add an option, document it both in --help output
370 (i.e., in the usage function that generates the --help output) and in
371 doc/*.texi.  The man pages are generated from --help output, so
372 you shouldn't need to change anything under man/.  User-visible changes
373 are usually documented in NEWS, too.
374
375 When writing prose (documentation, comments, log entries), use an
376 active voice, not a passive one.  I.e., say "print the frobnozzle",
377 not "the frobnozzle will be printed".
378
379 Please add comments per the GNU Coding Standard:
380   http://www.gnu.org/prep/standards/html_node/Comments.html
381
382
383 Minor syntactic preferences
384 ===========================
385 [I hesitate to write this one down, because it appears to be an
386  acquired taste, at least for native-English speakers.  It seems odd
387  (if not truly backwards) to nearly anyone who doesn't have a strong
388  mathematics background and perhaps a streak of something odd in their
389  character ;-) ]
390 In writing arithmetic comparisons, use "<" and "<=" rather than
391 ">" and ">=".  For some justification, read this:
392   http://thread.gmane.org/gmane.comp.version-control.git/3903/focus=4126
393
394 const placement:
395 Write "Type const *var", not "const Type *var".
396 FIXME: dig up justification
397
398
399 Be nice to translators
400 ======================
401 Don't change translatable strings if you can avoid it.
402 If you must rearrange individual lines (e.g., in multi-line --help
403 strings), extract and create new strings, rather than extracting
404 and moving into existing blocks.  This avoids making unnecessary
405 work for translators.
406
407
408 Add tests
409 ==========
410 Nearly every significant change must be accompanied by a test suite
411 addition that exercises it.  If you fix a bug, add at least one test that
412 fails without the patch, but that succeeds once your patch is applied.
413 If you add a feature, add tests to exercise as much of the new code
414 as possible. Note to run tests/new-test in isolation you can do:
415
416   (cd tests && make check TESTS=new-test VERBOSE=yes)
417
418 There are many tests in the tests/ directories.  Use one of the
419 init.sh-using scripts as a template.
420
421 If writing tests is not your thing, don't worry too much about it,
422 but do provide scenarios, input/output pairs, or whatever, along with
423 examples of running the tool to demonstrate the new or changed feature,
424 and someone else will massage that into a test (writing portable tests
425 can be a challenge).
426
427
428 Copyright assignment
429 ====================
430 If your change is significant (i.e., if it adds more than ~10 lines),
431 then you'll have to have a copyright assignment on file with the FSF.
432 Since that involves first an email exchange between you and the FSF,
433 and then the exchange (FSF to you, then back) of an actual sheet of paper
434 with your signature on it, and finally, some administrative processing
435 in Boston, the process can take a few weeks.
436
437 The forms to choose from are in gnulib's doc/Copyright/ directory.
438 If you want to assign a single change, you should use the file,
439 doc/Copyright/request-assign.changes:
440
441     http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/Copyright/request-assign.changes;hb=HEAD
442
443 If you would like to assign past and future contributions to a project,
444 you'd use doc/Copyright/request-assign.future:
445
446     http://git.sv.gnu.org/gitweb/?p=gnulib.git;a=blob;f=doc/Copyright/request-assign.future;hb=HEAD
447
448 You may make assignments for up to four projects at a time.
449
450 In case you're wondering why we bother with all of this, read this:
451
452     http://www.gnu.org/licenses/why-assign.html
453
454
455 Run "make syntax-check", or even "make distcheck"
456 ================================================
457 Making either of those targets runs many integrity and
458 project-specific policy-conformance tests.  For example, the former
459 ensures that you add no trailing blanks and no uses of certain deprecated
460 functions.  The latter performs all "syntax-check" tests, and also
461 ensures that the build completes with no warnings when using a certain
462 set of gcc -W... options.  Don't even bother running "make distcheck"
463 unless you have a reasonably up to date installation including recent
464 versions of gcc and the linux kernel, and modern GNU tools.
465
466
467 Ensure that your changes are indented properly.
468 ===============================================
469 Format the code the way GNU indent does.
470 In a file with the "indent-tabs-mode: nil" directive at the end,
471 running "indent --no-tabs" should induce no change.
472 With other files, there will be some existing differences.
473 Try not to add any more.
474
475
476 Avoid trailing white space
477 ==========================
478 You may notice that the only trailing blanks in parted's
479 version-controlled files are in a single directory: tests/pr,
480 which contains expected output from various invocations of pr.
481
482 Do not add any more trailing blanks anywhere.  While "make syntax-check"
483 will alert you if you slip up, it's better to nip any problem in the
484 bud, as you're typing.  A good way to help you adapt to this rule is
485 to configure your editor to highlight any offending characters in the
486 files you edit.  If you use Emacs, customize its font-lock mode (FIXME:
487 provide more detail) or try one of its whitespace packages.  This appears
488 to be the one that will end up in emacs 23:
489
490     http://www.emacswiki.org/emacs/WhiteSpace
491
492 [that page says its version also works with emacs 21 and 22]
493 If you use vim, add this to ~/.vimrc:
494
495     let c_space_errors=1
496     highlight RedundantSpaces ctermbg=red guibg=red
497     match RedundantSpaces /\s\+$\| \+\ze\t/
498
499
500 Git can help too, by stopping you from committing any change that would
501 add trailing blanks.  The example pre-commit hook contains code to check
502 for trailing whitespace and spaces before tabs; enable it by moving it
503 to the right place and making sure it is executable:
504
505     mv .git/hooks/pre-commit.sample .git/hooks/pre-commit
506
507 With a repository created by git-1.5.6 or older, use this command:
508
509     chmod +x .git/hooks/pre-commit
510
511 To manually check for whitespace errors before committing, you can use
512
513     git diff --check
514
515 Git also has some settings to enable suitable internal whitespace checks.
516 See the manpage for git-apply for details.
517
518
519 -------------------------------------------
520
521 Miscellaneous useful git commands
522 =================================
523
524   * gitk: give a graphical view of the revision graph of the current branch
525   * gitk --all: same, but display all branches
526   * git log: to get most of the same info in text form
527   * git log -p: same as above, but with diffs
528   * git log -p SOME_FILE: same as above, but limit to SOME_FILE
529   * git log -p -2 SOME_FILE: same as above, but print only two deltas
530   * git log -p -1: print the most recently committed change set
531   * git format-patch --stdout -1 > FILE: output the most recently committed
532       change set, in a format suitable to be submitted and/or applied via
533       "git am FILE".
534   * git reset --soft HEAD^: Commit the delta required to restore
535       state to the revision just before HEAD (i.e., next-to-last).
536   * git rebase -i master: run this from on a branch, and it gives
537       you an interface with which you can reorder and modify arbitrary
538       change sets on that branch.
539
540   * if you "misplace" a change set, i.e., via git reset --hard ..., so that
541     it's no longer reachable by any branch, you can use "git fsck" to find
542     its SHA1 and then tag it or cherry-pick it onto an existing branch.
543     For example, run this:
544       git fsck --lost-found HEAD && cd .git/lost-found/commit \
545         && for i in *; do git show $i|grep SOME_IDENTIFYING_STRING \
546         && echo $i; done
547     The "git fsck ..." command creates the .git/lost-found/... hierarchy
548     listing all unreachable objects.  Then the for loop
549     print SHA1s for commits that match via log or patch.
550     For example, say that found 556fbb57216b119155cdda824c98dc579b8121c8,
551     you could run "git show 556fbb57216b119" to examine the change set,
552     or "git checkout -b found 556fbb5721" to give it a branch name.
553     Finally, you might run "git checkout master && git cherry-pick 556fbb5721"
554     to put that change on the tip of "master".
555
556 -------------------------------------------
557
558 Finding things to do
559 ====================
560 If you don't know where to start, check out the TODO file for projects
561 that look like they're at your skill-/interest-level.  Another good
562 option is always to improve tests.  You never know what you might
563 uncover when you improve test coverage, and even if you don't find
564 any bugs your contribution is sure to be appreciated.
565
566 A good way to quickly assess current test coverage is to use "lcov"
567 to generate HTML coverage reports.  Follow these steps:
568
569   # configure with coverage information
570   ./configure CFLAGS="-g -fprofile-arcs -ftest-coverage"
571   make
572   # run whatever tests you want, i.e.:
573   make check
574   # run lcov
575   lcov -t parted -q -d libparted -b lib -o lib.lcov -c
576   lcov -t parted -q -d parted    -b src -o src.lcov -c
577   # generate HTML from the output
578   genhtml -p `pwd` -t parted -q --output-directory lcov-html *.lcov
579
580 Then just open the index.html file (in the generated lcov-html directory)
581 in your favorite web browser.
582
583 ========================================================================
584 Copyright (C) 2009-2012 Free Software Foundation, Inc.
585
586 Permission is granted to copy, distribute and/or modify this document
587 under the terms of the GNU Free Documentation License, Version 1.3 or
588 any later version published by the Free Software Foundation; with no
589 Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
590 Texts.  A copy of the license is included in the ``GNU Free
591 Documentation License'' file as part of this distribution.