monotone-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Monotone-devel] "mtn cat" text/binary impedence mismatch


From: Larry Hastings
Subject: Re: [Monotone-devel] "mtn cat" text/binary impedence mismatch
Date: Wed, 08 Nov 2006 23:29:58 -0800
User-agent: Thunderbird 1.5.0.8 (Windows/20061025)

Nathaniel Smith wrote:
On Wed, Nov 08, 2006 at 08:46:00AM -0800, Larry Hastings wrote:
  
   So here's a patch that I think will fix the problem.
    
Can someone who can actually write a test for this review it? :-)
Oh!  Good point.  Sorry for not writing a test to begin with.

Unfortunately, I don't really know Lua, so the test driver is even less tested than the patch.  Yes, it actually has had negative testing so far.  It is my hope that some kind soul will fix whatever errors are in the patch and repost it.

Cheers,


larry

-----


#
# old_revision [a842d70f3a7546ec5c1af5d4c2eef7caddc9f511]
#
# add_dir "tests/cat_preserves_eol"
#
# add_file "tests/cat_preserves_eol/__driver__.lua"
#  content [3d2c610e13755a63fe857ce7d045500a9a23a03c]
#
# patch "cmd_files.cc"
#  from [12243e3b47340b2aa81cd8e26f40559fad0ab51d]
#    to [70689ad71003c87e72aa02699e56744c99e5cb80]
#
# patch "platform.hh"
#  from [7224b228b7c8f0476b45ed5fb929aba4d6878fd5]
#    to [5959e7ef02930e75c3baa9b36b2b9869a148f837]
#
# patch "win32/make_io_binary.cc"
#  from [e1ab402f330f608d17714ec0d04878b99feebc97]
#    to [55fb0a7a07b64f97dfba944836537d231f2f73bb]
#
============================================================
--- tests/cat_preserves_eol/__driver__.lua    3d2c610e13755a63fe857ce7d045500a9a23a03c
+++ tests/cat_preserves_eol/__driver__.lua    3d2c610e13755a63fe857ce7d045500a9a23a03c
@@ -0,0 +1,23 @@
+--
+-- test to ensure that "mtn cat file" does not write out binary files in text mode,
+-- thereby munging the contents.
+--
+
+mtn_setup()
+
+-- take this text...
+original_contents = "look, a windows eol\r\nand a unix eol\nand an old-skool mac eol\rand another windows one\r\n"
+
+-- ... and check it in as "eol/file.binary"
+mkdir("eol")
+check(mtn("--branch=testbranch", "setup", "eol"), 0, false, false)
+writefile("eol/file.binary", original_contents)
+check(indir("eol", mtn("add", "file.binary")), 0, false, false)
+check(indir("eol", mtn("commit", "-m", 'add file')), 0, false, false)
+
+-- now "cat" the file, capturing stdout (to . not ./eol)
+check(indir("eol", mtn("cat", "file.binary")), 0, true, false)
+
+-- the contents of "stdout" should now be the same as the contents of "file.binary"
+check(samefile("stdout", "eol/file.binary"))
+
============================================================
--- cmd_files.cc    12243e3b47340b2aa81cd8e26f40559fad0ab51d
+++ cmd_files.cc    70689ad71003c87e72aa02699e56744c99e5cb80
@@ -218,7 +218,9 @@ CMD(cat, N_("informative"),
   file_data dat;
   L(FL("dumping file '%s'") % ident);
   app.db.get_file_version(ident, dat);
+  make_io_binary(true);
   cout.write(dat.inner()().data(), dat.inner()().size());
+  make_io_binary(false);
 
   guard.commit();
 }
============================================================
--- platform.hh    7224b228b7c8f0476b45ed5fb929aba4d6878fd5
+++ platform.hh    5959e7ef02930e75c3baa9b36b2b9869a148f837
@@ -34,7 +34,7 @@ int process_sleep(unsigned int seconds);
 int process_sleep(unsigned int seconds);
 
 // stop "\n"->"\r\n" from breaking automate on Windows
-void make_io_binary();
+void make_io_binary(bool make_binary = true);
 
 #ifdef WIN32
 std::string munge_argv_into_cmdline(const char* const argv[]);
============================================================
--- win32/make_io_binary.cc    e1ab402f330f608d17714ec0d04878b99feebc97
+++ win32/make_io_binary.cc    55fb0a7a07b64f97dfba944836537d231f2f73bb
@@ -6,9 +6,9 @@
 
 #include "platform.hh"
 
-void make_io_binary()
+void make_io_binary(bool make_binary)
 {
-  _setmode(_fileno(stdin), _O_BINARY);
-  _setmode(_fileno(stdout), _O_BINARY);
+  _setmode(_fileno(stdin), make_binary ? _O_BINARY : _O_TEXT);
+  _setmode(_fileno(stdout), make_binary ? _O_BINARY : _O_TEXT);
 }
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]