Wednesday, July 8, 2009

A sample git work flow to send/receive patch by email

I googled and tried couple of git work flows to send/receive trivial kernel patches, Here is my summary:



###################################################################
# References
http://linux.yyz.us/git-howto.html
http://www.kernel.org/pub/software/scm/git/docs/git-format-patch.html
http://www.kernel.org/pub/software/scm/git/docs/git-send-email.html


# One time commands

> apt-get install git-email
> cd /usr/src
> git clone git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git
linux-2.6
> cd /usr/src/linux-2.6
> git config --global user.name "Vincent Li"
> git config --global user.email "username@example.com"
> git config --global sendemail.smtpserver smtp.example.com
> git config --global sendemail.smtpserverport 587
> git config --global sendemail.smtpuser username
> git config --global sendemail.smtppass userpass

update: ( I did for my gmail account below)

199 apt-get install git-email
203 git config --global sendemail smtpserver smtp.gmail.com
205 cd .git
210 git branch
212 git config --global sendemail.smtpserver smtp.gmail.com
213 git config --global sendemail.smtpserverport 587
214 git config --global sendemail.smtpencryption tls
215 git config --global sendemail.smtpuser myusername@gmail.com
216 git config --global sendemail.smtppass xxxxx
233 git config --global user.name "Vincent Li"
234 git config --global user.email "myusername@gmail.com"



# Make a new branch for the patch you're doing. In this case, I'll do replacing BUG_ON with VM_BUG_ON in mm/vmscan.c

> git checkout -b experimental

# Now edit the file

> perl -pi -e 's/^(\t+)BUG_ON/$1VM_BUG_ON/g' mm/vmscan.c
> git commit -a

# Put in a simple message of a line or two.

Trivial: Replace BUG_ON with VM_BUG_ON for consistency

VM subsystem use VM_BUG_ON to test likely bug situation,mm/vmscan.c still have three BUG_ON left, Replacing it with VM_BUG_ON for code consistency.

# Now exit the editor

# Check the commit, which is the most recent one by default

> git log -1

# See the actual patch with:
> git diff master..HEAD

commit 64ea153753811970563ecf5938a8a87c54336495
Author: Vincent Li
Date: Wed Jul 8 10:17:37 2009 -0700

Trivial: Replace BUG_ON with VM_BUG_ON for consistency

VM subsystem use VM_BUG_ON to test likely bug situation,mm/vmscan.c still have three BUG_ON left, Replacing it with VM_BUG_ON for code consistency.


#If you want to format a single commit with signed off, you can do this with "git format-patch -1 -s ".

> git format-patch -1 -s 64ea153
0001-Trivial-Replace-BUG_ON-with-VM_BUG_ON-for-consisten.patch

# Now look the patch over and see if you need to edit the subject or anything


# Now do a dry run to send the email
> git send-email --dry-run --to=username@example.com
0001-Trivial-Replace-BUG_ON-with-VM_BUG_ON-for-consisten.patch

# Looks good, send for real
> git send-email --to=linux-kernel@vger.kernel.org
0001-Trivial-Replace-BUG_ON-with-VM_BUG_ON-for-consisten.patch

#I use alpine as email client, save the email as mbox single file, for example /tmp/trivial.patch, now use git am to apply the patch

> git checkout master

#git-am refuses to process new mailboxes while the .git/rebase-apply directory exists, so if you decide to start over from scratch,
run rm -f -r .git/rebase-apply before running the command with mailbox names.
> rm -f -r .git/rebase-apply
> git am /tmp/trivial.patch
Applying: Trivial: Replace BUG_ON with VM_BUG_ON for consistency

> git log -1

commit 9ba28a665d0a642f9bfda54a6ffedb8c0e8dbd8b
Author: Vincent Li
Date: Wed Jul 8 10:35:08 2009 -0700

Trivial: Replace BUG_ON with VM_BUG_ON for consistency

VM subsystem use VM_BUG_ON to test likely bug situation,mm/vmscan.c
still have three BUG_ON left, Replacing it with VM_BUG_ON for code consistency.

Signed-off-by: Vincent Li

# Now if you are not happy with the patch, and don't want it in history, reset master branch with

>git reset --hard HEAD^



That is my sample git work flow, of course you can merge your experimental branch patch with master branch with git merge, I just showed you the way to format/send/receive/apply patch by email, since from time to time, you may need to send out trivial patch and test out other's patch as system administrator, not full time programmer.

more info on how to submit multiple patches from linke below:

http://www.spinics.net/lists/newbies/msg44250.html

For example:

Create a local branch for a tree:

$ git clone git://git.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git
$ cd linux-next
$ git checkout -b devel origin/master

Do some change and commit:

$ emacs drivers/staging/pohmelfs/dir.c
$ git add drivers/staging/pohmelfs/dir.c
$ git commit -m "Staging: pohmelfs/dir.c: Fix something"

Do another change and commit:

$ emacs drivers/staging/pohmelfs/dir.c
$ git commit -m "Staging: pohmelfs/dir.c: Fix another thing"

Generate your patchset with your last two commits

$ git format-patch -s -2

This will create one file for each patch generated.

So to send your patchset you can use the command:

$ git send-email --compose --to='Zac Storer '
--cc='kernelnewbies@xxxxxxxxxxxxxxxxx' *.patch

The command will extract the commit message and use it as the mail
subject, with the --compose flag you can create a prelude mail
explaining your patchset.

So this command will create 3 mails with these subjects

[PATCH 0/2] Staging: pohmelfs/dir.c: Fixes
[PATCH 1/2] Staging: pohmelfs/dir.c: Fix something
[PATCH 2/2] Staging: pohmelfs/dir.c: Fix another thing

Also you can be sure that your email client didn't wrap lines and the
message era encoded in ASCII.

Remember always to use scripts/checkpatch.pl to check your patches and
scripts/get_maintainer.pl to check who are the developers that have to
be cc'ed.

No comments:

Post a Comment

Followers