# # # add_dir "tests/automate_identify" # # add_file "tests/automate_identify/__driver__.lua" # content [41b1aa7f4bc84e92f8b3dddb0b135e3def94aae3] # # patch "NEWS" # from [6265ab1312fbe38bdc3aafa92441139cb2b779b0] # to [278caee61e46138fb27c3f5334d784df7773dff8] # # patch "cmd_automate.cc" # from [69aefb502195a4d228f1cc39045ee72d42958b84] # to [14f92cbf9b27710882e81f435b1ec11b03ea2a69] # # patch "cmd_files.cc" # from [17de5623905f507598b21286d65d96870096e086] # to [e691d67b351c272a06cd75057190fc5486d6f5c8] # # patch "monotone.texi" # from [603ebed7857e0bc12898ad03927c732570650712] # to [ad2e9773940536622365d456c0c2ba1e8ad2dacb] # ============================================================ --- tests/automate_identify/__driver__.lua 41b1aa7f4bc84e92f8b3dddb0b135e3def94aae3 +++ tests/automate_identify/__driver__.lua 41b1aa7f4bc84e92f8b3dddb0b135e3def94aae3 @@ -0,0 +1,20 @@ + +mtn_setup() + +-- check what happens if we give it no params (hint: it does not wait for stdin) +check(mtn("automate", "identify"), 1, false, false) + +-- check if non-existing files are handled +check(mtn("automate", "identify", "non-existing-file"), 1, false, false) + +-- check what happens if our filename is the stdin marker (hint: it should stop) +check(mtn("automate", "identify", "-"), 1, false, false) + +-- finally check the actual functionality +writefile("testfile", "This is a testfile with test content.\n"); +testfile_id = "4339e3c947e0d5abc83aef850db5ad6687559ae1" + +check(mtn("automate", "identify", "testfile"), 0, true, false) +canonicalize("stdout") +check(samelines("stdout", { testfile_id })); + ============================================================ --- NEWS 6265ab1312fbe38bdc3aafa92441139cb2b779b0 +++ NEWS 278caee61e46138fb27c3f5334d784df7773dff8 @@ -6,13 +6,15 @@ New features + - 'automate identify', an automate version of 'mtn identify'. + Other Internal - Update the internal Lua to version 5.1.2. - - Added build files for Mac OS X. + - Added build files for Mac OS X. - Update the internal SQLite to version 3.3.16. ============================================================ --- cmd_automate.cc 69aefb502195a4d228f1cc39045ee72d42958b84 +++ cmd_automate.cc 14f92cbf9b27710882e81f435b1ec11b03ea2a69 @@ -61,7 +61,7 @@ automate_command(utf8 cmd, vector find_automation(cmd, root_cmd_name).run(args, root_cmd_name, app, output); } -static string const interface_version = "4.1"; +static string const interface_version = "4.2"; // Name: interface_version // Arguments: none ============================================================ --- cmd_files.cc 17de5623905f507598b21286d65d96870096e086 +++ cmd_files.cc e691d67b351c272a06cd75057190fc5486d6f5c8 @@ -205,6 +205,35 @@ CMD(identify, N_("debug"), N_("[PATH]"), cout << ident << '\n'; } +// Name: identify +// Arguments: +// 1: a file path +// Added in: 4.2 +// Purpose: Prints the fileid of the given file (aka hash) +// +// Output format: a single, 40 byte long hex-encoded id +// +// Error conditions: If the file path doesn't point to a valid file prints +// an error message to stderr and exits with status 1. +AUTOMATE(identify, N_("PATH"), options::opts::none) +{ + N(args.size() == 1, + F("wrong argument count")); + + utf8 path = idx(args, 0); + + N(path() != "-", + F("Cannot read from stdin")); + + data dat; + read_data_for_command_line(path, dat); + + hexenc ident; + calculate_ident(dat, ident); + + output << ident << '\n'; +} + static void dump_file(std::ostream & output, app_state & app, file_id & ident) { ============================================================ --- monotone.texi 603ebed7857e0bc12898ad03927c732570650712 +++ monotone.texi ad2e9773940536622365d456c0c2ba1e8ad2dacb @@ -6178,6 +6178,40 @@ @section Automation @end table address@hidden mtn automate identify @var{path} + address@hidden @strong address@hidden Arguments: + +A file path. + address@hidden Added in: + +4.2 + address@hidden Purpose: + +Prints the file ID (aka hash) of the given file. + address@hidden Sample output: + address@hidden +6265ab1312fbe38bdc3aafa92441139cb2b779b0 address@hidden verbatim + address@hidden Output format: + +A single line with the file's ID, in hexadecimal, followed by a newline. + address@hidden Error conditions: + +If the file does not exists, is a special file or not readable, prints an +error message to stderr and exists with status 1. A single file path only +consisting of "-" is disallowed since it collides with the UNIX stdin +marker. + address@hidden table + @item mtn automate inventory @table @strong