User:Sfink/Mercurial: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
(killed)
Line 1: Line 1:
== qimportbz ==
This entire page was outdated, and I don't seem to have the ability to delete.
 
* clone http://hg.mozilla.org/users/robarnold_cmu.edu/qimportbz
* put the result into the [extensions] section of your ~/.hgrc
 
The only documentation I can find says to use it by running
 
  hg qimportbz <bugnum> [options...]
 
but the version I just pulled does not define a 'qimportbz' command. What ''does'' still work is:
 
  hg qimport bz://<bugnum> [options...]
 
== conflicts ==
 
qpush creates .rej files with any conflicts.
* Open a .rej file in emacs and do ctrl-c ctrl-c to go to the corresponding source file
* ctrl-c ctrl-a re-attempts the apply (I guess that's useful if you edit the patch's context or something?)
 
I would like to know my current state with respect to those rejects, so I implemented a "delete-this-file" command in emacs and bound it to Ctrl-C Ctrl-D. That way I can easily nuke the .rej files when I have sucked their guts out.
 
<pre>
(defun delete-this-file ()
  "Delete the current buffer's file and close the buffer"
  (interactive)
  (if (y-or-n-p "Delete this file and close the buffer?")
      (progn (delete-file buffer-file-name)
    (kill-buffer))))
 
(global-set-key "\C-c\C-d" 'delete-this-file)
</pre>
 
This should really be done with a keymap or something, I think. I don't really know elisp.
 
== extensions ==
 
I am missing some of the features from Stacked Git, so I'm implementing some of them.
 
Implemented:
 
* qshow - dump out a selected patch, by name or index into your current patch set, as displayed by qseries -v. (I always use it the latter way. I don't believe in typing in patch names.)
** This should probably be a modification of the export command instead.
* qexport - dumps out the whole set of applied patches to a directory, one patch per file
** handy for attaching things to bugzilla, or generating a set of patches for an RPM build spec
** not the greatest name; should perhaps be a modification of the 'export' command instead
 
Planned:
 
* sink/float
* stg's pushing/popping behavior. Somehow it felt better in the way you could easily back out of trouble. I'll need to play with it some again. (It uses transactions of some sort.)
 
Right now, I am doing this as an 'mqext' extension that depends on mq already being loaded. I haven't published it anywhere yet. I don't know where the appropriate place is, if there is such a place. (Upstream may be the best place.) I'll probably put it on github or Mozilla's hg repo.
 
Usage (not the only way, just the way I use it):
 
* Save this as eg <code>~/mqext/__init__.py</code>
* Configure .hgrc
  [extensions]
  mqext = ~/mqext
 
  [alias]
  series = qseries -v
  show = qshow
  goto = qgoto
 
Those last two are totally unnecessary, but I like 'em.
 
* Use 'hg series', frequently, to keep track of your patch queue.
* To view an individual patch, use <code>hg show ''<index>''</code>, where <index> is the number in the first column of the 'hg series' output corresponding to the patch. This assumes you aliased qshow to 'show', which is probably a bad idea if you're used to mq commands starting with 'q'.
* To save out patches for attaching to bugzilla or whatever, do <code>hg qexport -p /tmp/d</code>. The -p option will append ".patch" to the end of the patch name when saving it out. This will save out all applied patches; I will normally then just pick one or two files out of the directory.
** If that bothers you, then just use ''show'' aka ''qshow'' to write out the patch you want and redirect it to some file. The advantage of qexport is that you don't have to type in a sensible filename; it'll use the patch name for you.
* Unrelated to this extension, use <code>hg qgoto ''<index>''</code> instead of irritating series of qpush/qpop to move around your queue. These days, I use it even when I'm only moving by 1 and could use qpush/qpop. It's much less error-prone.
 
Here's a usable snapshot:
<pre>
'''add some missing commands to the mq extension'''
 
import os
import errno
 
def qshow(ui, repo, patch=None, **opts):
    '''display a patch
 
    If no patch is given, the top of the applied stack is shown.'''
    q = repo.mq
 
    if patch is None:
        try:
            patch = q.applied[-1].name
        except:
            ui.write("No patches in series\n");
            return
 
    # Try to interpret the patch as an index into the full stack
    try:
        idx = int(patch)
        patch = q.series[idx]
    except:
        pass
 
    # This should probably dispatch to export, so that all of its
    # options could be used.
    try:
        for line in file(q.join(patch)):
            ui.write(line)
    except:
        ui.write("Invalid patch name '%s'\n" % (patch,))
 
def qexport(ui, repo, outdir, **opts):
    '''Save all applied patches into a directory'''
 
    try:
        os.mkdir(outdir)
    except OSError, inst:
        if inst.errno != errno.EEXIST:
            raise
 
    suffix = ''
    if opts['extension']:
        suffix += '.' + opts['extension']
    if opts['patch']:
        suffix += '.patch'
 
    q = repo.mq
 
    n = 0
    numlen = len(str(len(q.applied)))
 
    for p in q.applied:
        stem = p.name + suffix
        if opts['numbered']:
            stem = (('%0' + str(numlen) + 'd-') % n) + stem
        n += 1
        filename = os.path.join(outdir, stem)
 
        # This should really call p.export(...) instead of writing the
        # file directly...
        open(filename, 'w').write(file(q.join(p.name)).read())
        if ui.verbose:
            ui.write("Wrote %s\n" % filename)
 
cmdtable = {
    'qshow': (qshow, [], 'hg qshow [patch]'),
 
    'qexport':
        (qexport,
        [('p', 'patch', None, 'add .patch suffix to exported patches'),
          ('e', 'extension', '', 'append .EXTENSION to exported patches'),
          ('n', 'numbered', None, 'prefix patch names with order numbers'),
          ],
        ('hg qexport [-p] [-e EXTENSION] [-n]')),
}
</pre>
 
== Notes Gathered from Other People ==
 
=== Backing out multiple commits ===
 
From dbaron mailing list post:
 
Backing out multiple patches in a pair of commits is also pretty
trivial:
  hg up -C -rLASTPATCH
  hg revert --all --no-backup -rPARENTOFFIRSTPATCH
  hg ci -m"..."
  hg up -rOTHER-HEAD
  hg merge
  hg ci -m"..."
(though I'm not sure that will work correctly for renames / moves /
deletes)

Revision as of 19:42, 11 May 2015

This entire page was outdated, and I don't seem to have the ability to delete.