encode/decode filter weirdness

Matt Mackall mpm at selenic.com
Tue Sep 20 15:53:13 CDT 2005


On Mon, Sep 19, 2005 at 05:43:13PM -0700, Maquelin, Olivier wrote:
> Experimenting with encode/decode filters to convert CRLF <-> LF led to
> some behaviors I could not explain. The following was run under Linux
> using the 0.7 release of Mercurial.
> 
> Starting with a fresh repository, hgrc set up to call my 'txt2unix'
> filter (turns CRLF into LF) and a file containing CRLFs:
> 
> [~/foo] cat .hg/hgrc
> [encode]
> *.txt = txt2unix
> [~/foo] ls
> foo.txt
> [~/foo] od -a foo.txt
> 0000000   o   n   e  cr  nl   t   w   o  cr  nl
> 0000012
> 
> Now I commit the new file and check its contents:
> 
> [~/foo] hg addremove
> adding foo.txt
> [~/foo] hg commit -m "test"
> [~/foo] hg status
> [~/foo] od -a foo.txt
> 0000000   o   n   e  cr  nl   t   w   o  cr  nl
> 0000012
> 
> So far no big surprises. foo.txt still contains the CRLFs, but the
> internal representation should be the canonical one with LFs. It might
> be nice for 'hg status' to tell us that the directory contents do not
> match what would be retrieved from the repository, but that is not a
> terribly big deal.

The filters are applied in exactly two places:

 - reading files from the working directory
 - writing files to the working directory

Thus, the Mercurial internals never see files except in their
canonicalized form. For instance, checking whether a file is changed
is done by reading it from the working directory (w/filter) and
comparing it to what's in the repo (unfiltered).

> Now let's try to extract the canonical representation from the
> repository by deleting the file and having it re-created:
> 
> [~/foo] rm foo.txt 
> [~/foo] hg status
> R foo.txt
> [~/foo] hg revert
> [~/foo] hg status
> M foo.txt
> [~/foo] hg diff
> [~/foo] od -a foo.txt
> 0000000   o   n   e  nl   t   w   o  nl
> 0000010
> 
> The file contents are as expected, but why is 'hg status' reporting the
> file as being modified?

Because the revert command changed the size of the file without
changing the dirstate. The file is indeed changed.

If your filters are not matched, you'll get interesting results.

-- 
Mathematics is the supreme nostalgia of our time.


More information about the Mercurial mailing list