[PATCH] export: make -o foo overwrite, not append

Matt Mackall mpm at selenic.com
Fri Oct 5 17:26:27 CDT 2012


On Thu, 2012-10-04 at 16:10 -0500, Kevin Bullock wrote:
> On Oct 4, 2012, at 1:54 PM, Jordi Gutiérrez Hermoso wrote:
> 
> > On 4 October 2012 14:08, Kevin Bullock <kbullock+mercurial at ringworld.org> wrote:
> >> On Oct 4, 2012, at 12:41 PM, Jordi Gutiérrez Hermoso wrote:
> >> 
> >>> # HG changeset patch
> >>> # User Jordi Gutiérrez Hermoso <jordigh at octave.org>
> >>> # Date 1349372425 14400
> >>> # Node ID 80eea80279e6804128b828da97ff57c1da89a07c
> >>> # Parent  fa714f3ed2989aff64c267c9935251d9fc4f31ee
> >>> export: make -o foo overwrite, not append
> >>> 
> >>> Currently, "hg export -r foo -o bar" appends the results to bar, which
> >>> is mentioned nowhere in the documentation. This confuses users who
> >>> expect to get only one change in there, not several. This cset just
> >>> makes the -o option overwrite, not append.
> >> 
> >> I agree that that's surprising behavior, especially when exporting
> >> multiple changes with a parameterized file name spec. But it appears
> >> to go back to this:
> >> 
> >> changeset:   7319:eae1767cc6a8
> >> user:        Ronny Pfannschmidt <Ronny.Pfannschmidt at gmx.de>
> >> date:        Thu Nov 06 11:17:38 2008 +0100
> >> files:       mercurial/cmdutil.py mercurial/patch.py tests/test-export tests/test-export.out
> >> description:
> >> export: fixed silent output file overwriting
> >> 
> >> hg export -o outfile 1 2 3 4 had the same effect as hg -o outfile 4
> >> 
> >> This was caused by opening with 'w' instead of 'a'. This only occurs when
> >> the filename pattern resulted in ambiguous patch filenames.
> > 
> > So, should the current behaviour stay? Then it should be documented.
> > Should I do that?
> 
> I suspect that we actually want to do something more nuanced here. If
> we only have a single output file, we may want to keep the current
> append behavior (or might not, in which case we still want to preserve
> the ability to export multiple changesets to a single file). But for
> multiple files (i.e., multiple changes being exported AND a
> parameterized OUTFILESPEC), we probably want to either abort or
> overwrite.

We want to overwrite old files. But we also want to gather patches into
files from the current command. Which suggests we want to keep track of
which files we've visited and adjust the mode accordingly:

if f in seen:
    mode = 'a'
else:
    mode = 'o'
    seen.add(f)

-- 
Mathematics is the supreme nostalgia of our time.




More information about the Mercurial-devel mailing list