Chinaunix首页 | 论坛 | 博客
  • 博客访问: 38185
  • 博文数量: 1
  • 博客积分: 30
  • 博客等级: 民兵
  • 技术积分: 124
  • 用 户 组: 普通用户
  • 注册时间: 2012-12-10 22:37
个人简介

随缘

文章存档

2013年(1)

我的朋友

分类: LINUX

2013-03-28 22:48:09

本文是在Ubunt 12.04环境下测试的。

1、安装必要的软件

  1. # apt-get install git git-core git-email


2、配置send-email的环境,主要是设置本地email的客户端,用msmtp

vim ~/.msmtprc
 

  1. # default
  2. account gmail
  3. protocol smtp
  4. host smtp.gmail.com
  5. from user@example.com
  6. user user@example.com
  7. password ******
  8. port 587
  9. auth on
  10. tls on
  11. tls_trust_file /etc/ssl/certs/ca-certificates.crt
  12. syslog LOG_MAIL

  13. # set a default account
  14. account default : gmail


3、设置git send-email的配置
vim ~/.gitconfig

  1. [user]
  2.     name = your name
  3.     email = user@example.com

  4. [sendemail]
  5.         smtpencryption = tls
  6.         smtpuser = user@example.com
  7.         smtpserverport = 587
  8.         smtpserver = smtp.gmail.com
  9. # to = user@example.com
  10. # cc = user@example.com
  11. # from = user@example.com
        

其中,上面配置文件的最后三行在git send-email发送补丁文件时也可以通过命令行指定。建议大家最好通过命令行指定,因为内核补丁文件需要发送给相关模块的maintainer。


4、下面就以实例来说明如果制作一个符合规范的内核补丁。
Linux内核补丁的制作规范和发送格式参见内核文档Documentation/SubmittingPatches。
a、修改内核

  1. diff --git a/net/sunrpc/auth_null.c b/net/sunrpc/auth_null.c
  2. index a5c36c0..f8e0d73 100644
  3. --- a/net/sunrpc/auth_null.c
  4. +++ b/net/sunrpc/auth_null.c
  5. @@ -27,6 +27,7 @@ nul_create(struct rpc_clnt *clnt, rpc_authflavor_t flavor)
  6.  static void
  7.  nul_destroy(struct rpc_auth *auth)
  8.  {
  9. + pr_info("hellor world!\n");
  10.  }


b、提交修改

  1. git commit -a -s -m"test" -e


其中,-a表示all,-s表示在补丁文件头部增加Signed-off-by行,-m表示指定commit信息,-e表示使用git默认的编辑器来对commit信息进一步编辑,我这里默认的编辑器是nano。关于更详细的参数选项可以用命令git commit -h来察看。

执行上面那个命令以后,会进入到nano编辑器中,然后进行编辑。其中第一行显示的是补丁文件头部的Subject信息,第二行文字显示的是补丁文件的注释信息。编辑完以后,ctrl-o保存,ctrl-x退出。  
 
 
c、生成补丁文件

  1. git format-patch -1
其中,-1表示生成一个补丁文件,即最后git commit时的修改。用vim打开补丁文件,如下所示:

 
 
之所以要有Subject,Signed-off-by文件,那是因为内核文档Documentation/SubmittingPatches文件中有说明:

15) The canonical patch format

The canonical patch subject line is:

    Subject: [PATCH 001/123] subsystem: summary phrase

The canonical patch message body contains the following:

- A "from" line specifying the patch author.

- An empty line.

- The body of the explanation, which will be copied to the
    permanent changelog to describe this patch.

- The "Signed-off-by:" lines, described above, which will
    also go in the changelog.

- A marker line containing simply "---".

- Any additional comments not suitable for the changelog.

- The actual patch (diff output).

d、检测补丁
制作完补丁文件以后,不要急着把补丁文件mail出去,需要先检测一下这个补丁的正确性。内核中提供了一个补丁检测脚本。在内核源代码根目录下,补丁检测如下:
  1. # ./scripts/checkpatch.pl 0001-nfs-add-a-pr_info.patch
  2. total: 0 errors, 0 warnings, 7 lines checked

  3. 0001-nfs-add-a-pr_info.patch has no obvious style problems and is ready for submission.

e、确定补丁发送给谁
补丁检测通过以后,就可以mail出去了。但是该mail给谁呢?嗯,内核里面也同样提供了一个脚本,用于检测某个目录的maintainer是谁。以我修改的net/sunrpc目录里面的文件为例,执行下面的命令:

  1. root@bandari-PC:~/code/linux-3.5.4# ./scripts/get_maintainer.pl net/sunrpc/ -f
  2. Trond Myklebust <Trond.Myklebust@netapp.com> (maintainer:NFS, SUNRPC, AND...)
  3. "J. Bruce Fields" <bfields@fieldses.org> (supporter:KERNEL NFSD, SUNR...)
  4. "David S. Miller" <davem@davemloft.net> (maintainer:NETWORKING [GENERAL])
  5. linux-nfs@vger.kernel.org (open list:NFS, SUNRPC, AND...)
  6. netdev@vger.kernel.org (open list:NETWORKING [GENERAL])
  7. linux-kernel@vger.kernel.org (open list)
从上面输出可以看到,email destination有三个人。而后面的3个则用于email carbon copy (cc),即抄送。

5、发送补丁
命令如下所示:
  1. root@bandari-PC:~# git send-email --smtp-server /usr/bin/msmtp --to user@example.com
  2. --cc user@example.com 0001-nfs-add-a-pr_info.patch

其中,git send-email的选项选项说明如下:
--to 邮件的To地址 sendmail.to
--cc 邮件的Cc地址 sendmail.cc
--smtp-server SMTP服务器名称 sendmail.smtp-server

关于git send-email的详细选项说明,可以通过执行命令git send-email -h察看。
注意,这里是通过命令行参数设置,前面说过,在~/.msmtprc文件也可以设置全局参数。
如果大家要测试的话,可以将--to和--cc设置成自己的邮箱地址。

阅读(8423) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:没有了

给主人留下些什么吧!~~