aboutsummaryrefslogtreecommitdiff
path: root/org-maint.el
blob: db5b16ade28509df0f02ce8ddf5772138d1e1f03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(defvar org-maint-emacs-dir "~/src/emacs/emacs/")
(defvar org-maint-org-dir "~/src/emacs/org-mode-devel/")

(defun org-maint-apply-emacs-commit (commit &optional apply)
  "Apply COMMIT from `org-maint-emacs-dir' to `org-maint-org-dir'.
If APPLY is non-nil, use 'git apply' instead of 'git am'."
  (interactive (list (or (and (use-region-p)
                              (buffer-substring-no-properties
                               (region-beginning) (region-end)))
                         (magit-commit-at-point)
                         (read-string "Emacs commit: "))
                     current-prefix-arg))
  (unless (and org-maint-org-dir org-maint-emacs-dir)
    (user-error "Need to set org-maint-org-dir and org-maint-emacs-dir"))
  (with-temp-buffer
    (let ((default-directory org-maint-emacs-dir))
      (call-process "git" nil t nil
                    "format-patch" "--stdout"
                    (format "%s^..%s" commit commit)
                    "--" "lisp/org"))
    (let ((default-directory org-maint-org-dir))
      (call-process-region (point-min) (point-max)
                           "git" nil t nil
                           (if apply "apply" "am")
                           "-p3" "--directory=lisp/"))))

(defun org-maint-insert-emacs-commit-info (commit)
  "Insert information about COMMIT in `org-maint-emacs-dir'."
  (interactive "sCommit: ")
  (let ((default-directory org-maint-emacs-dir))
    (call-process "git" nil t nil
                  "show" "-s" "--format=%b%n%s%n%H%n%an%n%cd"
                  commit)))

(defun org-maint-rev-from-next-item ()
  (save-excursion
    (or (and (re-search-forward "- \\[[ X]\\] \\([A-z0-9]\\{40\\}\\)")
             (match-string-no-properties 1))
        (user-error "Next revision item not found"))))

(defun org-maint-check-for-new ()
  "Check for new commits to backport.
The last commit found is assumed to be the return value of
`org-maint-rev-from-next-item`, and Emacs ref name that should be
checked is taken from the Org \"ref\" property."
  (interactive)
  (let ((ref (or (org-entry-get (point) "ref")
                 (user-error "No reference found")))
        (last-rev (org-maint-rev-from-next-item))
        (default-directory org-maint-emacs-dir))
    (with-current-buffer (get-buffer-create "*org-maint-new-entries*")
      (goto-char (point-min))
      (erase-buffer)
      (insert (format ";; %s..%s\n\n" last-rev ref))
      (call-process "git" nil t nil
                    "log" "--oneline"
                    "--format=- [ ] %H%n%n  %s%n  %an%n  %cd%n"
                    (concat "^" last-rev) ref
                    "--"
                    "doc/misc/org.texi"
                    "etc/ORG-NEWS"
                    "etc/org"
                    "etc/refcards/orgcard.tex"
                    "etc/schema/od-manifest-schema-v1.2-os.rnc"
                    "etc/schema/od-schema-v1.2-os.rnc"
                    "lisp/org")
      (display-buffer (current-buffer)))))