~niklaseklund/egerrit

1ed03351b22f8b47fa0a4e538d059bc85eff7631 — Niklas Eklund a month ago b7f8048
Increase possibility to detect autogenerated files
1 files changed, 39 insertions(+), 17 deletions(-)

M egerrit-diff.el
M egerrit-diff.el => egerrit-diff.el +39 -17
@@ 57,9 57,14 @@

;;;; Variables

(defcustom egerrit-autogenerated-regexp nil
  "A regular expression to identify autogenerated files."
  :type 'string
(defcustom egerrit-autogenerated-content-regexps nil
  "A list of regular expressions to identify autogenerated content."
  :type 'list
  :group 'egerrit)

(defcustom egerrit-autogenerated-filepath-regexps nil
  "A list of regular expressions to identify paths to autogenerated files."
  :type 'list
  :group 'egerrit)

;;;; Functions


@@ 348,24 353,41 @@
   (egerrit-revision-id revision)))

(defun egerrit--diff-autogenerated-files (change revision)
  "Return a list of autogenerated files on CHANGE's REVISION."
  (let ((revision-files
         (egerrit-request-revision-files
          (egerrit-change-id change)
          (egerrit-revision-id revision))))
  "Return a list of generated files on CHANGE's REVISION."
  (let* ((egerrit--current-change change)
         (egerrit--current-revision revision)
         (revision-files
          (egerrit-request-revision-files
           (egerrit-change-id change)
           (egerrit-revision-id revision))))
    (thread-last revision-files
                 (seq-map (lambda (it)
                            (symbol-name (car it))))
                 (seq-filter (lambda (it)
                               (with-temp-buffer
                                 (erase-buffer)
                                 (insert
                                  (egerrit-request-download-file
                                   (egerrit-change-id change)
                                   (egerrit-revision-id revision)
                                   it))
                                 (goto-char (point-min))
                                 (re-search-forward egerrit-autogenerated-regexp nil t)))))))
                               (or (egerrit--autogenerated-file-path-p it)
                                   (egerrit--autogenerated-file-content-p it)))))))

(defun egerrit--autogenerated-file-path-p (file)
  "Return t if FILE has a path that matches expected generated files."
  (seq-find (lambda (re)
              (string-match-p re file))
            egerrit-autogenerated-filepath-regexps))

(defun egerrit--autogenerated-file-content-p (file)
  "Return t if content of the FILE is generated."
  (let ((change egerrit--current-change)
        (revision egerrit--current-revision))
    (with-temp-buffer
      (insert
       (egerrit-request-download-file
        (egerrit-change-id change)
        (egerrit-revision-id revision)
        file))
      (goto-char (point-min))
      (seq-find (lambda (re)
                  (save-excursion
                    (re-search-forward re nil t)))
                egerrit-autogenerated-content-regexps))))

(defun egerrit--diff-add-autogenerated-identifier (file)
  "Add identifier to FILE in diff buffer."