# # patch "ChangeLog" # from [63c37b88656196a7dd549876c6f79062f756db93] # to [321bfa7b9d52da2e3b3dbe2eff53794d10630cb1] # # patch "file_io.cc" # from [a887c87104212bab175b54ec1ceb1fa5153024e5] # to [da07ec92b669445496f03005c735d6b41911e422] # # patch "file_io.hh" # from [f104a889390ecd8eb031a56a81862cfef3aec01a] # to [16f383f0e4eb6fa8454fce1071880f066fc69bdb] # # patch "lua.cc" # from [60a450c0fcb35a460fdfe3a6fe4d74b5dd9612e0] # to [289aa9474f82e484b42a4db7f6280c4c6d33c088] # # patch "std_hooks.lua" # from [d7bd0756c48ace573926197709e53eb24dae5f5f] # to [a5d4006c7e8837fcd3e816c309c4fb7bee69393a] # ======================================================================== --- ChangeLog 63c37b88656196a7dd549876c6f79062f756db93 +++ ChangeLog 321bfa7b9d52da2e3b3dbe2eff53794d10630cb1 @@ -1,9 +1,3 @@ -2005-08-09 Eric Anderson - - * tests/perf-test.sh: A repeatable performance test harness - * tests/parse-accounting.pl: A script that parses the accounting - output into a nice tabular format - 2005-08-31 Matthew Gregan * paths.cc (test_bookkeeping_path, test_system_path): Second @@ -730,6 +724,12 @@ (external_path): Rename to system_path. Misc. other updates. +2005-08-21 Eric Anderson + * file_io.cc, file_io.hh, lua.cc, std_hooks.lua: determine if a + file is binary by looking at it incrementally, rather than reading + it in entirely. Prepare for making it possible to control what + characters are considered "binary" + 2005-08-20 Nathaniel Smith * paths.cc (is_absolute): New function. @@ -1429,6 +1429,12 @@ requirements, zlib as a runtime requirement. 2005-08-09 Eric Anderson + + * tests/perf-test.sh: A repeatable performance test harness + * tests/parse-accounting.pl: A script that parses the accounting + output into a nice tabular format + +2005-08-09 Eric Anderson * Changes to significantly improve network pull performance * string_queue.hh: created to store pending data and allow for ======================================================================== --- file_io.cc a887c87104212bab175b54ec1ceb1fa5153024e5 +++ file_io.cc da07ec92b669445496f03005c735d6b41911e422 @@ -1,3 +1,4 @@ +// -*- mode: C++; c-file-style: "gnu"; indent-tabs-mode: nil -*- // copyright (C) 2002, 2003 graydon hoare // all rights reserved. // licensed to the public under the terms of the GNU GPL (>= 2) @@ -123,15 +124,44 @@ return true; } -bool guess_binary(string const & s) +static bool did_char_is_binary_init; +static bool char_is_binary[256]; + +void +set_char_is_binary(char c, bool is_binary) { + char_is_binary[c] = is_binary; +} + +static void +init_char_is_binary() +{ // these do not occur in ASCII text files // FIXME: this heuristic is (a) crap and (b) hardcoded. fix both these. - if (s.find_first_of('\x00') != string::npos || - s.find_first_of("\x01\x02\x03\x04\x05\x06\x0e\x0f" - "\x10\x11\x12\x13\x14\x15\x16\x17\x18" - "\x19\x1a\x1c\x1d\x1e\x1f") != string::npos) - return true; + // Should be calling a lua hook here that can use set_char_is_binary() + // That will at least fix (b) + string nontext_chars("\x01\x02\x03\x04\x05\x06\x0e\x0f" + "\x10\x11\x12\x13\x14\x15\x16\x17\x18" + "\x19\x1a\x1c\x1d\x1e\x1f"); + set_char_is_binary('\0',true); + for(int i=0;i // all rights reserved. // licensed to the public under the terms of the GNU GPL (>= 2) @@ -22,6 +23,7 @@ #include #include +#include #include "app_state.hh" #include "file_io.hh" @@ -518,11 +520,31 @@ } static int - monotone_guess_binary_for_lua(lua_State *L) + monotone_guess_binary_filename_for_lua(lua_State *L) { const char *path = lua_tostring(L, -1); N(path, F("guess_binary called with an invalid parameter")); - lua_pushboolean(L, guess_binary(std::string(path, lua_strlen(L, -1)))); + + std::ifstream file(path, ios_base::binary); + if (!file) + { + lua_pushnil(L); + return 1; + } + const int bufsize = 8192; + string buf; + while(file.good()) + { + buf.resize(bufsize); + file.read(&buf[0],bufsize); + buf.resize(file.gcount()); + if (guess_binary(buf)) + { + lua_pushboolean(L, true); + return 1; + } + } + lua_pushboolean(L, false); return 1; } @@ -600,7 +622,7 @@ lua_register(st, "wait", monotone_wait_for_lua); lua_register(st, "kill", monotone_kill_for_lua); lua_register(st, "sleep", monotone_sleep_for_lua); - lua_register(st, "guess_binary", monotone_guess_binary_for_lua); + lua_register(st, "guess_binary_filename", monotone_guess_binary_filename_for_lua); lua_register(st, "include", monotone_include_for_lua); lua_register(st, "includedir", monotone_includedir_for_lua); } ======================================================================== --- std_hooks.lua d7bd0756c48ace573926197709e53eb24dae5f5f +++ std_hooks.lua a5d4006c7e8837fcd3e816c309c4fb7bee69393a @@ -131,10 +131,7 @@ if (string.find(lowname, "%.sql$")) then return false end -- unknown - read file and use the guess-binary -- monotone built-in function - filedata=read_contents_of_file(name, "rb") - if (filedata ~= nil) then return guess_binary(filedata) end - -- still unknown (file empty or unreadable) - report it as nil - return nil + return guess_binary_filename(name) end function edit_comment(basetext, user_log_message)