# # patch "automate.cc" # from [104a3a0307c16c724da0fed33f087175aaaba5bf] # to [5d1bba420f13d6f87c2ea44ac32d45edaddf5358] # # patch "commands.cc" # from [00ef62e671f25b832bb1280d1c66c0bbc7c39545] # to [61582d84558e7e68ba83c0f9d89e094667401d6c] # # patch "contrib/monotone.zsh_completion" # from [e6efc2fe7fbb25ed436549a2a2093575df0a0696] # to [34267516d8641af3d5b2ed345c5a6b6da2ac33bd] # --- automate.cc +++ automate.cc @@ -17,7 +17,7 @@ #include "revision.hh" #include "vocab.hh" -static std::string const interface_version = "0.2"; +static std::string const interface_version = "0.3"; // Name: interface_version // Arguments: none @@ -198,6 +198,54 @@ output << (*i).inner()() << std::endl; } +// Name: attributes +// Arguments: +// 1: file name (optional, if non-existant prints all files with attributes) +// Added in: 0.3 +// 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 @@ -677,6 +725,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"