Source / thg / manual / 2.4 / patches.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

<html xmlns="">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>7. Patches &mdash; TortoiseHg 2.4.0 documentation</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
        URL_ROOT:    '',
        VERSION:     '2.4.0',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/underscore.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="top" title="TortoiseHg 2.4.0 documentation" href="index.html" />
    <link rel="next" title="8. Extensions" href="extensions.html" />
    <link rel="prev" title="6. Settings" href="settings.html" /> 
    <div class="related">
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="extensions.html" title="8. Extensions"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="settings.html" title="6. Settings"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">TortoiseHg 2.4.0 documentation</a> &raquo;</li> 

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
  <div class="section" id="module-patches">
<span id="patches"></span><h1>7. Patches<a class="headerlink" href="#module-patches" title="Permalink to this headline"></a></h1>
<div class="section" id="defining-a-patch">
<h2>7.1. Defining a patch<a class="headerlink" href="#defining-a-patch" title="Permalink to this headline"></a></h2>
<p>These links are recommended reading for understanding the history and nature
of patches and how they can be used with Mercurial.</p>
<ul class="simple">
<li><a class="reference external" href="">The patch management problem</a></li>
<li><a class="reference external" href="">Understanding patches</a></li>
<li><a class="reference external" href="">More about patches</a></li>
<div class="section" id="pitfalls">
<h2>7.2. Pitfalls<a class="headerlink" href="#pitfalls" title="Permalink to this headline"></a></h2>
<p>The standard patch format cannot describe binary files, renames, copies,
or permission changes.  If your patch needs to record any of those
things, you will need to enable <strong>git</strong> patches via:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">diff</span><span class="p">]</span>
<span class="n">git</span><span class="o">=</span><span class="bp">True</span>
<p>Mercurial 1.5 improves its behavior in this regard.  It will warn you
when git diffs are required, or sometimes upgrade to the git format
automatically.  See also the
<a class="reference external" href="">diff section</a> of
the hgrc documentation.</p>
<p>Mercurial&#8217;s patch routines do not deal well with mixed EOLN between
source files and patches.  The <strong>patch.eol</strong> setting was introduced in
1.3 to improve this situation:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="p">[</span><span class="n">patch</span><span class="p">]</span>
<span class="n">eol</span> <span class="o">=</span> <span class="n">auto</span> <span class="c">#strict, lf, or crlf</span>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When eol is set to <em>auto</em>, the patching engine will preserve the line
endings of the patched file regardless of the line endings in the
patch itself.  You almost always want eol to be configured to <em>auto</em>.
The only downside is that you cannot make a patch that changes the
line endings of a source file.</p>
<p>See also the <a class="reference external" href="">patch section</a>
of the hgrc documentation.</p>
<p>Applying a patch is not a foolproof operation.  If the source file has
diverged from the file that was used to create the patch, there may be
conflicts during the patch application.  These are written to a file
with an .rej extension.  TortoiseHg 2.0 includes a <strong class="command">thg
rejects</strong> command that can aid in the merging of the rejected chunks into
the source file.</p>
<div class="section" id="export-patches">
<h2>7.3. Export Patches<a class="headerlink" href="#export-patches" title="Permalink to this headline"></a></h2>
<div class="section" id="changeset">
<h3>7.3.1. Changeset<a class="headerlink" href="#changeset" title="Permalink to this headline"></a></h3>
<p>To export a changeset as a patch file, use the changeset context menu of
the Workbench to select <em class="menuselection">Export ‣ Export Patch</em>.  It
writes the changeset to a file in the repository root folder.</p>
<div class="section" id="changeset-ranges">
<h3>7.3.2. Changeset Ranges<a class="headerlink" href="#changeset-ranges" title="Permalink to this headline"></a></h3>
<p>Select the start and end of a range of changesets in the Workbench and
open the special revision range context menu.  From this menu you can
generate patches, generate a bundle, send emails, or visually diff the
accumulated changes.</p>
<p>This is a very powerful feature and there is no restriction on the base
and target changesets you can select.</p>
<div class="section" id="email">
<h3>7.3.3. Email<a class="headerlink" href="#email" title="Permalink to this headline"></a></h3>
<div class="figure">
<img alt="Email dialog" src="_images/email.png" />
<p class="caption">Email dialog of Workbench</p>
<p>To send a changeset as an email, use the changeset context menu of the
Workbench. <em class="menuselection">Export ‣ Email Patch</em>.  This opens the
e-mail dialog for this single changeset.</p>
<p>To send a changeset range, use the changeset range selection feature of
the Workbench and select <em class="menuselection">Email selected...</em> or
<em class="menuselection">Email DAG range...</em>.</p>
<p>Lastly, you can use the <em class="guilabel">Email</em> button on the sync tab of the
Workbench to email all outgoing changes to the selected remote
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">You must configure
<a class="reference external" href="">SMTP</a>
to send patches via email</p>
<div class="section" id="import-patches">
<h2>7.4. Import Patches<a class="headerlink" href="#import-patches" title="Permalink to this headline"></a></h2>
<div class="figure">
<img alt="Import tool" src="_images/import.png" />
<p class="caption">Import dialog of the WorkBench</p>
<p>The import dialog can be opened from the <em class="guilabel">Repository</em> menu of
the Workbench, or via <strong class="command">thg import</strong>.  The dialog supports file
and directory drag and drop.</p>
<p>You have the choice of importing directly into the repository, the
working folder, a shelf file, or your patch queue.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Importing a patch requires a clean working directory state.  You
must commit, revert, or shelve changes before importing a patch.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">If a patch does not import itself cleanly into the repository, the
recommended recourse is to import the patch into your patch queue
(qimport) and then qpush the patch.  This uses TortoiseHg patch
rejection dialog and preserves the meta-data in the patch header.
Do not forget to qrefresh after resolving the rejected chunks.</p>
<div class="admonition warning">
<p class="first admonition-title">Warning</p>
<p class="last">If the patch you are importing does not have a commit
message, Mercurial will try to launch your editor, just as if you
had tried to import the patch from the command line.  Your ui.editor
needs to be a GUI app to make this work correctly.</p>
<div class="section" id="patch-queues">
<h2>7.5. Patch Queues<a class="headerlink" href="#patch-queues" title="Permalink to this headline"></a></h2>
<div class="figure">
<img alt="Patch Queue in Workbench" src="_images/patchqueue.png" />
<p class="caption">A patch queue in the repository graph</p>
<p>When MQ is enabled, several Workbench features are exposed. Context menu
options are exposed in the changeset menus, your patch queue is graphed
together with your repository&#8217;s history, and a Patch Queue task tab is
<div class="figure">
<img alt="Patch Queue Task Tab" src="_images/mq-tasktab.png" />
<p class="caption">MQ tool or task tab</p>
<p>The <em class="guilabel">Patch Queue</em> task tab is also available as <strong class="command">thg
mq</strong> from the command line.  Most MQ features are available from the
Patch Queue task tab, though a few features (qimport -r/qfinish) are
only supported via revision graph context menus.  Much functionality is
supported in both places.</p>
<p>Double clicking on an unapplied patch, an applied patch other than the
current qtip, or the qparent triggers a qgoto command; making the double
clicked revision the current patch.  Double clicking on any other
revision will trigger a visual diff of that revision.</p>
<p>In previous releases, the commit tool was a central feature in MQ use.
In TortoiseHg 2.0, the commit tool is almost completely unaware of MQ.
It only knows to not allow commits if the current working parent is an
applied patch.  Instead, MQ functionality has been focused into the
Workbench, Patch Queue task tab, and the shelve tool.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">The Workbench must be restarted after enabling or disabling the MQ
extension in a repository.  This is true of most extensions.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">It is recommended to learn the MQ extension before using the MQ
features of the Workbench.</p>
<div class="section" id="patch-rejects">
<h2>7.6. Patch Rejects<a class="headerlink" href="#patch-rejects" title="Permalink to this headline"></a></h2>
<p>As explained previously, patches are not guaranteed to apply cleanly to
their intended source files.  Prior to TortoiseHg 2.0, the only recourse
available when patch chunks were rejected was to open the source file
and the rejects file in an editor and manually fixup the rejected
<p>TortoiseHg 2.0 introduces a dialog that makes this a little bit easier.
If the shelve tool detects chunk rejections, it offers to open the
rejected chunks in the rejects editor.  The MQ tool also does this for
qpush commands.</p>
<div class="figure">
<img alt="Patch Rejects Editor" src="_images/rejects.png" />
<p class="caption">Resolve rejected patch chunks</p>
<p>The rejects editor is very basic.  Your source file is opened in a
QScintilla2 window for edit.  Below the source file is the list of
chunks that failed to apply to this file.  When you click on a chunk in
the list the editor jumps to the line where the chunk context was
supposed to match.  It is up to you to figure out why the chunk did not
apply and to resolve it (perhaps even by ignoring the chunk).  The
resolved/unresolved states are for your own book keeping, so you know
when all of the chunks have been dealt with.  Once you have marked all
of the chunks resolved, the <em class="guilabel">Save</em> button will become

      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/thg_logo_92x50.png" alt="Logo"/>
  <h3><a href="index.html">Table Of Contents</a></h3>
<li><a class="reference internal" href="#">7. Patches</a><ul>
<li><a class="reference internal" href="#defining-a-patch">7.1. Defining a patch</a></li>
<li><a class="reference internal" href="#pitfalls">7.2. Pitfalls</a></li>
<li><a class="reference internal" href="#export-patches">7.3. Export Patches</a><ul>
<li><a class="reference internal" href="#changeset">7.3.1. Changeset</a></li>
<li><a class="reference internal" href="#changeset-ranges">7.3.2. Changeset Ranges</a></li>
<li><a class="reference internal" href="#email">7.3.3. Email</a></li>
<li><a class="reference internal" href="#import-patches">7.4. Import Patches</a></li>
<li><a class="reference internal" href="#patch-queues">7.5. Patch Queues</a></li>
<li><a class="reference internal" href="#patch-rejects">7.6. Patch Rejects</a></li>

  <h4>Previous topic</h4>
  <p class="topless"><a href="settings.html"
                        title="previous chapter">6. Settings</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="extensions.html"
                        title="next chapter">8. Extensions</a></p>
  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="_sources/patches.txt"
           rel="nofollow">Show Source</a></li>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
<script type="text/javascript">$('#searchbox').show(0);</script>
      <div class="clearer"></div>
    <div class="related">
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
        <li class="right" >
          <a href="py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="extensions.html" title="8. Extensions"
             >next</a> |</li>
        <li class="right" >
          <a href="settings.html" title="6. Settings"
             >previous</a> |</li>
        <li><a href="index.html">TortoiseHg 2.4.0 documentation</a> &raquo;</li> 
    <div class="footer">
        &copy; Copyright 2012, Steve Borho and others.
      Created using <a href="">Sphinx</a> 1.1.3.