#
# add_file "tests/t_automate_attributes.at"
#
# patch "ChangeLog"
# from [2abf8c7eaa740f13cc224f5c7f287f4700078894]
# to [4aea07e5f341da91edb8232687892b0804919170]
#
# patch "automate.cc"
# from [6e3b8cec00c8f4d0d91d8d9fd14c4d06e8f0eef0]
# to [01d2a759958e74ea48078b2f337131e9ca4156e7]
#
# patch "commands.cc"
# from [00ef62e671f25b832bb1280d1c66c0bbc7c39545]
# to [61582d84558e7e68ba83c0f9d89e094667401d6c]
#
# patch "contrib/monotone.zsh_completion"
# from [e6efc2fe7fbb25ed436549a2a2093575df0a0696]
# to [f3786eacbf920e2d25b3dc2ff00464bc319e2332]
#
# patch "tests/t_automate_attributes.at"
# from []
# to [ed576e9065c0ed437f563975e7fb8fae967d233d]
#
# patch "testsuite.at"
# from [c3041362f6a63b9519d7ec321626392cd6baf6a6]
# to [780ed963e99a738ebbce9079486ac69c032ed5f5]
#
--- ChangeLog
+++ ChangeLog
@@ -1,3 +1,12 @@
+2005-05-13 Joel Reed
+
+ * automate.cc: add automate attributes command
+ * commands.cc: add attributes subcommand helptext
+ * contrib/monotone.zsh_completion: use automate attributes
+ for completion of monotone attr and cleanup ignore files code
+ * tests/t_automate_attributes.at: add testcase
+ * testsuite.at: include new testcaes
+
2005-05-13 Jon Bright
* testsuite.at (UNGZ): Change the way the ungzipping works on
Win32, in the hope that test 206 will no longer be given invalid
--- automate.cc
+++ automate.cc
@@ -199,6 +199,54 @@
output << (*i).inner()() << std::endl;
}
+// Name: attributes
+// Arguments:
+// 1: file name (optional, if non-existant prints all files with attributes)
+// Added in: 1.0
+// Purpose: Prints all attributes for a file, or all all files with attributes
+// if a file name provided.
+// Output format: A list of file names in alphabetically sorted order,
+// or a list of attributes if a file name provided.
+// Error conditions: If the file name has no attributes, prints nothing.
+static void
+automate_attributes(std::vector args,
+ std::string const & help_name,
+ app_state & app,
+ std::ostream & output)
+{
+ if (args.size() > 1)
+ throw usage(help_name);
+
+ // is there an .mt-attrs?
+ file_path attr_path;
+ get_attr_path(attr_path);
+ if (!file_exists(attr_path)) return;
+
+ // read attribute map
+ data attr_data;
+ attr_map attrs;
+
+ read_data(attr_path, attr_data);
+ read_attr_map(attr_data, attrs);
+
+ if (args.size() == 1) {
+ // a filename was given, if it has attributes, print them
+ file_path path = app.prefix(idx(args,0)());
+ attr_map::const_iterator i = attrs.find(path);
+ if (i == attrs.end()) return;
+
+ for (std::map::const_iterator j = i->second.begin();
+ j != i->second.end(); ++j)
+ output << j->first << std::endl;
+ }
+ else {
+ for (attr_map::const_iterator i = attrs.begin(); i != attrs.end(); ++i)
+ {
+ output << (*i).first << std::endl;
+ }
+ }
+}
+
// Name: toposort
// Arguments:
// 0 or more: revision ids
@@ -771,6 +819,8 @@
automate_select(args, root_cmd_name, app, output);
else if (cmd() == "inventory")
automate_inventory(args, root_cmd_name, app, output);
+ else if (cmd() == "attributes")
+ automate_attributes(args, root_cmd_name, app, output);
else
throw usage(root_cmd_name);
}
--- commands.cc
+++ commands.cc
@@ -3603,6 +3603,7 @@
"interface_version\n"
"heads [BRANCH]\n"
"ancestors REV1 [REV2 [REV3 [...]]]\n"
+ "attributes [FILE]\n"
"parents REV\n"
"descendents REV1 [REV2 [REV3 [...]]]\n"
"children REV\n"
--- contrib/monotone.zsh_completion
+++ contrib/monotone.zsh_completion
@@ -75,8 +75,11 @@
_monotone_attr() {
if (( CURRENT == 2 )); then
compadd -- set get drop
+ elif (( CURRENT == 3 )); then
+ compadd -- $(monotone automate attributes)
else
- _monotone_existing_entries
+ local fname="$words[3]";
+ compadd -- $(monotone automate attributes $fname)
fi
}
@@ -270,7 +273,7 @@
(( $+functions[_monotone_files_unmaintained] )) ||
_monotone_files_unmaintained() {
- compadd -F "$_monotone_ignore_default" -- $(monotone ls unknown)
+ compadd -- $(monotone ls unknown)
}
(( $+functions[_monotone_existing_entries] )) ||
@@ -278,9 +281,6 @@
_path_files -F "$_monotone_ignore_default" -g "*"
}
-(( $+_monotone_ignore_default )) ||
-_monotone_ignore_default=( "(*.Po *.a *.olb *.o *.so *.exe *.Z *.elc *.ln *.dirstamp *.rej *.orig *.BAK *.bak *.old autom4te.cache/* tags TAGS )" )
-
(( $+functions[_monotone_branches] )) ||
_monotone_branches() {
compadd -- $(monotone ls branches)
--- tests/t_automate_attributes.at
+++ tests/t_automate_attributes.at
@@ -0,0 +1,12 @@
+AT_SETUP([automate attributes])
+MONOTONE_SETUP
+
+ADD_FILE(testfile, [foo bar
+])
+AT_CHECK(MONOTONE attr set testfile unique_key unique_value, [], [ignore], [ignore])
+AT_CHECK(MONOTONE automate attributes testfile, [], [stdout], [ignore])
+AT_CHECK(grep -q unique_key stdout)
+AT_CHECK(MONOTONE automate attributes, [], [stdout], [ignore])
+AT_CHECK(grep -q testfile stdout)
+
+AT_CLEANUP
--- testsuite.at
+++ testsuite.at
@@ -641,3 +641,4 @@
m4_include(tests/t_unreadable_MT.at)
m4_include(tests/t_cvsimport3.at)
m4_include(tests/t_commit_message_file.at)
+m4_include(tests/t_automate_attributes.at)