+(defun batch-prepare-packages ()
+ "Prepare the `packages' directory inside the Bzr checkout.
+Expects to be called from within the `packages' directory.
+\"Prepare\" here is for subsequent construction of the packages and archive,
+so it is meant to refresh any generated files we may need.
+Currently only refreshes the ChangeLog files."
+ (let* ((wit ".changelog-witness")
+ (prevno (or (with-temp-buffer
+ (ignore-errors (insert-file-contents wit))
+ (when (looking-at "[1-9][0-9]*\\'")
+ (string-to-number (match-string 0))))
+ 1))
+ (new-revno
+ (or (with-temp-buffer
+ (call-process "bzr" nil '(t) nil "revno")
+ (goto-char (point-min))
+ (when (looking-at "[1-9][0-9]*$")
+ (string-to-number (match-string 0))))
+ (error "bzr revno did not return a number as expected")))
+ (pkgs '()))
+ (unless (= prevno new-revno)
+ (with-temp-buffer
+ (unless (zerop (call-process "bzr" nil '(t) nil "log" "-v"
+ (format "-r%d.." (1+ prevno))))
+ (error "Error signaled by bzr log -v -r%d.." (1+ prevno)))
+ (goto-char (point-min))
+ (while (re-search-forward "^ packages/\\([-[:alnum:]]+\\)/" nil t)
+ (cl-pushnew (match-string 1) pkgs :test #'equal))))
+ (dolist (pkg pkgs)
+ (condition-case v
+ (if (file-directory-p pkg)
+ (archive--make-changelog pkg))
+ (error (message "%s" (cadr v)))))
+ (write-region (number-to-string new-revno) nil wit nil 'quiet)))
+