HACKING 7.59 KB
Newer Older
1 2
Source code repository
======================
Chema Celorio's avatar
Chema Celorio committed
3

4 5 6 7 8 9 10 11 12
gedit source code is maintained using the git version control system
and is available at the following location:

    git://git.gnome.org/gedit

Or if you have an account on GNOME servers:

    ssh://USERNAME@git.gnome.org/git/gedit

13
A web interface is available at:
14

15
    https://git.gnome.org/browse/gedit
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38

Building from git
=================

When building from a git checkout you will need to run the
autogen.sh script which takes care of running automake, autoconf,
etc and then run "configure" for you. You can pass options like
--prefix to autogen.sh and they will be forwarded to the configure
script.

Note that you cannot run gedit from its build directory: you need
to install it with "make install". For this reason it is highly
recommended that you install in a separate prefix instead of
overwriting your system binaries. Note however that when running
gedit from a custom prefix you will need to set many environment
variables accordingly, for instance PATH and XDG_DATA_DIR.
The JHBuild tool can take care of all this for you.


Commit guidelines
=================

39
Please don't commit directly to the git repository unless
40
you have been given the green light to commit freely to gedit.
41
When in doubt assume you haven't ;-).
Chema Celorio's avatar
Chema Celorio committed
42

43 44
Please attach patches in bugzilla (http://bugzilla.gnome.org).
If the patch fixes a bug that is not reported yet in bugzilla or is
Paolo Maggi's avatar
Paolo Maggi committed
45
an enhancement, create a new bugreport.
Chema Celorio's avatar
Chema Celorio committed
46

47 48
Please create patches with the git format-patch command.

Chema Celorio's avatar
Chema Celorio committed
49
If you are a translator feel free to mark strings for translation,
Paolo Maggi's avatar
Paolo Maggi committed
50
fix typos in the code, etc.
Chema Celorio's avatar
Chema Celorio committed
51

52 53
Please send patches for build & configure fixes too.  I really appreciate
your help, I just want to review these fixes before applying.
Chema Celorio's avatar
Chema Celorio committed
54

55
If you are a "build sheriff", feel free to commit fixes for build and
Paolo Maggi's avatar
Paolo Maggi committed
56 57
configure (please, send me an e-mail with the patch you have applied).

58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
When committing to the gedit git repository make sure to include a
meaningful commit message. Changes without a sufficient commit message
will be reverted. Commit messages should have the following format:

=== begin example commit ===
Short explanation of the commit

Longer explanation explaining exactly what's changed, whether any
external or private interfaces changed, what bugs were fixed (with bug
tracker reference if applicable) and so forth. Be concise but not too brief.
=== end example commit ===

  - Always add a brief description of the commit to the _first_ line of
    the commit and terminate by two newlines (it will work without the
    second newline, but that is not nice for the interfaces).

  - First line (the brief description) must only be one sentence and
    should start with a capital letter unless it starts with a lowercase
    symbol or identifier. Don't use a trailing period either. Don't exceed
    72 characters.

  - The main description (the body) is normal prose and should use normal
    punctuation and capital letters where appropriate. Normally, for patches
    sent to a mailing list it's copied from there.

  - When committing code on behalf of others use the --author option, e.g.
    git commit -a --author "Joe Coder <joe@coder.org>" and --signoff.


87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
Code conventions
================

You may encounter old code that doesn't follow all the following code
conventions, but for new code it is better to follow them, for consistency.

  - Avoid trailing whitespace.

  - Indent the C code with tabulations with a width of eight characters.

  - The files should have a modeline for the indentation style.

  - All blocks should be surrounded by curly braces, even one-line blocks. It
    spaces out the code, and it is more convenient when some code must be added
    or removed without the need to add or remove the curly braces.

  - Follow the C89 standard. In particular, no "//"-style comments.

105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
  - As a general rule of thumb, follow the same coding style as the surrounding
    code.

  - Do not be cheap about blank lines, spacing the code vertically help
    readability. However never use two consecutive blank lines, there is really
    no need.


Programming best practices
==========================

gedit is a pretty big piece of software, developed over the years by different
people and GNOME technologies. Some parts of the code may be a little old. So
when editing the code, we should try to make it better, not worse.

Here are some general advices.

  - Simplicity: the simpler code the better. Any trick that seem smart when you
    write it is going to bite your ass later when reading the code. Given that
    you spend 90% of the time staring at the code and 10% writing it, making
    reading the code harder is a net loss.

  - Brevity: make an effort to refactor common code into utility functions and
    use library function whenever is possible: every time you cut and paste a
    line of code you are throwing away all the precious seconds of your life
    that you will later spend trying to figure out the differences among the two
    copies that will have surely diverged.

  - Code for change: code is bound to contain bugs no matter how well it is
    written. A good coding style allows to fix these bugs with minimal changes
    instead of reformatting a whole section of unrelated code, this is
    especially important to make patch review easier and to easily understand
    the commit history. Some practical examples are:

      - Factor code into self contained functions so that changing a function
	does not require to change all the callers.

      - Do not align variable declaration, "case" statements etc, since this
	will inevitably mean that when a line will change you'll have to
	reformat all the surrounding ones.

      - Declare variables in the strictest scope as possible.

      - Reorder functions so that you do not need prototypes for static
	functions so that when you change them you need to change them only in
	one place.

  - Self documentation and code comments: use code comments parsimoniously. Code
    should be written so that it is clear and evident without the need of
    comments. Besides, comments usually get outdated when the code is changed
    and they become misleading. In particular avoid stating the obvious e.g. "a
    = 1; /* assign 1 to a */". Use good function names and variables to make the
    code self-documented.

    A good function name is one that explain clearly all what its code really
    does. There shouldn't be hidden features. If you can not find easily a good
    function name, you should probably split the function in smaller pieces. A
    function should do only one thing, but do it well.

    Please avoid lots of one-letter variables. And a variable should be used for
    only one purpose.

    Self-documentation is obviously not always possible, so when a comment is
    needed, it is needed. In those cases make sure to explain why and not only
    how a specific thing is done: you can deduce the "how" from the code, but
    not the "why".  Public library functions should always be documented and in
    particular should include the calling conventions, e.g. if the result should
    be freed by the caller.

    Do not use fancy frames around comments like a line full of
    /*---------------*/ etc.

177 178 179 180
  - Contribute below on the stack. Fix a problem at the right place, instead of
    writing hacks to work around a bug or a lack of feature in an underlying
    library.

181 182 183 184 185

See also
========

https://wiki.gnome.org/Apps/Gedit/DevGettingStarted
186
https://developer.gnome.org/programming-guidelines/stable/
187
https://wiki.gnome.org/Projects/GTK%2B/BestPractices
188 189
http://ometer.com/hacking.html
http://blogs.gnome.org/swilmet/2012/08/01/about-code-quality-and-maintainability/
190 191


192 193 194
Thanks,

  The gedit team.