;;; ----------------------------------------------------------------------- ;;; p4-integrate-change --- Integrate a single p4 change from ;;; one branch to another (defvar p4-current-branch nil "Current branch name") (defvar p4-submit-header-text nil "First line in change description") (defun p4-regexp-buf-search (buffer regexp) (save-excursion (set-buffer buffer) (goto-char (point-min)) (re-search-forward regexp nil t))) (defun p4-set-integration-branch () (let ((args (p4-read-arg-string "Integrate to branch: " p4-current-branch "branch"))) (if (or (null args) (equal args "")) (error "Branch must be specified!")) (setq p4-current-branch args))) (defun p4-set-submit-header-text () (let ((args (read-from-minibuffer "Integrate change description: " p4-submit-header-text))) (setq p4-submit-header-text args))) (defun p4-integrate-change (change-no) (interactive (list (let ((c (get-char-property (point) 'change))) (if (or current-prefix-arg (null c)) (setq c (p4-read-arg-string "Integrate change: " c))) (setq c (string-to-number c)) c))) ;; Convert change number to string (setq change-no (number-to-string change-no)) ;; Check for other opened files (p4-noinput-buffer-action "opened" nil t nil) (if (and (not (p4-regexp-buf-search p4-output-buffer-name "not opened on this client")) (progn (ding t) (not (yes-or-no-p (concat "Files already opened in this " "client. Integrate anyway? "))))) (error "Integration aborted")) ;; Set branch name (if (or current-prefix-arg (not p4-current-branch) (string= p4-current-branch "")) (p4-set-integration-branch)) ;; Set change description text (if (or current-prefix-arg (not p4-submit-header-text) (string= p4-submit-header-text "")) (p4-set-submit-header-text)) ;; Run integrate command (p4-noinput-buffer-action "integ" nil t (list "-b" p4-current-branch (concat p4-default-depot-completion-prefix "...@" change-no "," change-no))) (if (not (p4-regexp-buf-search p4-output-buffer-name " - \\(integrate\\|branch/sync\\) from ")) (error "p4 integrate failed")) ;; Run resolve command (p4-noinput-buffer-action "resolve" nil t (list "-am")) (if (p4-regexp-buf-search p4-output-buffer-name " - resolve skipped") (error "p4 resolve failed")) ;; Run submit command (let ((submit-buf-name "*P4 Submit*")) (if (buffer-live-p submit-buf-name) (kill-buffer submit-buf-name))) (p4-submit) (goto-char (point-min)) (if (not (re-search-forward "\nDescription:\n\\(\\(.*\n\\)+\\)Files:\n" nil t)) (error "Can't parse change specification")) (delete-region (match-beginning 1) (match-end 1)) (goto-char (match-beginning 1)) (insert "\t" p4-submit-header-text "\n\tIntegrated change " change-no "\n\n") (goto-char (- (point) 2)) ;; Run diff command (p4-diff-all-opened) (other-window 1)) ;; Add a shortcut to the p4-filelog keymap (define-key p4-filelog-map "i" 'p4-integrate-change) (define-key p4-diff-map "i" 'p4-integrate-change) ;;; ----------------------------------------------------------------------- ;;; p4-revert-interactively --- Interactively revert any opened files ;;; Contributed by Michael Slass ;;; (defun p4-revert-interactively () "Interactively revert any opened files. Prompt in the minibuffer for y or n to revert each file" (interactive) (let* ((buffer (generate-new-buffer "opened-files"))) (progn (p4-exec-p4 buffer (list "opened") t) (set-buffer buffer) (beginning-of-buffer) (if (re-search-forward "File(s) not opened on this client\\." nil t) (message "File(s) not opened on this client.") (while (re-search-forward "//[^#]+" nil t) (let ((filename (buffer-substring (match-beginning 0) (match-end 0)))) (if (y-or-n-p (format "revert depot file %s? " filename)) (p4-noinput-buffer-action "revert" t t (list filename)))))) (kill-buffer buffer))))