Online Book Reader

Home Category

Mercurial_ The Definitive Guide - Bryan O'Sullivan [101]

By Root 987 0
stack and making your changes.

$ cd netplug

$ hg qinit

$ hg qnew -m 'fix build problem with gcc 4' build-fix.patch

$ perl -pi -e 's/int addr_len/socklen_t addr_len/' netlink.c

$ hg qrefresh

$ hg tip -p

changeset: 1:3174f1d41d77

tag: qtip

tag: build-fix.patch

tag: tip

tag: qbase

user: Bryan O'Sullivan

date: Tue May 05 06:44:41 2009 +0000

summary: fix build problem with gcc 4

diff -r 566cfe2faac9 -r 3174f1d41d77 netlink.c

--- a/netlink.c Tue May 05 06:44:41 2009 +0000

+++ b/netlink.c Tue May 05 06:44:41 2009 +0000

@@ -275,7 +275,7 @@

exit(1);

}

- int addr_len = sizeof(addr);

+ socklen_t addr_len = sizeof(addr);

if (getsockname(fd, (struct sockaddr *) &addr, &addr_len) == -1) {

do_log(LOG_ERR, "Could not get socket details: %m");

Let’s say a few weeks or months pass, and your package author releases a new version. First, bring their changes into the repository.

$ hg qpop -a

patch queue now empty

$ cd ..

$ download netplug-1.2.8.tar.bz2

$ hg clone netplug-1.2.5 netplug-1.2.8

updating working directory

18 files updated, 0 files merged, 0 files removed, 0 files unresolved

$ cd netplug-1.2.8

$ hg locate -0 | xargs -0 rm

$ cd ..

$ tar jxf netplug-1.2.8.tar.bz2

$ cd netplug-1.2.8

$ hg commit --addremove --message netplug-1.2.8

The pipeline starting with hg locate above deletes all files in the working directory, so that hg commit’s --addremove option can actually tell which files have really been removed in the newer version of the source.

Finally, you can apply your patches on top of the new tree.

$ cd ../netplug

$ hg pull ../netplug-1.2.8

pulling from ../netplug-1.2.8

searching for changes

adding changesets

adding manifests

adding file changes

added 1 changesets with 12 changes to 12 files

(run 'hg update' to get a working copy)

$ hg qpush -a

(working directory not at tip)

applying build-fix.patch

now at: build-fix.patch

Combining Entire Patches

MQ provides a command qfold that lets you combine entire patches. This “folds” the patches you name, in the order you name them, into the topmost applied patch, and concatenates their descriptions onto the end of its description. The patches that you fold must be unapplied before you fold them.

The order in which you fold patches matters. If your topmost applied patch is foo, and you qfold bar and quux into it, you will end up with a patch that has the same effect as if you applied first foo, then bar, followed by quux.

Merging Part of One Patch into Another

Merging part of one patch into another is more difficult than combining entire patches. If you want to move changes to entire files, you can use filterdiff’s -i and -x options to choose the modifications to snip out of one patch, concatenating its output onto the end of the patch you want to merge into. You usually won’t need to modify the patch you’ve merged the changes from. Instead, MQ will report some rejected hunks when you qpush it (from the hunks you moved into the other patch), and you can simply qrefresh the patch to drop the duplicate hunks.

If you have a patch that has multiple hunks modifying a file, and you only want to move a few of those hunks, the job becomes more messy, but you can still partly automate it. Use lsdiff -nvv to print some metadata about the patch.

$ lsdiff -nvv remove-redundant-null-checks.patch

22 File #1 a/drivers/char/agp/sgi-agp.c

24 Hunk #1 static int __devinit agp_sgi_init(void)

37 File #2 a/drivers/char/hvcs.c

39 Hunk #1 static struct tty_operations hvcs_ops =

53 Hunk #2 static int hvcs_alloc_index_list(int n)

69 File #3 a/drivers/message/fusion/mptfc.c

71 Hunk #1 mptfc_GetFcDevPage0(MPT_ADAPTER *ioc, in

85 File #4 a/drivers/message/fusion/mptsas.c

87 Hunk #1 mptsas_probe_hba_phys(MPT_ADAPTER *ioc)

98 File #5 a/drivers/net/fs_enet/fs_enet-mii.c

100 Hunk #1 static struct fs_enet_mii_bus *create_bu

111 File #6 a/drivers/net/wireless/ipw2200.c

113 Hunk #1 static struct ipw_fw_error *ipw_alloc_er

126 Hunk #2 static ssize_t clear_error(struct device

140 Hunk #3 static void ipw_irq_tasklet(struct

Return Main Page Previous Page Next Page

®Online Book Reader