If you have been around Linux distributions for any amount of time, you have realized that there are sometimes bugs in programs. In the Debian and Ubuntu distributions, bugs are often fixed through the packaging by patching the source code. Sometimes there are bugs in the packaging itself that can cause difficulties.


To patch the program's source code, you could simply download the current Ubuntu source package (with apt-get source) and make the needed changes. You can then add a new entry to the debian/changelog using dch -i or dch -v <version>-<revision> to specify the new revision. When you run debuild -S from the source directory you will have a new source package with a new .diff.gz in the parent directory that contains your changes. A problem with this approach is that the distinction between source and patches is unclear.

プログラムのソースコードの不具合を修正する簡単な方法は次のようになります。まず最新のUbuntuソースパッケージをダウンロードし(apt-get sourceコマンド)、修正を加えます。次にdch -idch -v <version>-<revision>を使ってdebian/changelogに新しいエントリを追加し、新バージョンの情報を書き込みます。あとはソースディレクトリからdebuild -Sを実行すれば、今回の変更点を含む.diff.gzと共に新しいソースパッケージが作成されます。この方法の問題点は、ソースとパッチの間の違いがはっきりしないことです。

A solution to this problem is to separate the changes to the source code into individual patches stored in the debian directory. One such patch system is called dpatch. The patches are stored in the debian/patches/ directory and have a special format.


To create a dpatch, perform the following steps sequentially.


Create a temporary work space and two copies of the current source directory:


mkdir tmp
cd tmp
cp -a ../<package>-<version> . 
cp -a <package>-<version> <package>-<version>.orig 

Make the changes in the <package>-<version> directory.


Create a patch file using diff and place it in the debian/patches directory:


diff -Nru <package>-<version>.orig <package>-<version> > patch-file

Create the dpatch using dpatch patch-template and a file named 00list that lists the dpatches:

dpatch patch-templateコマンドを使ってdpatchファイルを作成し、dpatchファイルのリストである00listにその名前を追加します:

dpatch patch-template -p "01_patchname" "patch-file description" \
         < patch-file > 01_patchname.dpatch
echo 01_patchname.dpatch >00list

You can now place 01_patchname.dpatch and 00list in the debian/patches directory of your source package:


mkdir ../<package>-<version>/debian/patches
cp 01_patchname.dpatch 00list ../<package>-<version>/debian/patches
cd ..
rm -rf tmp
  • attachment:UbuntuPackagingGuideJa/conventions/note.png You can also edit a pre-existing patch using dpatch-edit-patch.

  • attachment:UbuntuPackagingGuideJa/conventions/note.png dpatch-edit-patchを使えば、既存のパッチを編集することもできます。

Once all the changes have been made, a changelog entry added, and dpatch added to the debian/control file (if needed), then you can rebuild the source package with debuild -S.

すべての変更が加えられ、changelogファイルにエントリを追加し、(必要なら)debian/controlファイルにdpatchを追加したら、debuild -Sコマンドでソースパッケージをリビルドできます。

To get your fixed source package uploaded to the Ubuntu repositories, you will need to get your source package sponsored by a person who has upload rights. See the section called “Uploading and Review” for more details. Sometimes, rather than giving the entire source package (.diff.gz, .dsc, and .orig.tar.gz), it is easier and more efficient to just give the difference between the source package that is currently in the repositories and your fixed source package. A tool has been created to do just that called debdiff. Using debdiff is similar to using diff but is made specifically for packaging. You can debdiff the source package by:

修正したソースパッケージをUbuntuレポジトリにアップロードするためには、アップロード権限のある人に後見人になってもらう必要があります。詳しいことは“アップロードとレビュー”セクションを参照してください。ソースパッケージそのもの(.diff.gz, .dsc, .orig.tar.gz)を提出するよりも、現在レポジトリにあるソースパッケージと修正したソースパッケージの間の差分を提出した方がいい場合もあります。差分は、debdiffと呼ばれるツールを使えば作成できます。debdiffdiffに似ていますが、パッケージの差分を作成することに特化しています。debdiffを使ってソースパッケージの差分をとるには次のようにします:

debdiff <oldpackage>.dsc <newpackage>.dsc > package.debdiff

or the binary package by:


debdiff <oldpackage>.deb <newpackage>.deb > package.debdiff

Debdiffs are great to attach to bug reports and have ready for a sponsor to upload.


UbuntuJapaneseWiki: UbuntuPackagingGuideJa/updating-chap (last edited 2012-01-10 11:49:07 by anonymous)