Differences between revisions 26 and 27
Revision 26 as of 2011-09-28 04:48:02
Size: 6756
Editor: TKSoh
Comment: now works with Hg 1.9
Revision 27 as of 2011-10-23 07:04:53
Size: 6893
Editor: broadband-188-32-136-141
Comment:
Deletions are marked like this. Additions are marked like this.
Line 141: Line 141:
 Can you try out my [[Aurum]] plugin for Vim? It has AuRecord command that is as well makes you able to edit commited changes. --ZyX

Shelve Extension

This extension is not distributed with Mercurial.

Author: TK Soh <teekaysoh@gmail.com>

Repository: http://bitbucket.org/tksoh/hgshelve/

1. Overview

The shelve extension provides the shelve command to let you choose which parts of the changes in a working directory you'd like to set aside temporarily, at the granularity of patch hunks. You can later restore the shelved patch hunks using the unshelve command.

The shelve extension has been adapted from Mercurial's RecordExtension.

2. Compatibility with Mercurial

Mercurial

Shelve Extension

1.9.x

53dbf2e68dc6 or later

1.6.x - 1.8.x

41e13e800fb6 or later

1.5.x

d95c583611f8 or later

1.4.x

276d8083dc3b or later

1.3.x

18815655993b or later

1.1.x - 1.2.x

7090a3ed2da7

< 1.1.x

ef85a6331d31

3. Configuration

Configure your .hgrc to enable the extension by adding following lines:

[extensions]
hgshelve=/path/to/hgshelve.py

or place hgshelve.py in your 'hgext' directory and add the following lines:

[extensions]
hgext.hgshelve=

If you use the win32text extension, make sure you have the following lines in your .hgrc or mercurial.ini. This enables automatic line-ending translation when applying patches.

[patch]
eol = auto

4. Usage

(this is only a description of the basic usage)

hg shelve

Temporarily stash away changes. You can select the exact hunks of changes you want to shelve.

hg shelve --all

Temporarily stash away changes. All hunks will automatically be selected.

hg unshelve

Get the changes back into the workdir.

5. Shelves

Different changesets can be saved to different shelves, by using the --name parameter. Without this parameter, the shelf name "default" is used. You can have any number of shelves at one time.

hg shelve --name myshelf

Temporarily stash away changes to the shelf myshelf. Any changes already shelved to a different shelf will not be included.

hg shelve --name myshelf --append

Add any changes to the existing shelf myshelf.

hg unshelve --name myshelf

Get the changes stashed away to the shelf myshelf back into the workdir, and remove the shelf. Any changes shelved to a different shelf will not be included.

hg shelve --list

List all current shelves.

6. Hunk selection

y - shelve this change
n - skip this change

s - skip remaining changes to this file
f - shelve remaining changes to this file

d - done, skip remaining changes and files
a - shelve all changes to all remaining files
q - quit, shelveing no changes

? - display help

7. See also

AtticExtension

8. Feature Requests

I'd like to copy this comment from the RecordExtension page, as it equally applies here (and I think even more because the workflow of removing unnecessary things first, then checking the result and then committing it is much more natural than just committing parts of your workspace and hope for the best.

I would really like to have the ability to split hunks in this plugin. The problem is, that if there are multiple adjacent changes that have nothing to do with each other (like two new functions right next to each other) it is downright hard to commit them separately short of removing one, comitting and adding the other one again. --MartinHäcker

  • Me too. git has this handy feature. --LesliePolzer

    • How does git do this? --ThurnerRupert

      • When using git add -p, you will enter the interactive mode, and do something similar with darcs|hg record. But in git you've the choice of 'e' to open up an editor, and edit the patch. There is an example[1] at the footer of this page. --WeakishJiang

  • Yes, this feature of darcs record is missing. It would be great to have it. As described below, git does have it - using the e option to open an editor, like in darcs. However, I like the darcs approach, with a "before" and "after" section, better than the git approach of editing "+" and "-" markers. I find it cleaner. --YitzGale

    fyi: this has been available for some time with the CrecordExtension (based on RecordExtension), so maybe it wouldn't be too hard to incorporate some of the changes back into record. --MarkEdgington

    • crecord uses a curses interface, but record uses merely command line. so it's not very easy to specify how to split the hunks in record. Besides, crecord provides line-level granularity, which in most case is sufficient. But in some edge cases, we may have two changes doing different things in one line. The best practice I can think of right now is git's approach (manually editing the patch) explained above. --WeakishJiang

      I find crecord to be really clunky when dealing with sizable patches. It's slow, and requires me to scroll a lot unnecessarily. In addition to the (decent) interface in [1], git also has a powerful "interactive" interface. It's not user-friendly, but once you figure it out, it's much more efficient than crecord, and much more powerful than record. --JustinLebar

    Can you try out my Aurum plugin for Vim? It has AuRecord command that is as well makes you able to edit commited changes. --ZyX


Footnotes:

[1] a git example:

   1 $ git add -p f.c
   2 diff --git a/f.c b/f.c
   3 index a32488e..cf4b43e 100644
   4 --- a/f.c
   5 +++ b/f.c
   6 @@ -1,2 +1,4 @@
   7 -void splodge(int c) {
   8 +int blorf() { return s_blorfulocity / s_RAT; }
   9 +
  10 +void splodge(long c) {
  11  }
  12 Stage this hunk [y/n/a/d/e/?]? e
  13 
  14 4) External editor opens up with this content
  15 # Manual hunk edit mode -- see bottom for a quick guide
  16 @@ -1,2 +1,4 @@
  17 -void splodge(int c) {
  18 +int blorf() { return s_blorfulocity / s_RAT; }
  19 +
  20 +void splodge(long c) {
  21  }
  22 # ---
  23 # To remove '-' lines, make them ' ' lines (context).
  24 # To remove '+' lines, delete them.
  25 # Lines starting with # will be removed.
  26 #
  27 # If the patch applies cleanly, the edited hunk will immediately be
  28 # marked for staging. If it does not apply cleanly, you will be given
  29 # an opportunity to edit again. If all lines of the hunk are removed,
  30 # then the edit is aborted and the hunk is left unchanged.



CategoryExtensionsByOthers

ShelveExtension (last edited 2020-07-05 06:29:48 by DanKurtz)