[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Monotone-commits-diffs] net.venge.monotone.issue-148-80: 5b75e024b5f764
From: |
code |
Subject: |
[Monotone-commits-diffs] net.venge.monotone.issue-148-80: 5b75e024b5f764b49703ce0135328fc5f78834b6 |
Date: |
Tue, 7 Aug 2012 14:08:19 +0200 (CEST) |
revision: 5b75e024b5f764b49703ce0135328fc5f78834b6
date: 2012-08-07T11:20:53
author: address@hidden
branch: net.venge.monotone.issue-148-80
changelog:
rationalize --recursive for ls, add; issues 148, 80.
* doc/monotone.texi: doc changes in ls, add
* src/cmd_list.cc (get_unknown_ignored): add recurse arg
(CMD ls unknown): accept --recursive; default to true
(CMD ls ignored): accept --recursive; default to true
* src/cmd_ws_commit.cc (perform_add): handle recursive consistently between
--unknown and normal
* src/work.cc (file_itemizer): accept explicit recurse argument
(file_itemizer::visit_dir): use recurse arg, ignored; not known.
(addition_builder::visit_dir): same algorithm as file_itemizer; delete warning
(find_unknown_and_ignored): add recurse arg
* test/func/add_unknown_recursive: deleted test; redundant with
addition_of_files_and_directories
* test/func/addition_of_files_and_directories/__driver__.lua: improve comments,
clarity
* test/func/ls_unknown/__driver__.lua: improve, test --no-recursive
* test/func/things_in_.mtn-ignore_get_ignored/__driver__.lua: improve comments,
add --no-recursive
* test/func/two_parent_workspace_list/__driver__.lua: add --no-recursive
manifest:
format_version "1"
new_manifest [cfaa1d5e17edb0d5604b2c37263fafb5c151ab6a]
old_revision [5fc5ee39e5df44a9c65bfded2dca132082d96794]
delete "test/func/add_unknown_recursive"
delete "test/func/add_unknown_recursive/__driver__.lua"
patch "doc/monotone.texi"
from [31b5e777afe82c7a55b7134e15e356f29773e976]
to [b9b168c12543873d190353126c3cd3172c12df47]
patch "src/cmd_list.cc"
from [5eee1fff3753df893cfc1325d362f6bc8445dd11]
to [a0103f85cfb0c0e36fe33f3bad41e321cf1d5dcc]
patch "src/cmd_ws_commit.cc"
from [78e02629916d649d7eed18480e05ede5f4b19971]
to [9c041c3ec231af27f63333af4ca73b69dfd9983c]
patch "src/work.cc"
from [324996c07f4fc5bda6e32d20eac172b35db759cf]
to [82c6964129b93b16d99da1dc34d241dedda570d5]
patch "src/work.hh"
from [520ff77cc8bc9655d3826388f06dda29de9292d0]
to [b3fd4ec1187a85bd63081775e15471d692be2923]
patch "test/func/addition_of_files_and_directories/__driver__.lua"
from [0051df02ca4bdb2c88e5931b087aaa6b3b0e67e5]
to [a92d8e5231833e0f5146e04248c30eb31e82029e]
patch "test/func/ls_unknown/__driver__.lua"
from [db94178a695f12c74d0c083a83a3ead65ea257b7]
to [6654ef88997747a089cb73f7c6e7ff7ddd44d6a8]
patch "test/func/things_in_.mtn-ignore_get_ignored/__driver__.lua"
from [2b1974541199d82c39a4c9529f9d85d2bf5c7106]
to [e782689702a5ed0d977d1610dd7c06df505cdb1d]
patch "test/func/two_parent_workspace_list/__driver__.lua"
from [5d6df31659e888cf21e541121d487d3e5249e2df]
to [2a365be32c664d756c0187954ca84c79590558fd]
============================================================
--- doc/monotone.texi 31b5e777afe82c7a55b7134e15e356f29773e976
+++ doc/monotone.texi b9b168c12543873d190353126c3cd3172c12df47
@@ -5270,13 +5270,13 @@ @section Workspace
As a convenience, the @option{--unknown @var{pathname...}} option can be used;
this option will cause all of the files listed by @command{mtn list
-unknown @var{pathname...}} to be added.
+unknown @var{pathname...}} to be added. However, note that the default
+for @command{list unknown} is @option{--recursive}, while the default
+for @command{add} is @option{--no-recursive}.
Adding directories, whether explicitly or using the @option{--unknown}
option, is non-recursive by default. The @command{add} command can be
-made recursive using the @option{--recursive} option. When adding a
-directory non-recursively, monotone will warn if the directory has
-any files that would be added by a recursive add.
+made recursive using the @option{--recursive} option.
@anchor{mtn address@hidden mtn attr
Manage @ref{File Attributes}.
@@ -6144,7 +6144,7 @@ @section Informative
Two or more files are considered duplicates if the @sc{sha1} hashes of their
contents are equal.
address@hidden mtn list ignored address@hidden
address@hidden mtn list ignored [--[no-]recursive] address@hidden
@itemx mtn ls ignored
@command{ls ignored} is an alias for @command{list ignored}.
@@ -6161,6 +6161,11 @@ @section Informative
Specifying only the pathname "." will restrict the search for ignored
files to the current subdirectory of the workspace.
+Default is @option{--recursive}; all directories will be
+traversed. Specifying @option{--no-recursive} restricts the listing to
+the root directory of the specified path (or the workspace, if no path
+is given).
+
@item mtn list keys address@hidden
@itemx mtn ls keys
@command{ls keys} is an alias for @command{list keys}.
@@ -6212,7 +6217,7 @@ @section Informative
given @var{pattern} (default all tags). If @option{--exclude}
options are provided they are used as globs to exclude specified tags.
address@hidden mtn list unknown address@hidden
address@hidden mtn list unknown [--[no-]recursive] address@hidden
@itemx mtn ls unknown
@command{ls unknown} is an alias for @command{list unknown}.
@@ -6228,6 +6233,11 @@ @section Informative
Specifying only the pathname "." will restrict the search for unknown
files to the current subdirectory of the workspace.
+Default is @option{--recursive}; all directories will be
+traversed. Specifying @option{--no-recursive} restricts the listing to
+the root directory of the specified path (or the workspace, if no path
+is given).
+
@itemx mtn list vars address@hidden
@itemx mtn ls vars
@command{ls vars} is an alias for @command{list vars}.
============================================================
--- src/cmd_list.cc 5eee1fff3753df893cfc1325d362f6bc8445dd11
+++ src/cmd_list.cc a0103f85cfb0c0e36fe33f3bad41e321cf1d5dcc
@@ -1,4 +1,5 @@
// Copyright (C) 2002 Graydon Hoare <address@hidden>
+// Copyright (C) 2012 Stephen Leake <address@hidden>
//
// This program is made available under the GNU GPL version 2.0 or
// greater. See the accompanying file COPYING for details.
@@ -784,6 +785,7 @@ static void get_unknown_ignored(app_stat
static void get_unknown_ignored(app_state & app,
args_vector const & args,
+ bool recurse,
set<file_path> & unknown,
set<file_path> & ignored)
{
@@ -798,28 +800,36 @@ static void get_unknown_ignored(app_stat
if (roots.empty())
roots.push_back(file_path());
- work.find_unknown_and_ignored(db, mask, roots, unknown, ignored);
+ work.find_unknown_and_ignored(db, mask, recurse, roots, unknown, ignored);
}
+CMD_PRESET_OPTIONS(unknown)
+{
+ opts.recursive=true;
+}
CMD(unknown, "unknown", "", CMD_REF(list), "[PATH]",
N_("Lists workspace files that are unknown in the current branch"),
"",
- options::opts::depth | options::opts::exclude)
+ options::opts::depth | options::opts::exclude | options::opts::recursive)
{
set<file_path> unknown, _;
- get_unknown_ignored(app, args, unknown, _);
+ get_unknown_ignored(app, args, app.opts.recursive, unknown, _);
copy(unknown.begin(), unknown.end(),
ostream_iterator<file_path>(cout, "\n"));
}
+CMD_PRESET_OPTIONS(ignored)
+{
+ opts.recursive=true;
+}
CMD(ignored, "ignored", "", CMD_REF(list), "[PATH]",
N_("Lists workspace files that are ignored in the current branch"),
"",
- options::opts::depth | options::opts::exclude)
+ options::opts::depth | options::opts::exclude | options::opts::recursive)
{
set<file_path> _, ignored;
- get_unknown_ignored(app, args, _, ignored);
+ get_unknown_ignored(app, args, app.opts.recursive, _, ignored);
copy(ignored.begin(), ignored.end(),
ostream_iterator<file_path>(cout, "\n"));
============================================================
--- src/cmd_ws_commit.cc 78e02629916d649d7eed18480e05ede5f4b19971
+++ src/cmd_ws_commit.cc 9c041c3ec231af27f63333af4ca73b69dfd9983c
@@ -751,29 +751,38 @@ void perform_add(app_state & app,
workspace & work,
vector<file_path> roots)
{
- set<file_path> paths;
bool add_recursive = app.opts.recursive;
if (app.opts.unknown)
{
path_restriction mask(roots, args_to_paths(app.opts.exclude),
app.opts.depth, ignored_file(work));
+ set<file_path> unknown;
set<file_path> ignored;
// if no starting paths have been specified use the workspace root
if (roots.empty())
roots.push_back(file_path());
- work.find_unknown_and_ignored(db, mask, roots, paths, ignored);
+ work.find_unknown_and_ignored(db, mask, add_recursive, roots, unknown, ignored);
- work.perform_additions(db, ignored,
- add_recursive, !app.opts.no_ignore);
+ // This does nothing unless --no-ignore is given
+ work.perform_additions(db, ignored, add_recursive, !app.opts.no_ignore);
+
+ // No need for recursion here; all paths to be added are explicit in unknown
+ work.perform_additions(db, unknown, false, true);
}
else
- paths = set<file_path>(roots.begin(), roots.end());
-
- work.perform_additions(db, paths, add_recursive, !app.opts.no_ignore);
+ {
+ // There are at most two roots in a workspace
+ set<file_path> paths = set<file_path>(roots.begin(), roots.end());
+ work.perform_additions(db, paths, add_recursive, !app.opts.no_ignore);
+ }
}
+CMD_PRESET_OPTIONS(add)
+{
+ opts.recursive=false; // match 'ls unknown' and 'add --unknown --recursive'
+}
CMD(add, "add", "", CMD_REF(workspace), N_("[PATH]..."),
N_("Adds files to the workspace"),
"",
============================================================
--- src/work.cc 324996c07f4fc5bda6e32d20eac172b35db759cf
+++ src/work.cc 82c6964129b93b16d99da1dc34d241dedda570d5
@@ -1007,12 +1007,14 @@ struct file_itemizer : public tree_walke
set<file_path> & unknown;
set<file_path> & ignored;
path_restriction const & mask;
+ bool const recurse;
file_itemizer(database & db, workspace & work,
set<file_path> & k,
set<file_path> & u,
set<file_path> & i,
- path_restriction const & r)
- : db(db), work(work), known(k), unknown(u), ignored(i), mask(r) {}
+ path_restriction const & r,
+ bool recurse)
+ : db(db), work(work), known(k), unknown(u), ignored(i), mask(r), recurse(recurse) {}
virtual bool visit_dir(file_path const & path);
virtual void visit_file(file_path const & path);
};
@@ -1022,7 +1024,8 @@ file_itemizer::visit_dir(file_path const
file_itemizer::visit_dir(file_path const & path)
{
this->visit_file(path);
- return known.find(path) != known.end();
+ // Don't recurse into ignored directories, even for 'ls ignored'.
+ return recurse && ignored.find(path) == ignored.end();
}
void
@@ -1141,60 +1144,8 @@ addition_builder::visit_dir(file_path co
bool
addition_builder::visit_dir(file_path const & path)
{
- struct directory_has_unignored_files_exception {};
- struct directory_has_unignored_files : public dirent_consumer
- {
- directory_has_unignored_files(workspace & work, file_path const & p)
- : work(work), p(p) {}
- virtual void consume(char const * s)
- {
- try
- {
- file_path entry = p / path_component(s);
- if (!work.ignore_file(entry))
- throw directory_has_unignored_files_exception();
- }
- catch (std::logic_error)
- {
- // ignore this file for purposes of the warning; this file
- // wouldn't have been added by a recursive add anyway.
- }
- }
- private:
- workspace & work;
- file_path const & p;
- };
-
- if (!recursive)
- {
- bool warn = false;
-
- // If the db can ever be stored in a dir
- // then revisit this logic
- I(!db.is_dbfile(path));
-
- if (!respect_ignore)
- warn = !directory_empty(path);
- else if (!work.ignore_file(path))
- {
- directory_has_unignored_files dhuf(work, path);
- try
- {
- read_directory(path, dhuf, dhuf, dhuf);
- }
- catch (directory_has_unignored_files_exception)
- {
- warn = true;
- }
- }
-
- if (warn)
- W(F("non-recursive add: Files in the directory '%s' "
- "will not be added automatically.") % path);
- }
-
this->visit_file(path);
- return true;
+ return recursive && (!respect_ignore || !work.ignore_file(path));
}
void
@@ -1781,6 +1732,7 @@ workspace::find_unknown_and_ignored(data
void
workspace::find_unknown_and_ignored(database & db,
path_restriction const & mask,
+ bool recurse,
vector<file_path> const & roots,
set<file_path> & unknown,
set<file_path> & ignored)
@@ -1792,7 +1744,7 @@ workspace::find_unknown_and_ignored(data
get_current_roster_shape(db, nis, new_roster);
new_roster.extract_path_set(known);
- file_itemizer u(db, *this, known, unknown, ignored, mask);
+ file_itemizer u(db, *this, known, unknown, ignored, mask, recurse);
for (vector<file_path>::const_iterator
i = roots.begin(); i != roots.end(); ++i)
{
============================================================
--- src/work.hh 520ff77cc8bc9655d3826388f06dda29de9292d0
+++ src/work.hh b3fd4ec1187a85bd63081775e15471d692be2923
@@ -138,6 +138,7 @@ public:
void find_unknown_and_ignored(database & db,
path_restriction const & mask,
+ bool recurse,
std::vector<file_path> const & roots,
std::set<file_path> & unknown,
std::set<file_path> & ignored);
============================================================
--- test/func/add_unknown_recursive/__driver__.lua 5660b8f315d9ced31c4c9115cd7404bce44b7d36
+++ /dev/null
@@ -1,13 +0,0 @@
-
-mtn_setup()
-
-mkdir("adddir")
-writefile("adddir/test.txt", "A test file that won't be added unless --recursive is used\n")
-
-check(mtn("add", "--unknown"), 0, false, false)
-check(mtn("ls", "known"), 0, true, false)
-check(not qgrep("adddir/test.txt", "stdout"))
-check(mtn("drop", "--bookkeep-only", "adddir"), 0, true, false)
-check(mtn("add", "--unknown", "--recursive"), 0, false, false)
-check(mtn("ls", "known"), 0, true, false)
-check(qgrep("adddir/test.txt", "stdout"))
============================================================
--- test/func/addition_of_files_and_directories/__driver__.lua 0051df02ca4bdb2c88e5931b087aaa6b3b0e67e5
+++ test/func/addition_of_files_and_directories/__driver__.lua a92d8e5231833e0f5146e04248c30eb31e82029e
@@ -15,6 +15,7 @@ check(qgrep("adding 'file0'", "stderr"))
check(mtn("add", "file0"), 0, false, true)
check(qgrep("adding 'file0'", "stderr"))
+-- Default is --no-recursive
check(mtn("add", "dir"), 0, false, true)
check(not qgrep("adding 'dir/file1'", "stderr"))
check(not qgrep("adding 'dir/file2'", "stderr"))
@@ -45,36 +46,60 @@ check(not qgrep("file2", "stdout"))
check(not qgrep("file1", "stdout"))
check(not qgrep("file2", "stdout"))
--- add --unknown should add any files that ls unknown shows you and not ignored
-
writefile("file3", "file 3\n")
---writefile("file4.ignore", "file 4 ignore\n")
writefile("dir/file5", "file 5\n")
-writefile("dir/file6.ignore", "file 6\n")
mkdir("dir2")
writefile("dir2/file7", "file 7\n")
---writefile(".mtn-ignore", ".*\\.ignore$\n")
---check(raw_mtn("ls", "unkown"), 0, true, false)
+-- 'add --unknown --recursive' should add any files that 'ls unknown' shows.
+-- Default for add is --no-recursive, for ls it is --recursive. So dir/* and dir2/* are added.
+check(mtn("ls", "unknown"), 0, true, false)
+check(samelines("stdout",
+{"dir/file5",
+ "dir2",
+ "dir2/file7",
+ "emptyhomedir",
+ "file3",
+ "min_hooks.lua",
+ "stderr",
+ "stdout",
+ "tester.log"}))
-check(mtn("add", "--unknown"), 0, false, true)
-check(qgrep("adding 'file3'", "stderr"))
---check(not qgrep("adding 'file4\.ignore'", "stderr"))
-check(qgrep("adding 'dir/file5'", "stderr"))
---check(not qgrep("adding 'dir/file6\.ignore'", "stderr"))
-check(qgrep("adding 'dir2'", "stderr"))
-check(not qgrep("adding 'dir2/file7'", "stderr"))
-check(not qgrep("skipping 'dir2/file7'", "stderr"))
-check(not qgrep("adding 'test_hooks.lua'", "stderr"))
-
+-- Note that 'ls ignored' does not recurse into ignored directory 'keys'
+-- ignored files are _not_ in .mtn-ignore; see ../test_hooks.lua ignore_file
+check(mtn("ls", "ignored"), 0, true, false)
+check(samelines("stdout",
+{"keys",
+ "test.db",
+ "test_hooks.lua",
+ "ts-stderr",
+ "ts-stdin",
+ "ts-stdout"}))
+
+check(mtn("add", "--unknown", "--recursive"), 0, false, true)
+check(samelines("stderr",
+{"mtn: skipping ignorable file 'keys'",
+ "mtn: skipping ignorable file 'test.db'",
+ "mtn: skipping ignorable file 'test_hooks.lua'",
+ "mtn: skipping ignorable file 'ts-stderr'",
+ "mtn: skipping ignorable file 'ts-stdin'",
+ "mtn: skipping ignorable file 'ts-stdout'",
+ "mtn: adding 'dir/file5' to workspace manifest",
+ "mtn: adding 'dir2' to workspace manifest",
+ "mtn: adding 'dir2/file7' to workspace manifest",
+ "mtn: adding 'emptyhomedir' to workspace manifest",
+ "mtn: adding 'file3' to workspace manifest",
+ "mtn: adding 'min_hooks.lua' to workspace manifest",
+ "mtn: adding 'stderr' to workspace manifest",
+ "mtn: adding 'stdout' to workspace manifest",
+ "mtn: adding 'tester.log' to workspace manifest"}))
+
check(mtn("status"), 0, true)
check(not qgrep("file0", "stdout"))
check(not qgrep("file1", "stdout"))
check(not qgrep("file2", "stdout"))
check(qgrep("file3", "stdout"))
---check(not qgrep("file4", "stdout"))
check(qgrep("file5", "stdout"))
---check(not qgrep("file6", "stdout"))
commit()
@@ -83,6 +108,6 @@ check(not qgrep("file3", "stdout"))
check(not qgrep("file1", "stdout"))
check(not qgrep("file2", "stdout"))
check(not qgrep("file3", "stdout"))
---check(not qgrep("file4", "stdout"))
check(not qgrep("file5", "stdout"))
---check(not qgrep("file6", "stdout"))
+
+-- end of file
============================================================
--- test/func/ls_unknown/__driver__.lua db94178a695f12c74d0c083a83a3ead65ea257b7
+++ test/func/ls_unknown/__driver__.lua 6654ef88997747a089cb73f7c6e7ff7ddd44d6a8
@@ -2,33 +2,70 @@ mtn_setup()
mtn_setup()
+mkdir("known")
+addfile("known/1", "known 1")
+addfile("known/2", "known 2")
+commit()
+
mkdir("foo")
writefile("bar", "bar")
writefile("foo/a", "aaa")
writefile("foo/b", "bbb")
+writefile("known/3", "unknown 3")
--- Doesn't recurse into unknown directory
+-- Default is recurse; recurse into both known and unknown
+-- directories (as inventory does)
check(mtn("ls", "unknown"), 0, true, nil)
check(samelines("stdout",
{"bar",
"emptyhomedir",
"foo",
+ "foo/a",
+ "foo/b",
+ "known/3",
"min_hooks.lua",
"tester.log"}))
--- Doesn't show contents of unknown directory, even when the directory is specified
+-- respect --no-recursive
+check(mtn("ls", "unknown", "--no-recursive"), 0, true, nil)
+check(samelines("stdout",
+{"bar",
+ "emptyhomedir",
+ "foo",
+ "min_hooks.lua",
+ "stdout",
+ "tester.log"}))
+
+-- Show contents of unknown directory, when the directory
+-- is specified (issue 148 case 2)
check(mtn("ls", "unknown", "foo"), 0, true, nil)
check(samelines("stdout",
+{"foo",
+ "foo/a",
+ "foo/b"}))
+
+-- But not with --no-recursive
+check(mtn("ls", "unknown", "foo", "--no-recursive"), 0, true, nil)
+check(samelines("stdout",
{"foo"}))
+-- Show contents of unknown path in unknown directory,
+-- when the path is specified (issue 148 case 1)
+check(mtn("ls", "unknown", "foo/a"), 0, true, nil)
+check(samelines("stdout",
+{"foo/a"}))
+
-- From within an unknown directory, same as executing at root.
check(indir("foo", mtn("ls", "unknown")), 0, true, nil)
check(samelines("stdout",
{"bar",
"emptyhomedir",
"foo",
+ "foo/a",
+ "foo/b",
+ "known/3",
"min_hooks.lua",
"stdout",
"tester.log"}))
-
+-- end of file
============================================================
--- test/func/things_in_.mtn-ignore_get_ignored/__driver__.lua 2b1974541199d82c39a4c9529f9d85d2bf5c7106
+++ test/func/things_in_.mtn-ignore_get_ignored/__driver__.lua e782689702a5ed0d977d1610dd7c06df505cdb1d
@@ -6,6 +6,8 @@ writefile("baz/xyzzy")
writefile("bar")
writefile("baz/xyzzy")
+-- "*.d" is a bad regexp; nothing to repeat (this is _not_ shell glob syntax)
+-- Show this is not fatal, but does produce an error message.
writefile(".mtn-ignore", "bar\nbaz\n*.d\n")
check(raw_mtn("ls", "unknown"), 0, true, true)
@@ -18,7 +20,7 @@ check(qgrep("warning", "unknownerr"))
check(qgrep("warning", "unknownerr"))
-check(raw_mtn("ls", "ignored"), 0, true, true)
+check(raw_mtn("ls", "ignored", "--no-recursive"), 0, true, true)
copy("stdout", "ignored")
copy("stderr", "ignorederr")
============================================================
--- test/func/two_parent_workspace_list/__driver__.lua 5d6df31659e888cf21e541121d487d3e5249e2df
+++ test/func/two_parent_workspace_list/__driver__.lua 2a365be32c664d756c0187954ca84c79590558fd
@@ -30,9 +30,26 @@ check(mtn("ls", "known"), 0, "file1\nfil
-- ignore them all. if the test suite is ever fixed to use a
-- subdirectory for the workspace (and therefore to keep it cleaner)
-- or to ignore them all properly, this will have to change.
-check(mtn("ls", "ignored"), 0, "keys\ntest.db\ntest_hooks.lua\nts-stderr\nts-stdin\nts-stdout\n", nil)
-check(mtn("ls", "unknown"), 0, "_MTN.old\nemptyhomedir\nmin_hooks.lua\npaths-new\npaths-old\nstderr\ntester.log\n", nil)
+check(mtn("ls", "ignored", "--no-recursive"), 0, true, nil)
+check(samelines("stdout",
+{"keys",
+ "test.db",
+ "test_hooks.lua",
+ "ts-stderr",
+ "ts-stdin",
+ "ts-stdout"}))
+check(mtn("ls", "unknown", "--no-recursive"), 0, true, nil)
+check(samelines("stdout",
+{"_MTN.old",
+ "emptyhomedir",
+ "min_hooks.lua",
+ "paths-new",
+ "paths-old",
+ "stderr",
+ "stdout",
+ "tester.log"}))
+
-- we do this after the other tests so it doesn't interfere with them.
remove("file4")
check(mtn("ls", "missing"), 0, "file4\n", nil)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Monotone-commits-diffs] net.venge.monotone.issue-148-80: 5b75e024b5f764b49703ce0135328fc5f78834b6,
code <=