patches.sgml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. <chapter id="gbp.patches">
  2. <title>Working with patches</title>
  3. <para>&gbp-pq; can be used to manage patches inside
  4. <filename>debian/patches/</filename>.</para>
  5. <para>The basic idea is that patches are imported to a local
  6. patch-queue branch with one commit on the patch-queue branch
  7. representing exactly one patch
  8. in <filename>debian/patches/</filename>. The patch-queue branch will
  9. be named like the branch that has
  10. the <filename>debian/patches</filename> dir you imported from
  11. with <filename>patch-queue/</filename> prepended. So if you have your
  12. &debian; packaging on master the patch-queue branch will be
  13. called <filename>patch-queue/master</filename>.</para>
  14. <para>There, the
  15. maintainer will work on them using usual &git; commands (rebase, commit
  16. --amend, etc). When done, &gbp-pq; will be used to export the patches to
  17. <filename>debian/patches/</filename>. This workflow facilitates the
  18. cherry-picking of patches for stable releases, and the forward-porting of
  19. patches to new upstream versions by using git rebase on the
  20. patch-queue branch (patches already applied
  21. upstream are detected automatically). The generated patches
  22. in <filename>debian/patches/</filename> have all the necessary
  23. information to forward them upstream given they are auto generated via
  24. <command>git-format-patch(1)</command>.</para>
  25. <para>The main drawback of this workflow is the lack of history on the
  26. <filename>patch-queue/master</filename> branch (but there is full history on
  27. the <filename>master</filename> branch, of course).</para>
  28. <sect1 id="gbp.patches.workflow">
  29. <title>Workflow</title>
  30. <para>Assuming the &debian; source package has its patches in
  31. <filename>debian/patches</filename> and these are parseable by
  32. <command>git-quiltimport(1)</command>:</para>
  33. <para>Create patch-queue branch and
  34. import <filename>debian/patches</filename> onto it using &gbp-pq;
  35. </para>
  36. <programlisting>
  37. <command>cd <replaceable>REPO</replaceable></command>
  38. &gbp-pq; import
  39. </programlisting>
  40. <para>This will switch you to the patch-queue branch
  41. automatically.</para>
  42. <para>Now you can work on the patch-queue branch (add, remove, rebase, test) to
  43. get your patches into shape:
  44. <itemizedlist>
  45. <listitem><para>To add what will later become a patch in <filename>debian/patches/</filename> simply make a
  46. commit. The first line of the commit message will become the patch name later.
  47. The following lines include the details of what the patch does.</para></listitem>
  48. <listitem><para>To remove or edit commits use git rebase -i master. The git documentation
  49. explains how to work with git-rebase.</para></listitem>
  50. </itemizedlist></para>
  51. <para>Regenerate the patches in <filename>debian/patches/</filename> using
  52. &gbp-pq;. This will switch you back to master and regenerate the patches using
  53. a method similar to <command>git-format-patch(1)</command>:</para>
  54. <programlisting>
  55. &gbp-pq; export
  56. </programlisting>
  57. <para>Commit the result either by passing <option>--commit</option> to
  58. the above export or by using git commands:</para>
  59. <programlisting>
  60. &gitcmd; add debian/patches
  61. &gitcmd; commit
  62. </programlisting>
  63. <para>Update <filename>debian/changelog</filename> (e.g. by running "&gbp-dch; <option>-S</option> <option>-a</option>")</para>
  64. <para>You can now build the package as usual.</para>
  65. <para>After importing a new upstream version you can use the following commands
  66. to refresh <filename>debian/patches/</filename>:</para>
  67. <programlisting>
  68. &gbp-pq; rebase
  69. &gbp-pq; export
  70. </programlisting>
  71. <para>Should the rebase fail you can resort to
  72. &gitcmd; <option>rebase</option>.</para>
  73. <para>If you forgot to create a patch-queue before importing the new
  74. upstream version you can make &gbp-pq; figure out where to apply the
  75. patches by using the <option>--time-machine=</option>.</para>
  76. <para>If a package doesn't have any patches yet, these are the steps to add
  77. your first patch:</para>
  78. <orderedlist>
  79. <listitem><para>Launch an import, this will switch to the proper branch
  80. <programlisting>
  81. &gbp-pq; import
  82. </programlisting>
  83. </para></listitem>
  84. <listitem><para>Create your first patch: edit files, test, commit your changes using <command>git commit</command></para></listitem>
  85. <listitem><para>To generate the new Quilt patch set use
  86. <programlisting>
  87. &gbp-pq; export --commit
  88. </programlisting>This will switch you back to the <filename>master</filename>
  89. branch generate the patches and commit them right away to
  90. your <filename>master</filename> branch.
  91. Skip the <option>--commit</option> if you don't want to commit
  92. right away. If you want to pick the changelog message from the patch
  93. see
  94. <filename>/usr/share/doc/git-buildpackage/examples/gbp-add-patch</filename>.</para></listitem>
  95. </orderedlist>
  96. <para>
  97. In order to avoid a patched (unclean) source tree after the build, you
  98. can use &dpkg-source;'s <option>unapply-patches</option> option and
  99. tell &git; to ignore the <filename>.pc</filename> directory.
  100. <filename>/usr/share/doc/git-buildpackage/examples/gbp-configure-unpatched-source</filename>
  101. sets up these two files for you.
  102. </para>
  103. </sect1>
  104. <sect1 id="gbp.patches.team">
  105. <title>Team maintenance</title>
  106. <para>The easiest way is to not push out any patch-queue/* branches at all.
  107. They can be recreated by any team member easily by using</para>
  108. <programlisting>
  109. &gitcmd; branch -d patch-queue/master
  110. &gbp-pq; import
  111. </programlisting>
  112. <para>The patch-queue branch can also be re-created when pulling (this
  113. will additionally drop your current patch-queue branch and recreate it
  114. from <filename>debian/patches</filename>):</para>
  115. <programlisting>
  116. &gbp-pull; --redo-pq
  117. </programlisting>
  118. <para>
  119. Note that you can you can push out patch-queue branches. Other team
  120. members must just be aware that that branches in the patch-queue/
  121. namespace are being rebased frequently and therefore cause
  122. non fast-forward updates.
  123. </para>
  124. </sect1>
  125. <sect1 id="gbp.patches.30quilt">
  126. <title>Working with 3.0 (quilt) packges</title>
  127. <para>
  128. The 3.0 (quilt) format applies the patches
  129. in <filename>debian/patches</filename> automatically when building a
  130. source package. If you want your debian branch to contain the
  131. unpatched source there are several ways to handle this:
  132. </para>
  133. <itemizedlist>
  134. <listitem><para>Using <filename>debian/source/local-options</filename>:
  135. You can use <option>unapply-patches</option> in
  136. <filename>debian/source/local-options</filename> to unapply the patches after
  137. the build.
  138. <filename>/usr/share/doc/git-buildpackage/examples/gbp-configure-unpatched-source</filename>
  139. will this set up for you when run from inside a git repository of a Debian
  140. package.
  141. </para></listitem>
  142. <listitem><para>Using <option>--git-export-dir</option>:
  143. If you are using option <option>--git-export-dir</option> already there is no
  144. problem since the unpatched source tree gets exported before being built (and
  145. patched by dpkg-source). Since this implies an extra copy of the whole source
  146. tree (which might be slow for big projects) and it is not really necessary when
  147. using pbuilder the next method might be more appropriate.
  148. </para></listitem>
  149. <listitem><para>
  150. Working from a patch-queue branch.
  151. Instead of building from master build from patch-queue/master prepared by
  152. &gbp-pq; as describe above. This branch has the patches already applied as
  153. dpkg-source expects it:</para>
  154. <programlisting>
  155. &gbp-pq; import
  156. &gbp-buildpackage; --git-debian-branch=patch-queue/master
  157. #Build and test...
  158. &git; checkout master
  159. &gbp-pq; export
  160. </programlisting>
  161. </listitem>
  162. </itemizedlist>
  163. </sect1>
  164. </chapter>