# # # patch "monotone.texi" # from [c645706bac188f62662ddbaeb5830c0209cabe04] # to [766ac8dc432a047ea6091248417cb3f782f4a1de] # # patch "work.cc" # from [011e065cb66b572d0e10f382c70949c973e90679] # to [0ef66673796d2a408587d70530944a5a8747d488] # ============================================================ --- monotone.texi c645706bac188f62662ddbaeb5830c0209cabe04 +++ monotone.texi 766ac8dc432a047ea6091248417cb3f782f4a1de @@ -4663,9 +4663,8 @@ @section Workspace 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 is not -empty (for reasons of implementation simplicity, this warning appears -even if there are only ignorable files in the directory). +directory non-recursively, monotone will warn if the directory has +any files that would be added by a recursive add. @item mtn [--no-respect-ignore] mkdir @var{directory...} This command creates a directory in the filesystem relative to your ============================================================ --- work.cc 011e065cb66b572d0e10f382c70949c973e90679 +++ work.cc 0ef66673796d2a408587d70530944a5a8747d488 @@ -767,11 +767,12 @@ addition_builder roster_t & ros; editable_roster_base & er; bool respect_ignore; + bool recursive; public: addition_builder(database & db, workspace & work, roster_t & r, editable_roster_base & e, - bool i = true) - : db(db), work(work), ros(r), er(e), respect_ignore(i) + bool i, bool rec) + : db(db), work(work), ros(r), er(e), respect_ignore(i), recursive(rec) {} virtual bool visit_dir(file_path const & path); virtual void visit_file(file_path const & path); @@ -822,6 +823,46 @@ addition_builder::visit_dir(file_path co bool addition_builder::visit_dir(file_path const & path) { + 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 (respect_ignore && !work.ignore_file(path)) + { + vector children; + read_directory(path, children, children); + + for (vector::const_iterator i = children.begin(); + i != children.end(); ++i) + { + try + { + file_path entry = path / *i; + if (!work.ignore_file(entry) && !db.is_dbfile(entry)) + { + warn = true; + break; + } + } + catch (std::logic_error) + { + // ignore this file for purposes of the warning + // this file wouldn't have been added by a + // recursive add anyway. + } + } + } + + if (warn) + W(F("Non-recursive add: Files in the directory '%s' " + "will not be added automatically.") % path); + } + this->visit_file(path); return true; } @@ -1227,7 +1268,7 @@ add_parent_dirs(database & db, node_id_s file_path const & dst, roster_t & ros) { editable_roster_base er(ros, nis); - addition_builder build(db, work, ros, er); + addition_builder build(db, work, ros, er, false, true); // FIXME: this is a somewhat odd way to use the builder build.visit_dir(dst.dirname()); @@ -1390,7 +1431,7 @@ workspace::perform_additions(database & } I(new_roster.has_root()); - addition_builder build(db, *this, new_roster, er, respect_ignore); + addition_builder build(db, *this, new_roster, er, respect_ignore, recursive); for (set::const_iterator i = paths.begin(); i != paths.end(); ++i) { @@ -1413,10 +1454,6 @@ workspace::perform_additions(database & break; case path::directory: build.visit_dir(*i); - if (!directory_empty(*i)) - { - W(F("Non-recursive add: Files in the directory '%s' will not be added automatically.") % *i); - } break; } }