[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone: 01d48aa4dce0b565ff49caa10a
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone: 01d48aa4dce0b565ff49caa10a49f38ee79176b7 |
Date: |
Tue, 8 Mar 2011 13:54:41 +0100 (CET) |
revision: 01d48aa4dce0b565ff49caa10a49f38ee79176b7
date: 2011-03-08T12:54:29
author: Richard Levitte <address@hidden>
branch: net.venge.monotone
changelog:
* contrib/monotone-cvs-ignore.lua: Moved ...
* extra/mtn-hooks/monotone-cvs-ignore.lua: ... here. Modified to care
for already existing implementations of ignore_file() and to not raise
a warning of the file ".cvsignore" is missing.
* test/extra/cvs-ignore/__driver__.lua: New test driver for
monotone-cvs-ignore.lua.
manifest:
format_version "1"
new_manifest [c183a38a505414ad0ba566c7f152b174f6e9b3ef]
old_revision [c010d66fb90f5309f364a070baca780fe9b2c1c5]
rename "contrib/monotone-cvs-ignore.lua"
to "extra/mtn-hooks/monotone-cvs-ignore.lua"
add_dir "test/extra/cvs-ignore"
add_file "test/extra/cvs-ignore/__driver__.lua"
content [6ac0f69cbfdb9a85330fe127ce16c101af74be76]
patch "extra/mtn-hooks/monotone-cvs-ignore.lua"
from [9d8fe793ab5c6f3a5c21f534ceedea2796ee58eb]
to [7bc64a29dac6409b2dbfbda0b3458ccc5b5fdc46]
============================================================
--- contrib/monotone-cvs-ignore.lua 9d8fe793ab5c6f3a5c21f534ceedea2796ee58eb
+++ extra/mtn-hooks/monotone-cvs-ignore.lua 7bc64a29dac6409b2dbfbda0b3458ccc5b5fdc46
@@ -1,27 +1,37 @@
-function glob_to_pattern(glob)
- local pattern
+do
+
+ local _glob_to_pattern = function (glob)
+ local pattern
- -- escape all special characters:
- pattern = string.gsub(glob, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
+ -- escape all special characters:
+ pattern = string.gsub(glob, "([%^%$%(%)%%%.%[%]%*%+%-%?])", "%%%1")
- -- convert the glob's ones to pattern's:
- pattern = string.gsub(pattern, "%%%*", "[^/]*")
- pattern = string.gsub(pattern, "%%%?", ".")
+ -- convert the glob's ones to pattern's:
+ pattern = string.gsub(pattern, "%%%*", "[^/]*")
+ pattern = string.gsub(pattern, "%%%?", ".")
- return pattern
-end
+ return pattern
+ end
-function ignore_file(name)
- local dir, pat1, pat2
+ local old_ignore_file = ignore_file
+ function ignore_file(name)
+ local dir, pat1, pat2
- dir = string.gsub(name, "/[^/]+$", "/")
- if (dir == name) then dir = "" end
- pat1 = "^" .. glob_to_pattern(dir)
-
- for line in io.lines(dir .. ".cvsignore") do
- pat2 = glob_to_pattern(line) .. "$"
- if (string.find(name, pat1 .. pat2)) then return true end
- end
+ dir = string.gsub(name, "/[^/]+$", "/")
+ if (dir == name) then dir = "" end
+ pat1 = "^" .. _glob_to_pattern(dir)
- return false
+ local handle, msg = io.open(dir .. ".cvsignore")
+ if (handle) then
+ for line in handle:lines(dir .. ".cvsignore") do
+ pat2 = _glob_to_pattern(line) .. "$"
+ if (string.find(name, pat1 .. pat2)) then
+ return true
+ end
+ end
+ io.close(handle)
+ end
+
+ return old_ignore_file(name)
+ end
end
============================================================
--- /dev/null
+++ test/extra/cvs-ignore/__driver__.lua 6ac0f69cbfdb9a85330fe127ce16c101af74be76
@@ -0,0 +1,33 @@
+mtn_setup()
+
+-- Prepare the test by copying the lua hook to test
+-- and adding a few lines to test_hooks.lua
+mkdir("hooks.d")
+check(copy(srcdir.."/../extra/mtn-hooks/monotone-cvs-ignore.lua",
+ "hooks.d/monotone-cvs-ignore.lua"))
+
+append("test_hooks.lua", "\
+\
+includedirpattern(get_confdir() .. \"/hooks.d\",\"*.conf\")\
+includedirpattern(get_confdir() .. \"/hooks.d\",\"*.lua\")\
+")
+
+-- Do the test
+writefile("test1.txt", "foo")
+mkdir("subdir")
+writefile("subdir/test2.txt", "foo")
+
+check(mtn("ls","unknown"), 0, true, false)
+check(grep("^test1\\.txt$", "stdout"), 0, false, false)
+
+writefile("subdir/.cvsignore", "*.txt")
+
+check(mtn("ls","unknown"), 0, true, false)
+check(grep("^test1\\.txt$", "stdout"), 0, false, false)
+check(grep("^subdir/test2\\.txt$", "stdout"), 1, false, false)
+
+writefile(".cvsignore", "*.txt")
+
+check(mtn("ls","unknown"), 0, true, false)
+check(grep("^test1\\.txt$", "stdout"), 1, false, false)
+check(grep("^subdir/test2\\.txt$", "stdout"), 1, false, false)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone: 01d48aa4dce0b565ff49caa10a49f38ee79176b7,
code <=