Patchwork [5,of,8] histedit: allow "-" as a command file

login
register
mail settings
Submitter Pierre-Yves David
Date April 16, 2013, 7:20 p.m.
Message ID <df34ccbcce657753a631.1366140034@yamac.lan>
Download mbox | patch
Permalink /patch/1361/
State Accepted
Commit 730614b9b35291fa89221fe9d4fa0f97bcd424f6
Headers show

Comments

Pierre-Yves David - April 16, 2013, 7:20 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@logilab.fr>
# Date 1366138117 -7200
# Node ID df34ccbcce657753a6311b895278f6f82e629035
# Parent  bc6d6eba699fa8c6705c6888bc823536b40172c0
histedit: allow "-" as a command file

When "-" is specified as a command file, we read rules from stdin. We just
altered a test to demo the behavior, but most of them could benefit from this.

There is minor change in test output resulting from the fact we do not overwrite
the editor anyway.

Patch

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -141,10 +141,11 @@  repo, you can add a ``--force`` option.
 try:
     import cPickle as pickle
 except ImportError:
     import pickle
 import os
+import sys
 
 from mercurial import cmdutil
 from mercurial import discovery
 from mercurial import error
 from mercurial import copies
@@ -513,11 +514,14 @@  def histedit(ui, repo, *parent, **opts):
             # surprising happens.
             f = open(repo.join('histedit-last-edit.txt'), 'w')
             f.write(rules)
             f.close()
         else:
-            f = open(rules)
+            if rules == '-':
+                f = sys.stdin
+            else:
+                f = open(rules)
             rules = f.read()
             f.close()
         rules = [l for l in (r.strip() for r in rules.splitlines())
                  if l and not l[0] == '#']
         rules = verifyrules(rules, repo, ctxs)
diff --git a/tests/test-histedit-fold.t b/tests/test-histedit-fold.t
--- a/tests/test-histedit-fold.t
+++ b/tests/test-histedit-fold.t
@@ -48,31 +48,29 @@  Initial log
   o  1:d2ae7f538514 b'
   |
   o  0:cb9a9f314b8b a'
   
 
-  $ EDITED="$TESTTMP/editedhistory"
-  $ cat > $EDITED <<EOF
+  $ hg histedit 177f92b77385 --commands - 2>&1 <<EOF | fixbundle
   > pick e860deea161a e
   > pick 652413bf663e f
   > fold 177f92b77385 c
   > pick 055a42cdd887 d
   > EOF
-  $ HGEDITOR="cat \"$EDITED\" > " hg histedit 177f92b77385 2>&1 | fixbundle
   0 files updated, 0 files merged, 4 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 2 files removed, 0 files unresolved
   2 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
 
 log after edit
   $ hg log --graph
-  @  4:7e0a290363ed d'
+  @  4:9c277da72c9b d'
   |
-  o  3:5e24935bad3d pick e860deea161a e'
+  o  3:6de59d13424a f'
   |
   o  2:ee283cb5f2d5 e'
   |
   o  1:d2ae7f538514 b'
   |
@@ -90,11 +88,11 @@  post-fold manifest
 
 
 check histedit_source
 
   $ hg log --debug --rev 3
-  3:5e24935bad3d pick e860deea161a e'
+  3:6de59d13424a f'
 
   $ cd ..
 
 folding and creating no new change doesn't break:
 -------------------------------------------------
@@ -121,10 +119,11 @@  folded content is dropped during a merge
   o  1:617f94f13c0f +4'
   |
   o  0:0189ba417d34 1+2+3'
   
 
+  $ EDITED="$TESTTMP/editedhistory"
   $ cat > $EDITED <<EOF
   > pick 617f94f13c0f 1 +4
   > drop 888f9082bf99 2 +5
   > fold 251d831eeec5 3 +6
   > EOF