This lua script looks through a maildir directory to find files that have been moved, renamed, or deleted, and executes monotone commands to record the changes. (jack-monotone posted a script to do much the same thing, using inodes: http://lists.gnu.org/archive/html/monotone-devel/2005-09/msg00234.html)
#!/usr/bin/env lua if arg.n > 1 or (arg.n == 1 and (arg[1] == "-h" or arg[1] == "--help")) then print("Usage: " .. arg[0] .. " [-h | --help | MAILDIR]"); print("Execute 'monotone drop' and 'monotone rename' commands to "); print("compensate for changes made to MAILDIR by a mail reader."); print(" MAILDIR\tRelative path from the top of the working directory"); print(" \tto a maildir directory. (Default: \"Mail\")."); if arg.n == 1 then os.exit(0); else os.exit(1); end end if arg.n == 1 then maildir = arg[1]; else maildir = "Mail"; end -- Maildirs contain e-mail messages in separate files. The file names consist -- of a unique string in "x.y.z" form and an optional suffix that starts -- with ":". The suffix records the state of the message. Mail readers -- may move files between directories and may change a file's suffix, -- but the x.y.z part does not change. See -- http://cr.yp.to/proto/maildir.html for details. -- Grab the missing/unknown/ignored state, the directory name, the unique -- portion and the suffix from "monotone automate inventory" output. in_pat = "..([IMU]) %d+ %d+ (" .. maildir .. "/[^%c]*/)([^./:]+%.[^./:]+%.[^./:%c]+)([^%c]*)" missing = {}; present = {}; mtout = io.popen("monotone automate inventory"):read("*a"); starts, ends, state, dir, unique, suffix = string.find(mtout, in_pat); while starts do path = dir .. unique .. suffix; if state == "M" then missing[unique] = path elseif state == "U" or state == "I" then present[unique] = path; end starts, ends, state, dir, unique, suffix = string.find(mtout, in_pat, ends); end -- Assume that an unknown or ignored file name with the same unique part as a -- missing file is the result of a file move, and that missing files that don't -- share their unique part with an ignored or unknown file were deleted. for unique, path in pairs(missing) do if present[unique] then os.execute("monotone rename " .. path .. " " .. present[unique]); else os.execute("monotone drop " .. path); end end _______________________________________________ Monotone-devel mailing list Monotone-devel@nongnu.org http://lists.nongnu.org/mailman/listinfo/monotone-devel