Annotate doesn't handle filenames with whitespace (see 
http://bugs.darcs.net/issue65)
consistently.

PopulationData.Info contains nameI and creationNameI as PackedStrings. Since 
fn2ps
is used to convert a FileName to a PackedString, all whitespace is escaped like
in the patch hunks ('a file' -> 'a\32file').

That's why
darcs annotate 'a file'
can't find 'a file' in the population because there is only a file named 
'a\32file'.

This patch uses fn2ps_no_escape for converting the FileNames to PackedStrings in
applyToPop. Another possibility would be using FileNames instead of 
PackedStrings
for the nameI and creationNameI fields.

Wed May 17 14:48:55 CEST 2006  Benedikt Schmidt <[EMAIL PROTECTED]>
  * handle filenames with whitespace in annotate (issue65)

New patches:

[handle filenames with whitespace in annotate (issue65)
Benedikt Schmidt <[EMAIL PROTECTED]>**20060517124855] 
<
> {
hunk ./FileName.lhs 24
 module FileName ( FileName( ),
                   fp2fn, fn2fp,
                   fn2ps, ps2fn,
+                  fn2ps_no_escape,
                   break_on_dir, norm_path, own_name, super_name, patch_filename,
                   (///),
                   is_malicious_filename,
hunk ./FileName.lhs 60
 ps2fn :: PackedString -> FileName
 ps2fn ps = FN $ decode_white $ unpackPSfromUTF8 ps
 
+{-# INLINE fn2ps_no_escape #-}
+fn2ps_no_escape :: FileName -> PackedString
+fn2ps_no_escape (FN fp) = packWords $ encode fp
+
 encode_white :: FilePath -> String
 encode_white (c:cs) | isSpace c || c == '\\' =
     '\\' : (show $ ord c) ++ "\\" ++ encode_white cs
hunk ./PatchApply.lhs 32
                           unlinesPS,
                           break_after_nth_newline,
                           break_before_nth_newline, )
-import FileName ( fn2ps, fn2fp, fp2fn,
+import FileName ( fn2fp, fp2fn,
+                  fn2ps_no_escape,
                   is_malicious_filename,
                 )
 import PatchInfo ( PatchInfo )
hunk ./PatchApply.lhs 447
        applyToPopTree (Split ps) tr =
         foldl (\t p -> applyToPopTree p t) tr ps
        applyToPopTree p@(FP f AddFile) tr =
-           let xxx = splitPS '/' (fn2ps  f) in
+           let xxx = splitPS '/' (fn2ps_no_escape f) in
                popChange xxx p $ fst $ breakP xxx tr
hunk ./PatchApply.lhs 449
-       applyToPopTree p@(FP f _) tr = popChange (splitPS '/' (fn2ps  f)) p tr
+       applyToPopTree p@(FP f _) tr = popChange (splitPS '/' (fn2ps_no_escape f)) p tr
        applyToPopTree p@(DP f AddDir) tr =
hunk ./PatchApply.lhs 451
-           let xxx = splitPS '/' (fn2ps  f) in
+           let xxx = splitPS '/' (fn2ps_no_escape f) in
                popChange xxx p $ fst $ breakP xxx tr
hunk ./PatchApply.lhs 453
-       applyToPopTree p@(DP d _) tr = popChange (splitPS '/' (fn2ps  d)) p tr
+       applyToPopTree p@(DP d _) tr = popChange (splitPS '/' (fn2ps_no_escape d)) p tr
        -- precondition: ``to'' does not exist yet!
        applyToPopTree (Move from to) tr
hunk ./PatchApply.lhs 456
-        = case breakP (splitPS '/' (fn2ps from)) $
-               fst $ breakP (splitPS '/' $ fn2ps to) tr of
+        = case breakP (splitPS '/' (fn2ps_no_escape from)) $
+               fst $ breakP (splitPS '/' $ fn2ps_no_escape to) tr of
            (tr',Just ins) ->
hunk ./PatchApply.lhs 459
-               let to' = (splitPS '/' (fn2ps to))
+               let to' = (splitPS '/' (fn2ps_no_escape to))
                    ins' = case ins of
                           PopDir i trs -> PopDir (i {nameI = last to',
                                                      modifiedByI = pi,
hunk ./PatchApply.lhs 492
                                         modifiedByI = pi,
                                         modifiedHowI = AddedDir,
                                         createdByI = Just pi,
-                                        creationNameI = Just $ fn2ps d}) []
+                                        creationNameI = Just $ fn2ps_no_escape d}) []
        -- only mark a directory (and contents) as ``deleted'' do not delete it actually
        popChange [path] (DP _ RmDir) tr@(PopDir f trs)
         | path == (nameI f) = PopDir (f {modifiedByI = pi,
hunk ./PatchApply.lhs 507
                                          modifiedByI = pi,
                                          modifiedHowI = AddedFile,
                                          createdByI = Just pi,
-                                         creationNameI = Just $ fn2ps d})
+                                         creationNameI = Just $ fn2ps_no_escape d})
        popChange [path] (FP _ RmFile) tr@(PopFile f)
         | path == (nameI f) = PopFile (f {modifiedByI = pi,
                                          modifiedHowI = RemovedFile})
hunk ./tests/annotate.pl 24
 my $test_name = 'record something';
 
 `date >> date.t`;
+`touch 'a file'`;
 `$DARCS add date.t`;
hunk ./tests/annotate.pl 26
+`$DARCS add 'a file'`;
 
hunk ./tests/annotate.pl 28
-like(`$DARCS record -A 'Mark Stosberg <[EMAIL PROTECTED]>' -a -m foo date.t 2>&1`, qr/finished recording/i, $test_name);
+like(`$DARCS record -A 'Mark Stosberg <[EMAIL PROTECTED]>' -a -m foo 'a file' date.t 2>&1`, qr/finished recording/i, $test_name);
 
 ####
 
hunk ./tests/annotate.pl 34
 like(`$DARCS annotate --xml date.t `,qr/&lt;[EMAIL PROTECTED]&gt;/,'annotate --xml encodes < and >');
 
+like(`$DARCS annotate 'a file'`,qr/File a file created by/,'annotate handles filenames with whitespace');
+
 chdir '../';
 `rm -rf temp1`;
 ok((!-d 'temp1'), 'temp1 directory was deleted');
}

Context:

[Fail with a sensible message when there is no default repository to pull from.
[EMAIL PROTECTED] 
[Extend test suite for patch matching.
Eric Kow <[EMAIL PROTECTED]>**20060513192501
 
] 
[Implement help --match (issue91).
Eric Kow <[EMAIL PROTECTED]>**20060513185610
 
 Also, refactor matching code in a way that encourages developers
 to document for help --match any new matchers they create.
 
] 
[Replace dateparser.sh with more general match.pl for testing --match.
Eric Kow <[EMAIL PROTECTED]>**20060513104942
 
] 
[Add tests for pristine error and quiet mode when removing a directory.
Eric Kow <[EMAIL PROTECTED]>**20060513100021] 
[Suppress non-empty dir warning if Quiet.
Eric Kow <[EMAIL PROTECTED]>**20060513053456] 
[Replace test rmdir.sh with rmdir.pl.
Eric Kow <[EMAIL PROTECTED]>**20060513043823] 
[Add forgotten file umask.h.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20060423174844] 
[Add --umask to all commands that write to the current repository.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20060407195655] 
[Add option --umask.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20060407194552] 
[Actually switch umasks in withRepoLock.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20060407194202] 
[Implement withUMask.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20060407193312] 
[Add umask.c.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20060407193255] 
[Propagate opts to withRepoLock.
Juliusz Chroboczek <[EMAIL PROTECTED]>**20060325190622] 
[Test pull.pl, CREATE_DIR_ERROR: removed TODO now that directory name is printed in error message
Marnix Klooster <[EMAIL PROTECTED]>**20060304164033
 Also removes a superfluous (and erroneous) chdir statement, which tried to
 change to non-existing directory templ (last character was ell instead of one).
 
 Also improves the description of this test.
] 
[TAG 1.0.7
Tommy Pettersson <[EMAIL PROTECTED]>**20060513171438] 
Patch bundle hash:
1a50e60df585947ef6b5b26dc2c9a6bc17ebd702
_______________________________________________
darcs-devel mailing list
[email protected]
http://www.abridgegame.org/cgi-bin/mailman/listinfo/darcs-devel

Reply via email to