【问题标题】:How to work on multiple patches at the same time using Mercurial Queues?如何使用 Mercurial Queues 同时处理多个补丁?
【发布时间】:2013-03-08 18:32:36
【问题描述】:

可以说,我有 2 个错误要修复:bug1 和 bug2。

我从 bug1 开始,在修复它的过程中,我转到 bug2 并修复了一半。

我返回 bug1 并再次部分修复它并再次转到 bug2。

这样,经过多次切换,我修复了两个错误。

审查这两个错误的人是不同的,他们不想与他们不关心的错误有任何关系。所以,我需要为他们提供不同的补丁。

如果我使用普通的hg diff,我会这样做:

hg diff -U 7 -p file1 -r OLD_REVISION_NUMBER > patch1 用于 bug1,并且

hg diff -U 7 -p file2 -r OLD_REVISION_NUMBER > patch2 用于 bug2

如何对 Mercurial 队列进行同样的操作? 请提出一个基本的工作流程。

【问题讨论】:

    标签: mercurial patch mercurial-queue


    【解决方案1】:

    这是一个非常简化的工作流程,假设两个补丁不重叠,即两个补丁不会修改相同的文件。

    $ hg init myrepo
    $ cd myrepo
    $ echo "This is file1" >file1
    $ echo "This is file2" >file2
    $ hg add
    adding file1
    adding file2
    $ hg commit -m 'initial files'
    
    #  Initialize and work on patch1
    
    $ hg qnew -m 'Fix for bug1' patch1
    $ echo "a second line" >>file1
    $ hg diff
    diff --git a/file1 b/file1
    --- a/file1
    +++ b/file1
    @@ -1,1 +1,1 @@
    -This is file1
    +a second line
    $ hg qdiff
    diff --git a/file1 b/file1
    --- a/file1
    +++ b/file1
    @@ -1,1 +1,1 @@
    -This is file1
    +a second line
    
    #  Update the current patch (patch1)
    
    $ hg qrefresh
    $ hg diff
    $ hg qdiff
    diff --git a/file1 b/file1
    --- a/file1
    +++ b/file1
    @@ -1,1 +1,1 @@
    -This is file1
    +a second line
    
    #   Initialize and work on patch2
    
    $ hg qnew -m 'Fix for bug2' patch2
    $ hg qseries
    patch1
    patch2
    $ hg qtop
    patch2
    $ hg diff
    $ echo 'another line for file2' >>file2
    $ hg diff
    diff --git a/file2 b/file2
    --- a/file2
    +++ b/file2
    @@ -1,1 +1,2 @@
     This is file2
    +another line for file2
    $ hg qrefresh
    $ hg diff
    $ hg qdiff
    diff --git a/file2 b/file2
    --- a/file2
    +++ b/file2
    @@ -1,1 +1,2 @@
     This is file2
    +another line for file2
    
    #  Export patch2
    
    $ hg export qtip
    # HG changeset patch
    # User My Name <myemail>
    # Date 1362771912 28800
    # Node ID 2baa2bf81b000d4d720f9c4151242458b90bcd80
    # Parent  ccd75363c8f459bec4a8d6b94dfb4150fb9e3014
    Fix for bug2
    
    diff --git a/file2 b/file2
    --- a/file2
    +++ b/file2
    @@ -1,1 +1,2 @@
     This is file2
    +another line for file2
    
    #  Pop back to and export patch1
    
    $ hg qpop
    popping patch2
    now at: patch1
    $ hg export qtip
    # HG changeset patch
    # User My Name <myemail>
    # Date 1362771745 28800
    # Node ID ccd75363c8f459bec4a8d6b94dfb4150fb9e3014
    # Parent  a227e9c42f2d17fb28082ad2451a03d4926505ba
    Fix for bug1
    
    diff --git a/file1 b/file1
    --- a/file1
    +++ b/file1
    @@ -1,1 +1,1 @@
    -This is file1
    +a second line
    
    #  Resume working on patch2
    
    $ hg qpush
    applying patch2
    now at: patch2
    ...
    
    #  Apply patch1 to repo
    
    $ hg qpop
    popping patch2
    now at: patch1
    $ hg qfinish -a
    $ hg qseries
    patch2
    $ hg summary
    parent: 1:ccd75363c8f4 tip
     Fix for bug1
    branch: default
    commit: (clean)
    update: (current)
    mq:     1 unapplied
    $ hg qpush
    applying patch2
    now at: patch2
    

    请记住,Mercurial 队列旨在管理有序的补丁列表,其中系列中的后续补丁可能会修改早期补丁所做的更改。如果您正在处理的项目涉及对同一组文件进行并行开发,那么 MQ 可能不是最好的工具。在这种情况下,请考虑使用带有或不带有书签的 Mercurial 分支或 Mercurial 匿名头像。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多