Codebase list magit / 4aeb0ad
applied whitespace-cleanup close issue 304 Yann Hodique 12 years ago
3 changed file(s) with 978 addition(s) and 988 deletion(s). Raw diff Collapse all Expand all
33 ((emacs-lisp-mode
44 (indent-tabs-mode)
55 (tab-width . 8)))
6
193193 (abbreviate-file-name default-directory)))))))))
194194
195195 (provide 'magit-bisect)
196
+978
-986
magit.el less more
136136 :type '(choice (const :tag "Never" nil)
137137 (const :tag "Ask" t)
138138 (const :tag "Refuse" refuse)
139 (const :tag "Always" dontask)))
139 (const :tag "Always" dontask)))
140140
141141 (defcustom magit-save-some-buffers t
142142 "Non-nil means that \\[magit-status] will save modified buffers before running.
144144 save all modified buffers without asking."
145145 :group 'magit
146146 :type '(choice (const :tag "Never" nil)
147 (const :tag "Ask" t)
148 (const :tag "Save without asking" dontask)))
147 (const :tag "Ask" t)
148 (const :tag "Save without asking" dontask)))
149149
150150 (defcustom magit-save-some-buffers-predicate
151151 'magit-save-buffers-predicate-tree-only
178178 after a confirmation."
179179 :group 'magit
180180 :type '(choice (const :tag "No" nil)
181 (const :tag "Always" t)
182 (const :tag "Ask" ask)
183 (const :tag "Ask to stage everything" ask-stage)))
181 (const :tag "Always" t)
182 (const :tag "Ask" ask)
183 (const :tag "Ask to stage everything" ask-stage)))
184184
185185 (defcustom magit-commit-signoff nil
186186 "Add the \"Signed-off-by:\" line when committing."
209209 "Popup the process buffer if a command takes longer than this many seconds."
210210 :group 'magit
211211 :type '(choice (const :tag "Never" -1)
212 (const :tag "Immediately" 0)
213 (integer :tag "After this many seconds")))
212 (const :tag "Immediately" 0)
213 (integer :tag "After this many seconds")))
214214
215215 (defcustom magit-revert-item-confirm t
216216 "Require acknowledgment before reverting an item."
251251 :group 'magit
252252 :type '(radio (function-item magit-iswitchb-completing-read)
253253 (function-item magit-ido-completing-read)
254 (function-item magit-builtin-completing-read)
255 (function :tag "Other")))
254 (function-item magit-builtin-completing-read)
255 (function :tag "Other")))
256256
257257 (defcustom magit-create-branch-behaviour 'at-head
258258 "Where magit will create a new branch if not supplied a branchname or ref.
270270 The function is given one argument, the status buffer."
271271 :group 'magit
272272 :type '(radio (function-item switch-to-buffer)
273 (function-item pop-to-buffer)
274 (function :tag "Other")))
273 (function-item pop-to-buffer)
274 (function :tag "Other")))
275275
276276 (defcustom magit-rewrite-inclusive t
277277 "Whether magit includes the selected base commit in a rewrite operation.
645645 (defun magit-buffer-switch (buf)
646646 (if (string-match "magit" (buffer-name))
647647 (switch-to-buffer buf)
648 (pop-to-buffer buf)))
648 (pop-to-buffer buf)))
649649
650650 ;;; Macros
651651
710710 "Same as `string-match' except this function does not
711711 change the match data."
712712 (let ((inhibit-changing-match-data t))
713 (string-match regexp string start))))
713 (string-match regexp string start))))
714714
715715 (if (fboundp 'with-silent-modifications)
716716 (defalias 'magit-with-silent-modifications 'with-silent-modifications)
748748 (magit-refresh-all))
749749
750750 (defun magit-iswitchb-completing-read (prompt choices &optional predicate require-match
751 initial-input hist def)
751 initial-input hist def)
752752 "iswitchb-based completing-read almost-replacement."
753753 (require 'iswitchb)
754754 (let ((iswitchb-make-buflist-hook
771771 selected)))
772772
773773 (defun magit-builtin-completing-read (prompt choices &optional predicate require-match
774 initial-input hist def)
774 initial-input hist def)
775775 "Magit wrapper for standard `completing-read' function."
776776 (completing-read (if (and def (> (length prompt) 2)
777777 (string-equal ": " (substring prompt -2)))
780780 choices predicate require-match initial-input hist def))
781781
782782 (defun magit-completing-read (prompt choices &optional predicate require-match
783 initial-input hist def)
783 initial-input hist def)
784784 (funcall magit-completing-read-function prompt choices predicate require-match
785785 initial-input hist def))
786786
800800 (if (string= str "")
801801 nil
802802 (if (equal (elt str (- (length str) 1)) ?\n)
803 (substring str 0 (- (length str) 1))
803 (substring str 0 (- (length str) 1))
804804 str)))
805805
806806 (defun magit-split-lines (str)
808808 nil
809809 (let ((lines (nreverse (split-string str "\n"))))
810810 (if (string= (car lines) "")
811 (setq lines (cdr lines)))
811 (setq lines (cdr lines)))
812812 (nreverse lines))))
813813
814814 (defun magit-git-insert (args)
837837
838838 (defun magit-git-exit-code (&rest args)
839839 (apply #'process-file magit-git-executable nil nil nil
840 (append magit-git-standard-options args)))
840 (append magit-git-standard-options args)))
841841
842842 (defun magit-file-lines (file)
843843 (when (file-exists-p file)
844844 (with-temp-buffer
845845 (insert-file-contents file)
846846 (let ((rev (nreverse (split-string (buffer-string) "\n"))))
847 (nreverse (if (equal (car rev) "")
848 (cdr rev)
849 rev))))))
847 (nreverse (if (equal (car rev) "")
848 (cdr rev)
849 rev))))))
850850
851851 (defun magit-write-file-lines (file lines)
852852 (with-temp-buffer
870870
871871 (defun magit-remove-conflicts (alist)
872872 (let ((dict (make-hash-table :test 'equal))
873 (result nil))
873 (result nil))
874874 (dolist (a alist)
875875 (puthash (car a) (cons (cdr a) (gethash (car a) dict))
876 dict))
876 dict))
877877 (maphash (lambda (key value)
878 (if (= (length value) 1)
879 (push (cons key (car value)) result)
880 (let ((sub (magit-remove-conflicts
881 (mapcar (lambda (entry)
882 (let ((dir (directory-file-name
883 (substring entry 0 (- (length key))))))
884 (cons (concat (file-name-nondirectory dir) "/" key)
885 entry)))
886 value))))
887 (setq result (append result sub)))))
888 dict)
878 (if (= (length value) 1)
879 (push (cons key (car value)) result)
880 (let ((sub (magit-remove-conflicts
881 (mapcar (lambda (entry)
882 (let ((dir (directory-file-name
883 (substring entry 0 (- (length key))))))
884 (cons (concat (file-name-nondirectory dir) "/" key)
885 entry)))
886 value))))
887 (setq result (append result sub)))))
888 dict)
889889 result))
890890
891891 (defun magit-git-repo-p (dir)
900900 (if (magit-git-repo-p dir)
901901 (list dir)
902902 (apply #'append
903 (mapcar (lambda (entry)
904 (unless (or (string= (substring entry -3) "/..")
905 (string= (substring entry -2) "/."))
906 (magit-list-repos* entry (+ level 1))))
907 (and (file-directory-p dir)
908 (< level magit-repo-dirs-depth)
909 (directory-files dir t nil t))))))
903 (mapcar (lambda (entry)
904 (unless (or (string= (substring entry -3) "/..")
905 (string= (substring entry -2) "/."))
906 (magit-list-repos* entry (+ level 1))))
907 (and (file-directory-p dir)
908 (< level magit-repo-dirs-depth)
909 (directory-files dir t nil t))))))
910910
911911 (defun magit-list-repos (dirs)
912912 (magit-remove-conflicts
913913 (apply #'append
914 (mapcar (lambda (dir)
915 (mapcar #'(lambda (repo)
916 (cons (file-name-nondirectory repo)
917 repo))
918 (magit-list-repos* dir 0)))
919 dirs))))
914 (mapcar (lambda (dir)
915 (mapcar #'(lambda (repo)
916 (cons (file-name-nondirectory repo)
917 repo))
918 (magit-list-repos* dir 0)))
919 dirs))))
920920
921921 (defun magit-get-top-dir (cwd)
922922 (let ((cwd (expand-file-name (file-truename cwd))))
931931
932932 (defun magit-get-current-branch ()
933933 (let* ((head (magit-get-ref "HEAD"))
934 (pos (and head (string-match "^refs/heads/" head))))
934 (pos (and head (string-match "^refs/heads/" head))))
935935 (if pos
936 (substring head 11)
936 (substring head 11)
937937 nil)))
938938
939939 (defun magit-get-remote (branch)
969969 (error "Not a repository or a directory: %s" reply)))))
970970 (file-name-as-directory
971971 (read-directory-name "Git repository: "
972 (or (magit-get-top-dir default-directory)
973 default-directory)))))
972 (or (magit-get-top-dir default-directory)
973 default-directory)))))
974974
975975 (defun magit-rev-parse (ref)
976976 "Return the SHA hash for REF."
10281028
10291029 (defun magit-put-line-property (prop val)
10301030 (put-text-property (line-beginning-position) (line-beginning-position 2)
1031 prop val))
1031 prop val))
10321032
10331033 (defun magit-format-commit (commit format)
10341034 (magit-git-string "log" "--max-count=1"
1035 (concat "--pretty=format:" format)
1036 commit))
1035 (concat "--pretty=format:" format)
1036 commit))
10371037
10381038 (defun magit-current-line ()
10391039 (buffer-substring-no-properties (line-beginning-position)
1040 (line-end-position)))
1040 (line-end-position)))
10411041
10421042 (defun magit-insert-region (beg end buf)
10431043 (let ((text (buffer-substring-no-properties beg end)))
10461046
10471047 (defun magit-insert-current-line (buf)
10481048 (let ((text (buffer-substring-no-properties
1049 (line-beginning-position) (line-beginning-position 2))))
1049 (line-beginning-position) (line-beginning-position 2))))
10501050 (with-current-buffer buf
10511051 (insert text))))
10521052
10681068 (defun magit-choose-parent-id (commit op)
10691069 (let* ((parents (magit-commit-parents commit)))
10701070 (if (> (length parents) 1)
1071 (error "Can't %s merge commits" op)
1071 (error "Can't %s merge commits" op)
10721072 nil)))
10731073
10741074 ;;; Revisions and ranges
11501150 (defun magit-read-rev (prompt &optional def uninteresting)
11511151 (let* ((interesting-refs (magit-list-interesting-refs
11521152 (or uninteresting magit-uninteresting-refs)))
1153 (reply (magit-completing-read (concat prompt ": ") interesting-refs
1153 (reply (magit-completing-read (concat prompt ": ") interesting-refs
11541154 nil nil nil 'magit-read-rev-history def))
1155 (rev (or (cdr (assoc reply interesting-refs)) reply)))
1155 (rev (or (cdr (assoc reply interesting-refs)) reply)))
11561156 (if (string= rev "")
1157 nil
1157 nil
11581158 rev)))
11591159
11601160 (defun magit-read-rev-range (op &optional def-beg def-end)
11611161 (let ((beg (magit-read-rev (format "%s start" op)
1162 def-beg)))
1162 def-beg)))
11631163 (if (not beg)
1164 nil
1164 nil
11651165 (save-match-data
1166 (if (string-match "^\\(.+\\)\\.\\.\\(.+\\)$" beg)
1167 (cons (match-string 1 beg) (match-string 2 beg))
1168 (let ((end (magit-read-rev (format "%s end" op) def-end)))
1169 (cons beg end)))))))
1166 (if (string-match "^\\(.+\\)\\.\\.\\(.+\\)$" beg)
1167 (cons (match-string 1 beg) (match-string 2 beg))
1168 (let ((end (magit-read-rev (format "%s end" op) def-end)))
1169 (cons beg end)))))))
11701170
11711171 (defun magit-rev-to-git (rev)
11721172 (or rev
11811181 (if (stringp range)
11821182 range
11831183 (if (cdr range)
1184 (format "%s..%s"
1185 (magit-rev-to-git (car range))
1186 (magit-rev-to-git (cdr range)))
1184 (format "%s..%s"
1185 (magit-rev-to-git (car range))
1186 (magit-rev-to-git (cdr range)))
11871187 (format "%s" (magit-rev-to-git (car range))))))
11881188
11891189 (defun magit-rev-describe (rev)
11991199 (if (stringp range)
12001200 (format "%s in %s" things range)
12011201 (if (cdr range)
1202 (format "%s from %s to %s" things
1203 (magit-rev-describe (car range))
1204 (magit-rev-describe (cdr range)))
1202 (format "%s from %s to %s" things
1203 (magit-rev-describe (car range))
1204 (magit-rev-describe (cdr range)))
12051205 (format "%s at %s" things (magit-rev-describe (car range))))))
12061206
12071207 (defun magit-default-rev ()
12081208 (or (magit-name-rev (magit-commit-at-point t))
12091209 (let ((branch (magit-guess-branch)))
1210 (if branch
1211 (if (string-match "^refs/\\(.*\\)" branch)
1212 (match-string 1 branch)
1213 branch)))))
1210 (if branch
1211 (if (string-match "^refs/\\(.*\\)" branch)
1212 (match-string 1 branch)
1213 branch)))))
12141214
12151215 (defun magit-read-remote (&optional prompt def)
12161216 "Read the name of a remote.
12181218 DEF is the default value, and defaults to the value of `magit-get-current-branch'."
12191219 (let* ((prompt (or prompt "Remote: "))
12201220 (def (or def (magit-get-current-remote)))
1221 (remotes (magit-git-lines "remote"))
1222 (reply (magit-completing-read prompt remotes
1221 (remotes (magit-git-lines "remote"))
1222 (reply (magit-completing-read prompt remotes
12231223 nil nil nil nil def)))
12241224 (if (string= reply "") nil reply)))
12251225
12551255
12561256 If TYPE is nil, the section won't be highlighted."
12571257 (let* ((s (make-magit-section :parent magit-top-section
1258 :title title
1259 :type type
1260 :hidden magit-section-hidden-default))
1261 (old (and magit-old-top-section
1262 (magit-find-section (magit-section-path s)
1263 magit-old-top-section))))
1258 :title title
1259 :type type
1260 :hidden magit-section-hidden-default))
1261 (old (and magit-old-top-section
1262 (magit-find-section (magit-section-path s)
1263 magit-old-top-section))))
12641264 (if magit-top-section
1265 (push s (magit-section-children magit-top-section))
1266 (setq magit-top-section s))
1265 (push s (magit-section-children magit-top-section))
1266 (setq magit-top-section s))
12671267 (if old
1268 (setf (magit-section-hidden s) (magit-section-hidden old)))
1268 (setf (magit-section-hidden s) (magit-section-hidden old)))
12691269 s))
12701270
12711271 (defun magit-cancel-section (section)
12721272 "Delete the section SECTION."
12731273 (delete-region (magit-section-beginning section)
1274 (magit-section-end section))
1274 (magit-section-end section))
12751275 (let ((parent (magit-section-parent section)))
12761276 (if parent
1277 (setf (magit-section-children parent)
1278 (delq section (magit-section-children parent)))
1279 (setq magit-top-section nil))))
1277 (setf (magit-section-children parent)
1278 (delq section (magit-section-children parent)))
1279 (setq magit-top-section nil))))
12801280
12811281 (defmacro magit-with-section (title type &rest body)
12821282 "Create a new section of title TITLE and type TYPE and evaluate BODY there.
12881288 (declare (indent 2))
12891289 (let ((s (make-symbol "*section*")))
12901290 `(let* ((,s (magit-new-section ,title ,type))
1291 (magit-top-section ,s))
1291 (magit-top-section ,s))
12921292 (setf (magit-section-beginning ,s) (point))
12931293 ,@body
12941294 (setf (magit-section-end ,s) (point))
12951295 (setf (magit-section-children ,s)
1296 (nreverse (magit-section-children ,s)))
1296 (nreverse (magit-section-children ,s)))
12971297 ,s)))
12981298
12991299 (defun magit-set-section (title type start end)
13091309
13101310 (defun magit-set-section-needs-refresh-on-show (flag &optional section)
13111311 (setf (magit-section-needs-refresh-on-show
1312 (or section magit-top-section))
1313 flag))
1312 (or section magit-top-section))
1313 flag))
13141314
13151315 (defmacro magit-create-buffer-sections (&rest body)
13161316 "Empty current buffer of text and Magit's sections, and then evaluate BODY."
13211321 (setq magit-top-section nil)
13221322 ,@body
13231323 (when (null magit-top-section)
1324 (magit-with-section 'top nil
1325 (insert "(empty)\n")))
1324 (magit-with-section 'top nil
1325 (insert "(empty)\n")))
13261326 (magit-propertize-section magit-top-section)
13271327 (magit-section-set-hidden magit-top-section
1328 (magit-section-hidden magit-top-section)))))
1328 (magit-section-hidden magit-top-section)))))
13291329
13301330 (defun magit-propertize-section (section)
13311331 "Add text-property needed for SECTION."
13321332 (put-text-property (magit-section-beginning section)
1333 (magit-section-end section)
1334 'magit-section section)
1333 (magit-section-end section)
1334 'magit-section section)
13351335 (dolist (s (magit-section-children section))
13361336 (magit-propertize-section s)))
13371337
13411341 top
13421342 (let ((secs (magit-section-children top)))
13431343 (while (and secs (not (equal (car path)
1344 (magit-section-title (car secs)))))
1345 (setq secs (cdr secs)))
1344 (magit-section-title (car secs)))))
1345 (setq secs (cdr secs)))
13461346 (and (car secs)
1347 (magit-find-section (cdr path) (car secs))))))
1347 (magit-find-section (cdr path) (car secs))))))
13481348
13491349 (defun magit-section-path (section)
13501350 "Return the path of SECTION."
13511351 (if (not (magit-section-parent section))
13521352 '()
13531353 (append (magit-section-path (magit-section-parent section))
1354 (list (magit-section-title section)))))
1354 (list (magit-section-title section)))))
13551355
13561356 (defun magit-find-section-after (pos)
13571357 "Find the first section that begins after POS."
13991399 magit-top-section))
14001400
14011401 (defun magit-insert-section (section-title-and-type
1402 buffer-title washer cmd &rest args)
1402 buffer-title washer cmd &rest args)
14031403 "Run CMD and put its result in a new section.
14041404
14051405 SECTION-TITLE-AND-TYPE is either a string that is the title of the section
14151415
14161416 CMD is an external command that will be run with ARGS as arguments."
14171417 (let* ((body-beg nil)
1418 (section-title (if (consp section-title-and-type)
1419 (car section-title-and-type)
1420 section-title-and-type))
1421 (section-type (if (consp section-title-and-type)
1422 (cdr section-title-and-type)
1423 nil))
1424 (section
1425 (magit-with-section section-title section-type
1426 (if buffer-title
1427 (insert (propertize buffer-title 'face 'magit-section-title)
1428 "\n"))
1429 (setq body-beg (point))
1418 (section-title (if (consp section-title-and-type)
1419 (car section-title-and-type)
1420 section-title-and-type))
1421 (section-type (if (consp section-title-and-type)
1422 (cdr section-title-and-type)
1423 nil))
1424 (section
1425 (magit-with-section section-title section-type
1426 (if buffer-title
1427 (insert (propertize buffer-title 'face 'magit-section-title)
1428 "\n"))
1429 (setq body-beg (point))
14301430 (magit-cmd-insert cmd args)
1431 (if (not (eq (char-before) ?\n))
1432 (insert "\n"))
1433 (if washer
1434 (save-restriction
1435 (narrow-to-region body-beg (point))
1436 (goto-char (point-min))
1437 (funcall washer)
1438 (goto-char (point-max)))))))
1431 (if (not (eq (char-before) ?\n))
1432 (insert "\n"))
1433 (if washer
1434 (save-restriction
1435 (narrow-to-region body-beg (point))
1436 (goto-char (point-min))
1437 (funcall washer)
1438 (goto-char (point-max)))))))
14391439 (if (= body-beg (point))
1440 (magit-cancel-section section)
1440 (magit-cancel-section section)
14411441 (insert "\n"))
14421442 section))
14431443
14441444 (defun magit-git-section (section-title-and-type
1445 buffer-title washer &rest args)
1445 buffer-title washer &rest args)
14461446 "Run git and put its result in a new section.
14471447
14481448 see `magit-insert-section' for meaning of the arguments"
14491449 (apply #'magit-insert-section
1450 section-title-and-type
1451 buffer-title
1452 washer
1453 magit-git-executable
1454 (append magit-git-standard-options args)))
1450 section-title-and-type
1451 buffer-title
1452 washer
1453 magit-git-executable
1454 (append magit-git-standard-options args)))
14551455
14561456 (defun magit-goto-next-section ()
14571457 "Go to the next Magit section."
14911491 "Go to the section described by PATH."
14921492 (let ((sec (magit-find-section path magit-top-section)))
14931493 (if sec
1494 (goto-char (magit-section-beginning sec))
1494 (goto-char (magit-section-beginning sec))
14951495 (message "No such section"))))
14961496
14971497 (defun magit-for-all-sections (func &optional top)
15021502 (when section
15031503 (funcall func section)
15041504 (dolist (c (magit-section-children section))
1505 (magit-for-all-sections func c)))))
1505 (magit-for-all-sections func c)))))
15061506
15071507 (defun magit-section-set-hidden (section hidden)
15081508 "Hide SECTION if HIDDEN is not nil, show it otherwise."
15091509 (setf (magit-section-hidden section) hidden)
15101510 (if (and (not hidden)
1511 (magit-section-needs-refresh-on-show section))
1511 (magit-section-needs-refresh-on-show section))
15121512 (magit-refresh)
15131513 (let ((inhibit-read-only t)
1514 (beg (save-excursion
1515 (goto-char (magit-section-beginning section))
1516 (forward-line)
1517 (point)))
1518 (end (magit-section-end section)))
1514 (beg (save-excursion
1515 (goto-char (magit-section-beginning section))
1516 (forward-line)
1517 (point)))
1518 (end (magit-section-end section)))
15191519 (if (< beg end)
15201520 (put-text-property beg end 'invisible hidden)))
15211521 (if (not hidden)
1522 (dolist (c (magit-section-children section))
1523 (magit-section-set-hidden c (magit-section-hidden c))))))
1522 (dolist (c (magit-section-children section))
1523 (magit-section-set-hidden c (magit-section-hidden c))))))
15241524
15251525 (defun magit-section-any-hidden (section)
15261526 "Return true if SECTION or any of its children is hidden."
15271527 (or (magit-section-hidden section)
15281528 (let ((kids (magit-section-children section)))
1529 (while (and kids (not (magit-section-any-hidden (car kids))))
1530 (setq kids (cdr kids)))
1531 kids)))
1529 (while (and kids (not (magit-section-any-hidden (car kids))))
1530 (setq kids (cdr kids)))
1531 kids)))
15321532
15331533 (defun magit-section-collapse (section)
15341534 "Show SECTION and hide all its children."
15621562 (when (magit-section-parent section)
15631563 (goto-char (magit-section-beginning section))
15641564 (if (functionp flag-or-func)
1565 (funcall flag-or-func section)
1566 (magit-section-set-hidden section flag-or-func)))))
1565 (funcall flag-or-func section)
1566 (magit-section-set-hidden section flag-or-func)))))
15671567
15681568 (defun magit-show-section ()
15691569 "Show current section."
16051605 (magit-section-hideshow
16061606 (lambda (s)
16071607 (cond ((magit-section-any-hidden s)
1608 (magit-section-expand-all s))
1609 (t
1610 (magit-section-collapse s))))))
1608 (magit-section-expand-all s))
1609 (t
1610 (magit-section-collapse s))))))
16111611
16121612 (defun magit-cycle-section ()
16131613 "Cycle between expanded, hidden and collapsed state for current section.
16191619 (magit-section-hideshow
16201620 (lambda (s)
16211621 (cond ((magit-section-hidden s)
1622 (magit-section-collapse s))
1623 ((notany #'magit-section-hidden (magit-section-children s))
1624 (magit-section-set-hidden s t))
1625 (t
1626 (magit-section-expand s))))))
1622 (magit-section-collapse s))
1623 ((notany #'magit-section-hidden (magit-section-children s))
1624 (magit-section-set-hidden s t))
1625 (t
1626 (magit-section-expand s))))))
16271627
16281628 (defun magit-section-lineage (s)
16291629 "Return list of parent, grand-parents... for section S."
16341634 (magit-section-set-hidden section (>= level threshold))
16351635 (when (and (< level threshold)
16361636 (not (magit-no-commit-p)))
1637 (if path
1638 (magit-section-show-level (car path) (1+ level) threshold (cdr path))
1639 (dolist (c (magit-section-children section))
1640 (magit-section-show-level c (1+ level) threshold nil)))))
1637 (if path
1638 (magit-section-show-level (car path) (1+ level) threshold (cdr path))
1639 (dolist (c (magit-section-children section))
1640 (magit-section-show-level c (1+ level) threshold nil)))))
16411641
16421642 (defun magit-show-level (level all)
16431643 "Show section whose level is less than LEVEL, hide the others.
16451645 otherwise do it only on ancestors and descendants of current section."
16461646 (magit-with-refresh
16471647 (if all
1648 (magit-section-show-level magit-top-section 0 level nil)
1648 (magit-section-show-level magit-top-section 0 level nil)
16491649 (let ((path (reverse (magit-section-lineage (magit-current-section)))))
1650 (magit-section-show-level (car path) 0 level (cdr path))))))
1650 (magit-section-show-level (car path) 0 level (cdr path))))))
16511651
16521652 (defun magit-show-only-files ()
16531653 "Show section that are files, but not there subsection.
16731673 If ALL is non nil, this function will affect all section,
16741674 otherwise it will affect only ancestors and descendants of current section."
16751675 (let ((fun (intern (format "magit-show-level-%s%s"
1676 level (if all "-all" ""))))
1677 (doc (format "Show sections on level %s." level)))
1676 level (if all "-all" ""))))
1677 (doc (format "Show sections on level %s." level)))
16781678 `(defun ,fun ()
16791679 ,doc
16801680 (interactive)
16921692
16931693 TITLE is the displayed title of the section."
16941694 (let ((fun (intern (format "magit-jump-to-%s" sym)))
1695 (doc (format "Jump to section `%s'." title)))
1695 (doc (format "Jump to section `%s'." title)))
16961696 `(defun ,fun ()
16971697 ,doc
16981698 (interactive)
17201720 (when (not (eq section magit-highlighted-section))
17211721 (setq magit-highlighted-section section)
17221722 (if (not magit-highlight-overlay)
1723 (let ((ov (make-overlay 1 1)))
1724 (overlay-put ov 'face 'magit-item-highlight)
1725 (setq magit-highlight-overlay ov)))
1723 (let ((ov (make-overlay 1 1)))
1724 (overlay-put ov 'face 'magit-item-highlight)
1725 (setq magit-highlight-overlay ov)))
17261726 (if (and section (magit-section-type section))
1727 (move-overlay magit-highlight-overlay
1728 (magit-section-beginning section)
1729 (magit-section-end section)
1730 (current-buffer))
1731 (delete-overlay magit-highlight-overlay)))))
1727 (move-overlay magit-highlight-overlay
1728 (magit-section-beginning section)
1729 (magit-section-end section)
1730 (current-buffer))
1731 (delete-overlay magit-highlight-overlay)))))
17321732
17331733 (defun magit-section-context-type (section)
17341734 (if (null section)
17351735 '()
17361736 (let ((c (or (magit-section-type section)
1737 (if (symbolp (magit-section-title section))
1738 (magit-section-title section)))))
1737 (if (symbolp (magit-section-title section))
1738 (magit-section-title section)))))
17391739 (if c
1740 (cons c (magit-section-context-type
1741 (magit-section-parent section)))
1742 '()))))
1740 (cons c (magit-section-context-type
1741 (magit-section-parent section)))
1742 '()))))
17431743
17441744 (defun magit-prefix-p (prefix list)
17451745 "Returns non-nil if PREFIX is a prefix of LIST. PREFIX and LIST should both be
17871787 (cond ,@(mapcar (lambda (clause)
17881788 (if (eq (car clause) t)
17891789 `(t (or (progn ,@(cdr clause))
1790 t))
1790 t))
17911791 (let ((prefix (reverse (car clause)))
17921792 (body (cdr clause)))
17931793 `((magit-prefix-p ',prefix ,context)
17941794 (or (progn ,@body)
1795 t)))))
1795 t)))))
17961796 clauses)
17971797 ,@(when opname
17981798 `(((run-hook-with-args-until-success
18751875 (let ((pr (if str (concat " " str) "")))
18761876 (save-excursion
18771877 (magit-for-all-buffers (lambda ()
1878 (setq mode-line-process pr))))))
1878 (setq mode-line-process pr))))))
18791879
18801880 (defun magit-process-indicator-from-command (comps)
18811881 (if (magit-prefix-p (cons magit-git-executable magit-git-standard-options)
1882 comps)
1882 comps)
18831883 (setq comps (nthcdr (+ (length magit-git-standard-options) 1) comps)))
18841884 (cond ((or (null (cdr comps))
1885 (not (member (car comps) '("remote"))))
1886 (car comps))
1887 (t
1888 (concat (car comps) " " (cadr comps)))))
1885 (not (member (car comps) '("remote"))))
1886 (car comps))
1887 (t
1888 (concat (car comps) " " (cadr comps)))))
18891889
18901890 (defvar magit-process nil)
18911891 (defvar magit-process-client-buffer nil)
18931893 "Buffer name for running git commands.")
18941894
18951895 (defun magit-run* (cmd-and-args
1896 &optional logline noerase noerror nowait input)
1896 &optional logline noerase noerror nowait input)
18971897 (if (and magit-process
1898 (get-buffer magit-process-buffer-name))
1898 (get-buffer magit-process-buffer-name))
18991899 (error "Git is already running"))
19001900 (let ((cmd (car cmd-and-args))
1901 (args (cdr cmd-and-args))
1902 (dir default-directory)
1903 (buf (get-buffer-create magit-process-buffer-name))
1904 (successp nil))
1901 (args (cdr cmd-and-args))
1902 (dir default-directory)
1903 (buf (get-buffer-create magit-process-buffer-name))
1904 (successp nil))
19051905 (magit-set-mode-line-process
19061906 (magit-process-indicator-from-command cmd-and-args))
19071907 (setq magit-process-client-buffer (current-buffer))
19091909 (view-mode 1)
19101910 (set (make-local-variable 'view-no-disable-on-exit) t)
19111911 (setq view-exit-action
1912 (lambda (buffer)
1913 (with-current-buffer buffer
1914 (bury-buffer))))
1912 (lambda (buffer)
1913 (with-current-buffer buffer
1914 (bury-buffer))))
19151915 (setq buffer-read-only t)
19161916 (let ((inhibit-read-only t))
1917 (setq default-directory dir)
1918 (if noerase
1919 (goto-char (point-max))
1920 (erase-buffer))
1921 (insert "$ " (or logline
1922 (mapconcat 'identity cmd-and-args " "))
1923 "\n")
1924 (cond (nowait
1925 (setq magit-process
1926 (let ((process-connection-type magit-process-connection-type))
1927 (apply 'magit-start-process cmd buf cmd args)))
1928 (set-process-sentinel magit-process 'magit-process-sentinel)
1929 (set-process-filter magit-process 'magit-process-filter)
1930 (when input
1931 (with-current-buffer input
1932 (process-send-region magit-process
1933 (point-min) (point-max)))
1934 (process-send-eof magit-process)
1935 (sit-for 0.1 t))
1936 (cond ((= magit-process-popup-time 0)
1937 (pop-to-buffer (process-buffer magit-process)))
1938 ((> magit-process-popup-time 0)
1939 (run-with-timer
1940 magit-process-popup-time nil
1941 (function
1942 (lambda (buf)
1943 (with-current-buffer buf
1944 (when magit-process
1945 (display-buffer (process-buffer magit-process))
1946 (goto-char (point-max))))))
1947 (current-buffer))))
1948 (setq successp t))
1949 (input
1950 (with-current-buffer input
1951 (setq default-directory dir)
1952 (setq magit-process
1953 ;; Don't use a pty, because it would set icrnl
1954 ;; which would modify the input (issue #20).
1955 (let ((process-connection-type nil))
1956 (apply 'magit-start-process cmd buf cmd args)))
1957 (set-process-filter magit-process 'magit-process-filter)
1958 (process-send-region magit-process
1959 (point-min) (point-max))
1960 (process-send-eof magit-process)
1961 (while (equal (process-status magit-process) 'run)
1962 (sit-for 0.1 t))
1963 (setq successp
1964 (equal (process-exit-status magit-process) 0))
1965 (setq magit-process nil))
1966 (magit-set-mode-line-process nil)
1967 (magit-need-refresh magit-process-client-buffer))
1968 (t
1969 (setq successp
1970 (equal (apply 'process-file cmd nil buf nil args) 0))
1971 (magit-set-mode-line-process nil)
1972 (magit-need-refresh magit-process-client-buffer))))
1917 (setq default-directory dir)
1918 (if noerase
1919 (goto-char (point-max))
1920 (erase-buffer))
1921 (insert "$ " (or logline
1922 (mapconcat 'identity cmd-and-args " "))
1923 "\n")
1924 (cond (nowait
1925 (setq magit-process
1926 (let ((process-connection-type magit-process-connection-type))
1927 (apply 'magit-start-process cmd buf cmd args)))
1928 (set-process-sentinel magit-process 'magit-process-sentinel)
1929 (set-process-filter magit-process 'magit-process-filter)
1930 (when input
1931 (with-current-buffer input
1932 (process-send-region magit-process
1933 (point-min) (point-max)))
1934 (process-send-eof magit-process)
1935 (sit-for 0.1 t))
1936 (cond ((= magit-process-popup-time 0)
1937 (pop-to-buffer (process-buffer magit-process)))
1938 ((> magit-process-popup-time 0)
1939 (run-with-timer
1940 magit-process-popup-time nil
1941 (function
1942 (lambda (buf)
1943 (with-current-buffer buf
1944 (when magit-process
1945 (display-buffer (process-buffer magit-process))
1946 (goto-char (point-max))))))
1947 (current-buffer))))
1948 (setq successp t))
1949 (input
1950 (with-current-buffer input
1951 (setq default-directory dir)
1952 (setq magit-process
1953 ;; Don't use a pty, because it would set icrnl
1954 ;; which would modify the input (issue #20).
1955 (let ((process-connection-type nil))
1956 (apply 'magit-start-process cmd buf cmd args)))
1957 (set-process-filter magit-process 'magit-process-filter)
1958 (process-send-region magit-process
1959 (point-min) (point-max))
1960 (process-send-eof magit-process)
1961 (while (equal (process-status magit-process) 'run)
1962 (sit-for 0.1 t))
1963 (setq successp
1964 (equal (process-exit-status magit-process) 0))
1965 (setq magit-process nil))
1966 (magit-set-mode-line-process nil)
1967 (magit-need-refresh magit-process-client-buffer))
1968 (t
1969 (setq successp
1970 (equal (apply 'process-file cmd nil buf nil args) 0))
1971 (magit-set-mode-line-process nil)
1972 (magit-need-refresh magit-process-client-buffer))))
19731973 (or successp
1974 noerror
1975 (error
1974 noerror
1975 (error
19761976 "%s ... [Hit %s or see buffer %s for details]"
19771977 (or (with-current-buffer (get-buffer magit-process-buffer-name)
19781978 (when (re-search-backward
19881988 (autoload 'dired-uncache "dired")
19891989 (defun magit-process-sentinel (process event)
19901990 (let ((msg (format "%s %s." (process-name process) (substring event 0 -1)))
1991 (successp (string-match "^finished" event))
1991 (successp (string-match "^finished" event))
19921992 (key (with-current-buffer magit-process-client-buffer
19931993 (key-description (car (where-is-internal
19941994 'magit-display-process))))))
19951995 (with-current-buffer (process-buffer process)
19961996 (let ((inhibit-read-only t))
1997 (goto-char (point-max))
1998 (insert msg "\n")
1999 (message (if successp msg
1997 (goto-char (point-max))
1998 (insert msg "\n")
1999 (message (if successp msg
20002000 (format "%s Hit %s or see buffer %s for details."
20012001 msg key (current-buffer)))))
20022002 (unless (memq (process-status process) '(run open))
20142014 ((string-match "^[pP]assword:" string)
20152015 (setq ask "Password:")))
20162016 (when ask
2017 (process-send-string proc (concat (read-passwd ask nil) "\n")))))
2017 (process-send-string proc (concat (read-passwd ask nil) "\n")))))
20182018
20192019 (defun magit-process-filter (proc string)
20202020 (save-current-buffer
20252025 ;; Find last ^M in string. If one was found, ignore everything
20262026 ;; before it and delete the current line.
20272027 (let ((ret-pos (length string)))
2028 (while (and (>= (setq ret-pos (1- ret-pos)) 0)
2029 (/= ?\r (aref string ret-pos))))
2030 (cond ((>= ret-pos 0)
2031 (goto-char (line-beginning-position))
2032 (delete-region (point) (line-end-position))
2033 (insert (substring string (+ ret-pos 1))))
2034 (t
2035 (insert string))))
2028 (while (and (>= (setq ret-pos (1- ret-pos)) 0)
2029 (/= ?\r (aref string ret-pos))))
2030 (cond ((>= ret-pos 0)
2031 (goto-char (line-beginning-position))
2032 (delete-region (point) (line-end-position))
2033 (insert (substring string (+ ret-pos 1))))
2034 (t
2035 (insert string))))
20362036 (set-marker (process-mark proc) (point)))))
20372037
20382038 (defun magit-run (cmd &rest args)
20422042 (defun magit-run-git (&rest args)
20432043 (magit-with-refresh
20442044 (magit-run* (append (cons magit-git-executable
2045 magit-git-standard-options)
2046 args))))
2045 magit-git-standard-options)
2046 args))))
20472047
20482048 (defun magit-run-git-with-input (input &rest args)
20492049 (magit-with-refresh
20502050 (magit-run* (append (cons magit-git-executable
2051 magit-git-standard-options)
2052 args)
2053 nil nil nil nil input)))
2051 magit-git-standard-options)
2052 args)
2053 nil nil nil nil input)))
20542054
20552055 (defun magit-run-git-async (&rest args)
20562056 (message "Running %s %s" magit-git-executable (mapconcat 'identity args " "))
20572057 (magit-run* (append (cons magit-git-executable
2058 magit-git-standard-options)
2059 args)
2060 nil nil nil t))
2058 magit-git-standard-options)
2059 args)
2060 nil nil nil t))
20612061
20622062 (defun magit-run-async-with-input (input cmd &rest args)
20632063 (magit-run* (cons cmd args) nil nil nil t input))
21852185 before the last command."
21862186 (if (invisible-p (point))
21872187 (let ((end (magit-invisible-region-end (point))))
2188 (goto-char (if (= end last-point)
2189 (magit-invisible-region-start (point))
2190 end))))
2188 (goto-char (if (= end last-point)
2189 (magit-invisible-region-start (point))
2190 end))))
21912191 (setq disable-point-adjustment t))
21922192
21932193 (defun magit-post-command-hook ()
22042204 (buffer-disable-undo)
22052205 (setq buffer-read-only t)
22062206 (setq major-mode 'magit-mode
2207 mode-name "Magit"
2207 mode-name "Magit"
22082208 mode-line-process "")
22092209 (add-hook 'pre-command-hook #'magit-remember-point nil t)
22102210 (add-hook 'post-command-hook #'magit-post-command-hook t t)
22192219
22202220 (defun magit-mode-init (dir submode refresh-func &rest refresh-args)
22212221 (setq default-directory dir
2222 magit-refresh-function refresh-func
2223 magit-refresh-args refresh-args)
2222 magit-refresh-function refresh-func
2223 magit-refresh-args refresh-args)
22242224 (funcall submode)
22252225 (magit-refresh-buffer))
22262226
22472247 (dolist (buf (buffer-list))
22482248 (with-current-buffer buf
22492249 (if (and (derived-mode-p 'magit-mode)
2250 (or (null dir)
2251 (equal default-directory dir)))
2252 (funcall func)))))
2250 (or (null dir)
2251 (equal default-directory dir)))
2252 (funcall func)))))
22532253
22542254 (defun magit-refresh-buffer (&optional buffer)
22552255 (with-current-buffer (or buffer (current-buffer))
22562256 (let* ((old-line (line-number-at-pos))
22572257 (old-point (point))
2258 (old-section (magit-current-section))
2259 (old-path (and old-section
2260 (magit-section-path (magit-current-section)))))
2258 (old-section (magit-current-section))
2259 (old-path (and old-section
2260 (magit-section-path (magit-current-section)))))
22612261 (beginning-of-line)
22622262 (let ((section-line (and old-section
22632263 (count-lines
23022302 "Update the modeline for buffers representable by magit."
23032303 (dolist (buffer (buffer-list))
23042304 (when (and buffer
2305 (buffer-file-name buffer)
2306 (magit-string-has-prefix-p (buffer-file-name buffer) dir))
2305 (buffer-file-name buffer)
2306 (magit-string-has-prefix-p (buffer-file-name buffer) dir))
23072307 (with-current-buffer buffer
2308 (condition-case var
2309 (vc-find-file-hook)
2310 (error (let ((signal-data (cadr var)))
2311 (cond (t (magit-bug-report signal-data))))))))))
2308 (condition-case var
2309 (vc-find-file-hook)
2310 (error (let ((signal-data (cadr var)))
2311 (cond (t (magit-bug-report signal-data))))))))))
23122312
23132313 (defvar magit-refresh-needing-buffers nil)
23142314 (defvar magit-refresh-pending nil)
23172317 (if magit-refresh-pending
23182318 (funcall func)
23192319 (let* ((dir default-directory)
2320 (status-buffer (magit-find-status-buffer dir))
2321 (magit-refresh-needing-buffers nil)
2322 (magit-refresh-pending t))
2320 (status-buffer (magit-find-status-buffer dir))
2321 (magit-refresh-needing-buffers nil)
2322 (magit-refresh-pending t))
23232323 (unwind-protect
2324 (funcall func)
2325 (when magit-refresh-needing-buffers
2326 (magit-revert-buffers dir)
2327 (dolist (b (adjoin status-buffer
2328 magit-refresh-needing-buffers))
2329 (magit-refresh-buffer b)))))))
2324 (funcall func)
2325 (when magit-refresh-needing-buffers
2326 (magit-revert-buffers dir)
2327 (dolist (b (adjoin status-buffer
2328 magit-refresh-needing-buffers))
2329 (magit-refresh-buffer b)))))))
23302330
23312331 (defun magit-need-refresh (&optional buffer)
23322332 "Mark BUFFER as needing to be refreshed. If BUFFER is nil, use the
23532353 (defun magit-wash-untracked-file ()
23542354 (if (looking-at "^? \\(.*\\)$")
23552355 (let ((file (match-string-no-properties 1)))
2356 (delete-region (point) (+ (line-end-position) 1))
2357 (magit-with-section file 'file
2358 (magit-set-section-info file)
2359 (insert "\t" file "\n"))
2360 t)
2356 (delete-region (point) (+ (line-end-position) 1))
2357 (magit-with-section file 'file
2358 (magit-set-section-info file)
2359 (insert "\t" file "\n"))
2360 t)
23612361 nil))
23622362
23632363 (defun magit-wash-untracked-files ()
23742374 (unless (string= (magit-get "status" "showUntrackedFiles") "no")
23752375 (apply 'magit-git-section
23762376 `(untracked
2377 "Untracked files:"
2378 magit-wash-untracked-files
2379 "ls-files" "--others" "-t" "--exclude-standard"
2380 ,@(when magit-omit-untracked-dir-contents
2381 '("--directory"))))))
2377 "Untracked files:"
2378 magit-wash-untracked-files
2379 "ls-files" "--others" "-t" "--exclude-standard"
2380 ,@(when magit-omit-untracked-dir-contents
2381 '("--directory"))))))
23822382
23832383 ;;; Diffs and Hunks
23842384
24072407
24082408 (defun magit-diff-line-file ()
24092409 (cond ((looking-at "^diff --git ./\\(.*\\) ./\\(.*\\)$")
2410 (match-string-no-properties 2))
2411 ((looking-at "^diff --cc +\\(.*\\)$")
2412 (match-string-no-properties 1))
2413 (t
2414 nil)))
2410 (match-string-no-properties 2))
2411 ((looking-at "^diff --cc +\\(.*\\)$")
2412 (match-string-no-properties 1))
2413 (t
2414 nil)))
24152415
24162416 (defun magit-wash-diffs ()
24172417 (magit-wash-sequence #'magit-wash-diff-or-other-file))
24232423 (defun magit-wash-other-file ()
24242424 (if (looking-at "^? \\(.*\\)$")
24252425 (let ((file (match-string-no-properties 1)))
2426 (delete-region (point) (+ (line-end-position) 1))
2427 (magit-with-section file 'file
2428 (magit-set-section-info file)
2429 (insert "\tNew " file "\n"))
2430 t)
2426 (delete-region (point) (+ (line-end-position) 1))
2427 (magit-with-section file 'file
2428 (magit-set-section-info file)
2429 (insert "\tNew " file "\n"))
2430 t)
24312431 nil))
24322432
24332433 (defvar magit-hide-diffs nil)
24362436
24372437 (defun magit-insert-diff-title (status file file2)
24382438 (let ((status-text (case status
2439 ((unmerged)
2440 (format "Unmerged %s" file))
2441 ((new)
2442 (format "New %s" file))
2443 ((deleted)
2444 (format "Deleted %s" file))
2445 ((renamed)
2446 (format "Renamed %s (from %s)"
2447 file file2))
2448 ((modified)
2449 (format "Modified %s" file))
2450 ((typechange)
2451 (format "Typechange %s" file))
2452 (t
2453 (format "? %s" file)))))
2439 ((unmerged)
2440 (format "Unmerged %s" file))
2441 ((new)
2442 (format "New %s" file))
2443 ((deleted)
2444 (format "Deleted %s" file))
2445 ((renamed)
2446 (format "Renamed %s (from %s)"
2447 file file2))
2448 ((modified)
2449 (format "Modified %s" file))
2450 ((typechange)
2451 (format "Typechange %s" file))
2452 (t
2453 (format "? %s" file)))))
24542454 (insert (make-string magit-indentation-level ?\t) status-text "\n")))
24552455
24562456 (defvar magit-current-diff-range nil
24772477
24782478 (defun magit-wash-diff-section ()
24792479 (cond ((looking-at "^\\* Unmerged path \\(.*\\)")
2480 (let ((file (match-string-no-properties 1)))
2481 (delete-region (point) (line-end-position))
2482 (insert "\tUnmerged " file "\n")
2483 (magit-set-section-info (list 'unmerged file nil))
2484 t))
2485 ((looking-at "^diff")
2486 (let ((file (magit-diff-line-file))
2487 (end (save-excursion
2488 (forward-line) ;; skip over "diff" line
2489 (if (search-forward-regexp "^diff\\|^@@" nil t)
2490 (goto-char (match-beginning 0))
2491 (goto-char (point-max)))
2492 (point-marker))))
2493 (let* ((status (cond
2494 ((looking-at "^diff --cc")
2495 'unmerged)
2496 ((save-excursion
2497 (search-forward-regexp "^new file" end t))
2498 'new)
2499 ((save-excursion
2500 (search-forward-regexp "^deleted" end t))
2501 'deleted)
2502 ((save-excursion
2503 (search-forward-regexp "^rename" end t))
2504 'renamed)
2505 (t
2506 'modified)))
2507 (file2 (cond
2508 ((save-excursion
2509 (search-forward-regexp "^rename from \\(.*\\)"
2510 end t))
2511 (match-string-no-properties 1)))))
2480 (let ((file (match-string-no-properties 1)))
2481 (delete-region (point) (line-end-position))
2482 (insert "\tUnmerged " file "\n")
2483 (magit-set-section-info (list 'unmerged file nil))
2484 t))
2485 ((looking-at "^diff")
2486 (let ((file (magit-diff-line-file))
2487 (end (save-excursion
2488 (forward-line) ;; skip over "diff" line
2489 (if (search-forward-regexp "^diff\\|^@@" nil t)
2490 (goto-char (match-beginning 0))
2491 (goto-char (point-max)))
2492 (point-marker))))
2493 (let* ((status (cond
2494 ((looking-at "^diff --cc")
2495 'unmerged)
2496 ((save-excursion
2497 (search-forward-regexp "^new file" end t))
2498 'new)
2499 ((save-excursion
2500 (search-forward-regexp "^deleted" end t))
2501 'deleted)
2502 ((save-excursion
2503 (search-forward-regexp "^rename" end t))
2504 'renamed)
2505 (t
2506 'modified)))
2507 (file2 (cond
2508 ((save-excursion
2509 (search-forward-regexp "^rename from \\(.*\\)"
2510 end t))
2511 (match-string-no-properties 1)))))
25122512 (magit-set-section-info (list status
25132513 file
25142514 (or file2 file)
25152515 magit-current-diff-range))
2516 (magit-insert-diff-title status file file2)
2516 (magit-insert-diff-title status file file2)
25172517 (when (search-forward-regexp "\\(--- \\(.*\\)\n\\+\\+\\+ \\(.*\\)\n\\)" () t)
25182518 (when (match-string 1)
25192519 (add-text-properties (match-beginning 1) (match-end 1)
25222522 '(face magit-diff-file-header))
25232523 (add-text-properties (match-beginning 3) (match-end 3)
25242524 '(face magit-diff-file-header))))
2525 (goto-char end)
2526 (let ((magit-section-hidden-default nil))
2527 (magit-wash-sequence #'magit-wash-hunk))))
2528 t)
2529 (t
2530 nil)))
2525 (goto-char end)
2526 (let ((magit-section-hidden-default nil))
2527 (magit-wash-sequence #'magit-wash-hunk))))
2528 t)
2529 (t
2530 nil)))
25312531
25322532 (defun magit-wash-diff ()
25332533 (let ((magit-section-hidden-default magit-hide-diffs))
25482548
25492549 (defun magit-wash-hunk ()
25502550 (cond ((looking-at "\\(^@+\\)[^@]*@+.*")
2551 (let ((n-columns (1- (length (match-string 1))))
2552 (head (match-string 0)))
2553 (magit-with-section head 'hunk
2554 (add-text-properties (match-beginning 0) (match-end 0)
2555 '(face magit-diff-hunk-header))
2556 (forward-line)
2557 (while (not (or (eobp)
2558 (looking-at "^diff\\|^@@")))
2551 (let ((n-columns (1- (length (match-string 1))))
2552 (head (match-string 0)))
2553 (magit-with-section head 'hunk
2554 (add-text-properties (match-beginning 0) (match-end 0)
2555 '(face magit-diff-hunk-header))
2556 (forward-line)
2557 (while (not (or (eobp)
2558 (looking-at "^diff\\|^@@")))
25592559 (magit-highlight-line-whitespace)
2560 (let ((prefix (buffer-substring-no-properties
2561 (point) (min (+ (point) n-columns) (point-max)))))
2562 (cond ((string-match "\\+" prefix)
2563 (magit-put-line-property 'face 'magit-diff-add))
2564 ((string-match "-" prefix)
2565 (magit-put-line-property 'face 'magit-diff-del))
2566 (t
2567 (magit-put-line-property 'face 'magit-diff-none))))
2568 (forward-line))))
2569 t)
2570 (t
2571 nil)))
2560 (let ((prefix (buffer-substring-no-properties
2561 (point) (min (+ (point) n-columns) (point-max)))))
2562 (cond ((string-match "\\+" prefix)
2563 (magit-put-line-property 'face 'magit-diff-add))
2564 ((string-match "-" prefix)
2565 (magit-put-line-property 'face 'magit-diff-del))
2566 (t
2567 (magit-put-line-property 'face 'magit-diff-none))))
2568 (forward-line))))
2569 t)
2570 (t
2571 nil)))
25722572
25732573 (defvar magit-diff-options nil)
25742574
25752575 (defun magit-insert-diff (file status)
25762576 (let ((cmd magit-git-executable)
2577 (args (append (list "diff")
2578 (list (magit-diff-U-arg))
2579 magit-diff-options
2580 (list "--" file))))
2577 (args (append (list "diff")
2578 (list (magit-diff-U-arg))
2579 magit-diff-options
2580 (list "--" file))))
25812581 (let ((p (point)))
25822582 (magit-git-insert args)
25832583 (if (not (eq (char-before) ?\n))
2584 (insert "\n"))
2584 (insert "\n"))
25852585 (save-restriction
2586 (narrow-to-region p (point))
2587 (goto-char p)
2586 (narrow-to-region p (point))
2587 (goto-char p)
25882588 (cond
25892589 ((eq status 'typechange)
25902590 (magit-insert-diff-title status file file)
25912591 (magit-wash-typechange-section file))
25922592 (t
25932593 (magit-wash-diff-section)))
2594 (goto-char (point-max))))))
2594 (goto-char (point-max))))))
25952595
25962596 (defvar magit-last-raw-diff nil)
25972597 (defvar magit-ignore-unmerged-raw-diffs nil)
26042604 (if (looking-at
26052605 ":\\([0-7]+\\) \\([0-7]+\\) [0-9a-f]+ [0-9a-f]+ \\(.\\)[0-9]*\t\\([^\t\n]+\\)$")
26062606 (let ((old-perm (match-string-no-properties 1))
2607 (new-perm (match-string-no-properties 2))
2608 (status (case (string-to-char (match-string-no-properties 3))
2609 (?A 'new)
2610 (?D 'deleted)
2611 (?M 'modified)
2612 (?U 'unmerged)
2613 (?T 'typechange)
2614 (t nil)))
2615 (file (match-string-no-properties 4)))
2616 ;; If this is for the same file as the last diff, ignore it.
2617 ;; Unmerged files seem to get two entries.
2618 ;; We also ignore unmerged files when told so.
2619 (if (or (equal file magit-last-raw-diff)
2620 (and magit-ignore-unmerged-raw-diffs (eq status 'unmerged)))
2621 (delete-region (point) (+ (line-end-position) 1))
2622 (setq magit-last-raw-diff file)
2623 ;; The 'diff' section that is created here will not work with
2624 ;; magit-insert-diff-item-patch etc when we leave it empty.
2625 ;; Luckily, raw diffs are only produced for staged and
2626 ;; unstaged changes, and we never call
2627 ;; magit-insert-diff-item-patch on them. This is a bit
2628 ;; brittle, of course.
2629 (let ((magit-section-hidden-default magit-hide-diffs))
2630 (magit-with-section file 'diff
2631 (delete-region (point) (+ (line-end-position) 1))
2632 (if (not (magit-section-hidden magit-top-section))
2633 (magit-insert-diff file status)
2634 (magit-set-section-info (list status file nil))
2635 (magit-set-section-needs-refresh-on-show t)
2636 (magit-insert-diff-title status file nil)))))
2637 t)
2607 (new-perm (match-string-no-properties 2))
2608 (status (case (string-to-char (match-string-no-properties 3))
2609 (?A 'new)
2610 (?D 'deleted)
2611 (?M 'modified)
2612 (?U 'unmerged)
2613 (?T 'typechange)
2614 (t nil)))
2615 (file (match-string-no-properties 4)))
2616 ;; If this is for the same file as the last diff, ignore it.
2617 ;; Unmerged files seem to get two entries.
2618 ;; We also ignore unmerged files when told so.
2619 (if (or (equal file magit-last-raw-diff)
2620 (and magit-ignore-unmerged-raw-diffs (eq status 'unmerged)))
2621 (delete-region (point) (+ (line-end-position) 1))
2622 (setq magit-last-raw-diff file)
2623 ;; The 'diff' section that is created here will not work with
2624 ;; magit-insert-diff-item-patch etc when we leave it empty.
2625 ;; Luckily, raw diffs are only produced for staged and
2626 ;; unstaged changes, and we never call
2627 ;; magit-insert-diff-item-patch on them. This is a bit
2628 ;; brittle, of course.
2629 (let ((magit-section-hidden-default magit-hide-diffs))
2630 (magit-with-section file 'diff
2631 (delete-region (point) (+ (line-end-position) 1))
2632 (if (not (magit-section-hidden magit-top-section))
2633 (magit-insert-diff file status)
2634 (magit-set-section-info (list status file nil))
2635 (magit-set-section-needs-refresh-on-show t)
2636 (magit-insert-diff-title status file nil)))))
2637 t)
26382638 nil))
26392639
26402640 (defun magit-hunk-item-diff (hunk)
26412641 (let ((diff (magit-section-parent hunk)))
26422642 (or (eq (magit-section-type diff) 'diff)
2643 (error "Huh? Parent of hunk not a diff"))
2643 (error "Huh? Parent of hunk not a diff"))
26442644 diff))
26452645
26462646 (defun magit-diff-item-insert-header (diff buf)
26472647 (let ((beg (save-excursion
2648 (goto-char (magit-section-beginning diff))
2649 (forward-line)
2650 (point)))
2651 (end (if (magit-section-children diff)
2652 (magit-section-beginning (car (magit-section-children diff)))
2653 (magit-section-end diff))))
2648 (goto-char (magit-section-beginning diff))
2649 (forward-line)
2650 (point)))
2651 (end (if (magit-section-children diff)
2652 (magit-section-beginning (car (magit-section-children diff)))
2653 (magit-section-end diff))))
26542654 (magit-insert-region beg end buf)))
26552655
26562656 (defun magit-insert-diff-item-patch (diff buf)
26572657 (let ((beg (save-excursion
2658 (goto-char (magit-section-beginning diff))
2659 (forward-line)
2660 (point)))
2661 (end (magit-section-end diff)))
2658 (goto-char (magit-section-beginning diff))
2659 (forward-line)
2660 (point)))
2661 (end (magit-section-end diff)))
26622662 (magit-insert-region beg end buf)))
26632663
26642664 (defun magit-insert-hunk-item-patch (hunk buf)
26652665 (magit-diff-item-insert-header (magit-hunk-item-diff hunk) buf)
26662666 (magit-insert-region (magit-section-beginning hunk) (magit-section-end hunk)
2667 buf))
2667 buf))
26682668
26692669 (defun magit-insert-hunk-item-region-patch (hunk reverse beg end buf)
26702670 (magit-diff-item-insert-header (magit-hunk-item-diff hunk) buf)
26742674 (forward-line)
26752675 (let ((copy-op (if reverse "+" "-")))
26762676 (while (< (point) (magit-section-end hunk))
2677 (if (and (<= beg (point)) (< (point) end))
2678 (magit-insert-current-line buf)
2679 (cond ((looking-at " ")
2680 (magit-insert-current-line buf))
2681 ((looking-at copy-op)
2682 (let ((text (buffer-substring-no-properties
2683 (+ (point) 1) (line-beginning-position 2))))
2684 (with-current-buffer buf
2685 (insert " " text))))))
2686 (forward-line))))
2677 (if (and (<= beg (point)) (< (point) end))
2678 (magit-insert-current-line buf)
2679 (cond ((looking-at " ")
2680 (magit-insert-current-line buf))
2681 ((looking-at copy-op)
2682 (let ((text (buffer-substring-no-properties
2683 (+ (point) 1) (line-beginning-position 2))))
2684 (with-current-buffer buf
2685 (insert " " text))))))
2686 (forward-line))))
26872687 (with-current-buffer buf
26882688 (diff-fixup-modifs (point-min) (point-max))))
26892689
26902690 (defun magit-hunk-item-is-conflict-p (hunk)
26912691 ;;; XXX - Using the title is a bit too clever...
26922692 (string-match "^diff --cc"
2693 (magit-section-title (magit-hunk-item-diff hunk))))
2693 (magit-section-title (magit-hunk-item-diff hunk))))
26942694
26952695 (defun magit-hunk-item-target-line (hunk)
26962696 (save-excursion
26982698 (let ((line (line-number-at-pos)))
26992699 (goto-char (magit-section-beginning hunk))
27002700 (if (not (looking-at "@@+ .* \\+\\([0-9]+\\)\\(,[0-9]+\\)? @@+"))
2701 (error "Hunk header not found"))
2701 (error "Hunk header not found"))
27022702 (let ((target (string-to-number (match-string 1))))
2703 (forward-line)
2704 (while (< (line-number-at-pos) line)
2705 ;; XXX - deal with combined diffs
2706 (if (not (looking-at "-"))
2707 (setq target (+ target 1)))
2708 (forward-line))
2709 target))))
2703 (forward-line)
2704 (while (< (line-number-at-pos) line)
2705 ;; XXX - deal with combined diffs
2706 (if (not (looking-at "-"))
2707 (setq target (+ target 1)))
2708 (forward-line))
2709 target))))
27102710
27112711 (defun magit-show (commit filename &optional select prefix)
27122712 "Returns a buffer containing the contents of the file FILENAME, as stored in
27372737 (with-current-buffer buffer
27382738 (let ((tmpname (match-string 1 checkout-string)))
27392739 (magit-with-silent-modifications
2740 (insert-file-contents tmpname nil nil nil t))
2740 (insert-file-contents tmpname nil nil nil t))
27412741 (delete-file tmpname)))))
27422742 (t
27432743 (with-current-buffer buffer
27562756
27572757 (defmacro with-magit-tmp-buffer (var &rest body)
27582758 (declare (indent 1)
2759 (debug (symbolp &rest form)))
2759 (debug (symbolp &rest form)))
27602760 `(let ((,var (generate-new-buffer magit-tmp-buffer-name)))
27612761 (unwind-protect
2762 (progn ,@body)
2762 (progn ,@body)
27632763 (kill-buffer ,var))))
27642764
27652765 (defun magit-apply-diff-item (diff &rest args)
27682768 (with-magit-tmp-buffer tmp
27692769 (magit-insert-diff-item-patch diff tmp)
27702770 (apply #'magit-run-git-with-input tmp
2771 "apply" (append args (list "-")))))
2771 "apply" (append args (list "-")))))
27722772
27732773 (defun magit-apply-hunk-item* (hunk reverse &rest args)
27742774 (when (zerop magit-diff-context-lines)
27752775 (setq args (cons "--unidiff-zero" args)))
27762776 (with-magit-tmp-buffer tmp
27772777 (if (magit-use-region-p)
2778 (magit-insert-hunk-item-region-patch
2779 hunk reverse (region-beginning) (region-end) tmp)
2780 (magit-insert-hunk-item-patch hunk tmp))
2778 (magit-insert-hunk-item-region-patch
2779 hunk reverse (region-beginning) (region-end) tmp)
2780 (magit-insert-hunk-item-patch hunk tmp))
27812781 (apply #'magit-run-git-with-input tmp
2782 "apply" (append args (list "-")))))
2782 "apply" (append args (list "-")))))
27832783
27842784 (defun magit-apply-hunk-item (hunk &rest args)
27852785 (apply #'magit-apply-hunk-item* hunk nil args))
28092809
28102810 ;;; Logs and Commits
28112811
2812 ; Note: making this a plain defcustom would probably let users break
2813 ; the parser too easily
2812 ; Note: making this a plain defcustom would probably let users break
2813 ; the parser too easily
28142814 (defvar magit-git-log-options
28152815 '("--pretty=format:* %H %s"))
2816 ; --decorate=full otherwise some ref prefixes are stripped
2817 ; '("--pretty=format:* %H%d %s" "--decorate=full"))
2818
2816 ; --decorate=full otherwise some ref prefixes are stripped
2817 ; '("--pretty=format:* %H%d %s" "--decorate=full"))
28192818
28202819 ;;
28212820 ;; Regexps for parsing ref names
28292828
28302829 (defconst magit-ref-nonslash-re
28312830 (concat "\\(?:"
2832 ;; "no slash-separated component can begin with a dot ." (rule 1)
2833 "[^" magit-ref-nonchars "./]"
2834 ;; "cannot have two consecutive dots .. anywhere." (rule 3)
2835 "\\.?"
2831 ;; "no slash-separated component can begin with a dot ." (rule 1)
2832 "[^" magit-ref-nonchars "./]"
2833 ;; "cannot have two consecutive dots .. anywhere." (rule 3)
2834 "\\.?"
28362835 "\\)*")
28372836 "Regexp that matches the non-slash parts of a ref name.
28382837
28392838 Evaluate (man \"git-check-ref-format\") for details")
28402839
28412840 (defconst magit-refname-re
2842 (concat
2843 "\\(?:HEAD\\|"
2844
2845 "\\(?:tag: \\)?"
2846
2847 ;; optional non-slash sequence at the beginning
2848 magit-ref-nonslash-re
2849
2850 ;; any number of slash-prefixed sequences
2851 "\\(?:"
2852 "/"
2853 magit-ref-nonslash-re
2854 "\\)*"
2855
2856 "/" ;; "must contain at least one /." (rule 2)
2857 magit-ref-nonslash-re
2858
2859 ;; "cannot end with a slash / nor a dot .." (rule 5)
2860 "[^" magit-ref-nonchars "./]"
2861
2862 "\\)"
2863 )
2841 (concat
2842 "\\(?:HEAD\\|"
2843
2844 "\\(?:tag: \\)?"
2845
2846 ;; optional non-slash sequence at the beginning
2847 magit-ref-nonslash-re
2848
2849 ;; any number of slash-prefixed sequences
2850 "\\(?:"
2851 "/"
2852 magit-ref-nonslash-re
2853 "\\)*"
2854
2855 "/" ;; "must contain at least one /." (rule 2)
2856 magit-ref-nonslash-re
2857
2858 ;; "cannot end with a slash / nor a dot .." (rule 5)
2859 "[^" magit-ref-nonchars "./]"
2860
2861 "\\)"
2862 )
28642863 "Regexp that matches a git symbolic reference name.
28652864
28662865 Evaluate (man \"git-check-ref-format\") for details")
28702869 "^\\([_\\*|/ -.]+\\)?" ; graph (1)
28712870 "\\(?:commit \\)?" ; this happens in long mode
28722871 "\\(?:"
2873 "\\([0-9a-fA-F]\\{40\\}\\)" ; sha1 (2)
2874
2875
2876 "\\(?:" ; refs (3)
2877 " "
2878 "\\("
2879 "("
2880 magit-refname-re "\\(?:, " magit-refname-re "\\)*"
2881 ")"
2882 "\\)"
2883 "\\)?"
2872 "\\([0-9a-fA-F]\\{40\\}\\)" ; sha1 (2)
2873
2874 "\\(?:" ; refs (3)
2875 " "
2876 "\\("
2877 "("
2878 magit-refname-re "\\(?:, " magit-refname-re "\\)*"
2879 ")"
2880 "\\)"
2881 "\\)?"
28842882 "\\)?"
28852883
28862884 " ?\\(.*\\)$" ; msg (4)
29812979 (magit-with-section "longer" 'longer
29822980 (insert "type \"e\" to show more logs\n")))))))
29832981
2984
29852982 (defun magit-wash-log-line ()
29862983 (beginning-of-line)
29872984 (let ((line-re magit-log-oneline-re))
29912988 (sha1 (match-string 2))
29922989 (msg (match-string 4))
29932990 (refs (when (match-string 3)
2994 (delq nil
2995 (mapcar
2996 (lambda (s)
2997 (and (not
2998 (or (string= s "tag:")
2999 (string= s "HEAD"))) ; as of 1.6.6
3000 s))
3001 (split-string (match-string 3) "[(), ]" t))))))
2991 (delq nil
2992 (mapcar
2993 (lambda (s)
2994 (and (not
2995 (or (string= s "tag:")
2996 (string= s "HEAD"))) ; as of 1.6.6
2997 s))
2998 (split-string (match-string 3) "[(), ]" t))))))
30022999 (delete-region (point-at-bol) (point-at-eol))
30033000 (insert (funcall magit-present-log-line-function chart sha1 refs msg))
30043001 (goto-char (point-at-bol))
30863083 (magit-configure-have-decorate)
30873084 (magit-create-buffer-sections
30883085 (apply #'magit-git-section nil nil
3089 'magit-wash-commit
3090 "log"
3086 'magit-wash-commit
3087 "log"
30913088 "--max-count=1"
30923089 "--pretty=medium"
30933090 `(,@(if magit-have-abbrev (list "--no-abbrev-commit"))
31933190 (defun magit-refresh-marked-commits-in-buffer ()
31943191 (if (not magit-mark-overlay)
31953192 (let ((ov (make-overlay 1 1)))
3196 (overlay-put ov 'face 'magit-item-mark)
3197 (setq magit-mark-overlay ov)))
3193 (overlay-put ov 'face 'magit-item-mark)
3194 (setq magit-mark-overlay ov)))
31983195 (delete-overlay magit-mark-overlay)
31993196 (magit-for-all-sections
32003197 (lambda (section)
32013198 (when (and (eq (magit-section-type section) 'commit)
3202 (equal (magit-section-info section)
3203 magit-marked-commit))
3199 (equal (magit-section-info section)
3200 magit-marked-commit))
32043201 (move-overlay magit-mark-overlay
3205 (magit-section-beginning section)
3206 (magit-section-end section)
3207 (current-buffer))))))
3202 (magit-section-beginning section)
3203 (magit-section-end section)
3204 (current-buffer))))))
32083205
32093206 (defun magit-set-marked-commit (commit)
32103207 (setq magit-marked-commit commit)
32433240 (let ((merge (magit-get "branch" local-branch "merge")))
32443241 (save-match-data
32453242 (if (and merge (string-match "^refs/heads/\\(.+\\)" merge))
3246 (concat (if prepend-remote-name
3243 (concat (if prepend-remote-name
32473244 (concat "remotes/"
32483245 (magit-get "branch" local-branch "remote")
32493246 "/"))
32573254 (cond
32583255 ((string= "." remote)
32593256 (format "branch %s"
3260 (propertize remote-branch 'face 'magit-branch)))
3257 (propertize remote-branch 'face 'magit-branch)))
32613258 (remote
3262 (concat
3263 (propertize remote-branch 'face 'magit-branch)
3264 " @ "
3265 remote
3266 " ("
3267 (magit-get "remote" remote "url")
3268 ")"))
3259 (concat
3260 (propertize remote-branch 'face 'magit-branch)
3261 " @ "
3262 remote
3263 " ("
3264 (magit-get "remote" remote "url")
3265 ")"))
32693266 (t
32703267 (run-hook-with-args-until-success 'magit-remote-string-hook))))
32713268
32753272 (magit-create-buffer-sections
32763273 (magit-with-section 'status nil
32773274 (let* ((branch (magit-get-current-branch))
3278 (remote (and branch (magit-get "branch" branch "remote")))
3279 (remote-branch (or (and branch (magit-remote-branch-for branch)) branch))
3280 (remote-string (magit-remote-string remote remote-branch))
3281 (head (magit-git-string
3282 "log" "--max-count=1" "--abbrev-commit" "--pretty=oneline"))
3283 (no-commit (not head)))
3284 (when remote-string
3285 (insert "Remote: " remote-string "\n"))
3286 (insert (format "Local: %s %s\n"
3287 (propertize (magit--bisect-info-for-status branch)
3288 'face 'magit-branch)
3289 (abbreviate-file-name default-directory)))
3290 (insert (format "Head: %s\n"
3291 (if no-commit "nothing commited (yet)" head)))
3292 (let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
3293 (if merge-heads
3294 (insert (format "Merging: %s\n"
3295 (mapconcat 'identity
3275 (remote (and branch (magit-get "branch" branch "remote")))
3276 (remote-branch (or (and branch (magit-remote-branch-for branch)) branch))
3277 (remote-string (magit-remote-string remote remote-branch))
3278 (head (magit-git-string
3279 "log" "--max-count=1" "--abbrev-commit" "--pretty=oneline"))
3280 (no-commit (not head)))
3281 (when remote-string
3282 (insert "Remote: " remote-string "\n"))
3283 (insert (format "Local: %s %s\n"
3284 (propertize (magit--bisect-info-for-status branch)
3285 'face 'magit-branch)
3286 (abbreviate-file-name default-directory)))
3287 (insert (format "Head: %s\n"
3288 (if no-commit "nothing commited (yet)" head)))
3289 (let ((merge-heads (magit-file-lines ".git/MERGE_HEAD")))
3290 (if merge-heads
3291 (insert (format "Merging: %s\n"
3292 (mapconcat 'identity
32963293 (mapcar 'magit-name-rev merge-heads)
32973294 ", ")))))
3298 (let ((rebase (magit-rebase-info)))
3299 (if rebase
3300 (insert (apply 'format "Rebasing: onto %s (%s of %s); Press \"R\" to Abort, Skip, or Continue\n" rebase))))
3301 (insert "\n")
3302 (magit-git-exit-code "update-index" "--refresh")
3303 (magit-insert-stashes)
3295 (let ((rebase (magit-rebase-info)))
3296 (if rebase
3297 (insert (apply 'format "Rebasing: onto %s (%s of %s); Press \"R\" to Abort, Skip, or Continue\n" rebase))))
3298 (insert "\n")
3299 (magit-git-exit-code "update-index" "--refresh")
3300 (magit-insert-stashes)
33043301 (magit-insert-untracked-files)
3305 (magit-insert-pending-changes)
3306 (magit-insert-pending-commits)
3307 (magit-insert-unpulled-commits remote remote-branch)
3308 (let ((staged (or no-commit (magit-anything-staged-p))))
3309 (magit-insert-unstaged-changes
3310 (if staged "Unstaged changes:" "Changes:"))
3311 (magit-insert-staged-changes staged no-commit))
3312 (magit-insert-unpushed-commits remote remote-branch)
3313 (run-hooks 'magit-refresh-status-hook)))))
3302 (magit-insert-pending-changes)
3303 (magit-insert-pending-commits)
3304 (magit-insert-unpulled-commits remote remote-branch)
3305 (let ((staged (or no-commit (magit-anything-staged-p))))
3306 (magit-insert-unstaged-changes
3307 (if staged "Unstaged changes:" "Changes:"))
3308 (magit-insert-staged-changes staged no-commit))
3309 (magit-insert-unpushed-commits remote remote-branch)
3310 (run-hooks 'magit-refresh-status-hook)))))
33143311
33153312 (defun magit-init (dir)
33163313 "Initialize git repository in the DIR directory."
33173314 (interactive (list (read-directory-name "Directory for Git repository: ")))
33183315 (let ((topdir (magit-get-top-dir dir)))
33193316 (when (or (not topdir)
3320 (yes-or-no-p
3321 (format
3322 (if (string-equal topdir (expand-file-name dir))
3323 "There is already a Git repository in %s. Reinitialize? "
3324 "There is a Git repository in %s. Create another in %s? ")
3325 topdir dir)))
3317 (yes-or-no-p
3318 (format
3319 (if (string-equal topdir (expand-file-name dir))
3320 "There is already a Git repository in %s. Reinitialize? "
3321 "There is a Git repository in %s. Create another in %s? ")
3322 topdir dir)))
33263323 (unless (file-directory-p dir)
3327 (and (y-or-n-p (format "Directory %s does not exists. Create it? " dir))
3328 (make-directory dir)))
3324 (and (y-or-n-p (format "Directory %s does not exists. Create it? " dir))
3325 (make-directory dir)))
33293326 (let ((default-directory dir))
3330 (magit-run* (list magit-git-executable "init"))))))
3327 (magit-run* (list magit-git-executable "init"))))))
33313328
33323329 (define-derived-mode magit-status-mode magit-mode "Magit"
3333 "Mode for looking at git status.
3330 "Mode for looking at git status.
33343331
33353332 \\{magit-status-mode-map}"
33363333 :group 'magit)
33603357 predicate-function)
33613358 (when msg
33623359 (message msg)))))
3363
33643360
33653361 (defun magit-save-buffers-predicate-all ()
33663362 "Prompt to save all buffers with unsaved changes"
33933389 (let ((topdir (magit-get-top-dir dir)))
33943390 (unless topdir
33953391 (when (y-or-n-p (format "There is no Git repository in %S. Create one? "
3396 dir))
3397 (magit-init dir)
3398 (setq topdir (magit-get-top-dir dir))))
3392 dir))
3393 (magit-init dir)
3394 (setq topdir (magit-get-top-dir dir))))
33993395 (when topdir
34003396 (let ((buf (or (magit-find-status-buffer topdir)
3401 (generate-new-buffer
3402 (concat "*magit: "
3403 (file-name-nondirectory
3404 (directory-file-name topdir)) "*")))))
3397 (generate-new-buffer
3398 (concat "*magit: "
3399 (file-name-nondirectory
3400 (directory-file-name topdir)) "*")))))
34053401 (funcall magit-status-buffer-switch-function buf)
34063402 (magit-mode-init topdir 'magit-status-mode #'magit-refresh-status)))))
34073403
34583454 (magit-apply-hunk-item-reverse item "--cached"))
34593455 ((staged diff)
34603456 (if (eq (car info) 'unmerged)
3461 (error "Can't unstage an unmerged file. Resolve it first"))
3457 (error "Can't unstage an unmerged file. Resolve it first"))
34623458 (if (magit-no-commit-p)
3463 (magit-run-git "rm" "--cached" "--" (magit-diff-item-file item))
3464 (magit-run-git "reset" "-q" "HEAD" "--" (magit-diff-item-file item))))
3459 (magit-run-git "rm" "--cached" "--" (magit-diff-item-file item))
3460 (magit-run-git "reset" "-q" "HEAD" "--" (magit-diff-item-file item))))
34653461 ((unstaged *)
34663462 (error "Already unstaged"))
34673463 ((diff diff)
35533549 magit-uninteresting-refs)))))
35543550 (if revision
35553551 (when (not (magit-maybe-create-local-tracking-branch revision))
3556 (magit-save-some-buffers)
3557 (magit-run-git "checkout" (magit-rev-to-git revision))
3558 (magit-update-vc-modeline default-directory))))
3552 (magit-save-some-buffers)
3553 (magit-run-git "checkout" (magit-rev-to-git revision))
3554 (magit-update-vc-modeline default-directory))))
35593555
35603556 (defun magit-read-create-branch-args ()
35613557 (let* ((cur-branch (magit-get-current-branch))
3562 (cur-point (magit-default-rev))
3563 (branch (read-string "Create branch: "))
3564 (parent (magit-read-rev "Parent"
3565 (cond
3566 ((eq magit-create-branch-behaviour 'at-point) cur-point)
3567 ((eq magit-create-branch-behaviour 'at-head) cur-branch)
3568 (t cur-branch)))))
3558 (cur-point (magit-default-rev))
3559 (branch (read-string "Create branch: "))
3560 (parent (magit-read-rev "Parent"
3561 (cond
3562 ((eq magit-create-branch-behaviour 'at-point) cur-point)
3563 ((eq magit-create-branch-behaviour 'at-head) cur-branch)
3564 (t cur-branch)))))
35693565 (list branch parent)))
35703566
35713567 (magit-define-command create-branch (branch parent)
35743570 \('git checkout -b BRANCH REVISION')."
35753571 (interactive (magit-read-create-branch-args))
35763572 (when (and branch (not (string= branch ""))
3577 parent)
3573 parent)
35783574 (magit-save-some-buffers)
35793575 (magit-run-git "checkout" "-b"
3580 branch
3581 (append
3582 magit-custom-options
3583 (magit-rev-to-git parent)))
3576 branch
3577 (append
3578 magit-custom-options
3579 (magit-rev-to-git parent)))
35843580 (magit-update-vc-modeline default-directory)))
35853581
35863582 (defun magit-delete-branch (branch)
35903586 (interactive (list (magit-read-rev "Branch to delete" (magit-default-rev))))
35913587 (when (and branch (string= branch (magit-get-current-branch)))
35923588 (if (y-or-n-p "Cannot delete current branch. Switch to master first? ")
3593 (magit-checkout "master")
3589 (magit-checkout "master")
35943590 (setq branch nil)))
35953591 (when branch
35963592 (magit-run-git "branch" "-d" (append magit-custom-options
3597 (magit-rev-to-git branch)))))
3593 (magit-rev-to-git branch)))))
35983594
35993595 (defun magit-delete-branch-forced (branch)
36003596 "Asks for a branch and deletes it, irrespective of its merged status.
36143610 If the branch is the current one, offers to switch to `master' first.
36153611 \('git branch -m OLD NEW')."
36163612 (interactive (list (magit-read-rev "Old name" (magit-default-rev))
3617 (magit-read-rev "New name" (magit-default-rev))))
3613 (magit-read-rev "New name" (magit-default-rev))))
36183614 (magit-run-git "branch" "-m" (magit-rev-to-git old) new))
36193615
36203616 ;;; Merging
36773673 (interactive)
36783674 (let ((info (magit-rebase-info)))
36793675 (if (not info)
3680 (let* ((current-branch (magit-get-current-branch))
3676 (let* ((current-branch (magit-get-current-branch))
36813677 (remote (when current-branch
36823678 (magit-get "branch" current-branch "remote")))
36833679 (remote-branch (when remote
36913687 (cons (concat "refs/heads/" current-branch)
36923688 magit-uninteresting-refs)
36933689 magit-uninteresting-refs))))
3694 (if rev
3695 (magit-run-git "rebase" (magit-rev-to-git rev))))
3690 (if rev
3691 (magit-run-git "rebase" (magit-rev-to-git rev))))
36963692 (let ((cursor-in-echo-area t)
36973693 (message-log-max nil))
36983694 (message "Rebase in progress. [A]bort, [S]kip, or [C]ontinue? ")
37143710 and staging area are lost.
37153711 \('git reset [--soft|--hard] REVISION')."
37163712 (interactive (list (magit-read-rev (format "%s head to"
3717 (if current-prefix-arg
3718 "Hard reset"
3719 "Reset"))
3720 (or (magit-default-rev)
3721 "HEAD^"))
3722 current-prefix-arg))
3713 (if current-prefix-arg
3714 "Hard reset"
3715 "Reset"))
3716 (or (magit-default-rev)
3717 "HEAD^"))
3718 current-prefix-arg))
37233719 (when revision
37243720 (magit-run-git "reset" (if hard "--hard" "--soft")
3725 (magit-rev-to-git revision))
3721 (magit-rev-to-git revision))
37263722 (magit-update-vc-modeline default-directory)))
37273723
37283724 (magit-define-command reset-head-hard (revision)
37303726 Uncomitted changes in both working tree and staging area are lost.
37313727 \('git reset --hard REVISION')."
37323728 (interactive (list (magit-read-rev (format "Hard reset head to")
3733 (or (magit-default-rev)
3734 "HEAD"))))
3729 (or (magit-default-rev)
3730 "HEAD"))))
37353731 (magit-reset-head revision t))
37363732
37373733 (magit-define-command reset-working-tree (&optional include-untracked)
37643760
37653761 (magit-define-inserter pending-commits ()
37663762 (let* ((info (magit-read-rewrite-info))
3767 (pending (cdr (assq 'pending info))))
3763 (pending (cdr (assq 'pending info))))
37683764 (when pending
37693765 (magit-with-section 'pending nil
3770 (insert (propertize "Pending commits:\n"
3771 'face 'magit-section-title))
3772 (dolist (p pending)
3773 (let* ((commit (car p))
3774 (properties (cdr p))
3775 (used (plist-get properties 'used)))
3776 (magit-with-section commit 'commit
3777 (magit-set-section-info commit)
3778 (insert (magit-git-string
3779 "log" "--max-count=1"
3780 (if used
3781 "--pretty=format:. %s"
3782 "--pretty=format:* %s")
3783 commit "--")
3784 "\n")))))
3766 (insert (propertize "Pending commits:\n"
3767 'face 'magit-section-title))
3768 (dolist (p pending)
3769 (let* ((commit (car p))
3770 (properties (cdr p))
3771 (used (plist-get properties 'used)))
3772 (magit-with-section commit 'commit
3773 (magit-set-section-info commit)
3774 (insert (magit-git-string
3775 "log" "--max-count=1"
3776 (if used
3777 "--pretty=format:. %s"
3778 "--pretty=format:* %s")
3779 commit "--")
3780 "\n")))))
37853781 (insert "\n"))))
37863782
37873783 (defun magit-rewrite-set-commit-property (commit prop value)
37883784 (let* ((info (magit-read-rewrite-info))
3789 (pending (cdr (assq 'pending info)))
3790 (p (assoc commit pending)))
3785 (pending (cdr (assq 'pending info)))
3786 (p (assoc commit pending)))
37913787 (when p
37923788 (setf (cdr p) (plist-put (cdr p) prop value))
37933789 (magit-write-rewrite-info info)
38073803
38083804 (magit-define-inserter pending-changes ()
38093805 (let* ((info (magit-read-rewrite-info))
3810 (orig (cadr (assq 'orig info))))
3806 (orig (cadr (assq 'orig info))))
38113807 (when orig
38123808 (let ((magit-hide-diffs t))
3813 (magit-git-section 'pending-changes
3814 "Pending changes"
3815 'magit-wash-diffs
3816 "diff" (magit-diff-U-arg) "-R" orig)))))
3809 (magit-git-section 'pending-changes
3810 "Pending changes"
3811 'magit-wash-diffs
3812 "diff" (magit-diff-U-arg) "-R" orig)))))
38173813
38183814 (defun magit-rewrite-start (from &optional onto)
38193815 (interactive (list (magit-read-rev "Rewrite from" (magit-default-rev))))
38333829 (car (magit-commit-parents from))
38343830 (error "Can't rewrite a parentless commit."))
38353831 from))
3836 (pending (magit-git-lines "rev-list" (concat base ".."))))
3832 (pending (magit-git-lines "rev-list" (concat base ".."))))
38373833 (magit-write-rewrite-info `((orig ,orig)
3838 (pending ,@(mapcar #'list pending))))
3834 (pending ,@(mapcar #'list pending))))
38393835 (magit-run-git "reset" "--hard" base)))
38403836
38413837 (defun magit-rewrite-stop (&optional noconfirm)
38423838 (interactive)
38433839 (let* ((info (magit-read-rewrite-info)))
38443840 (or info
3845 (error "No rewrite in progress"))
3841 (error "No rewrite in progress"))
38463842 (when (or noconfirm
3847 (yes-or-no-p "Stop rewrite? "))
3843 (yes-or-no-p "Stop rewrite? "))
38483844 (magit-write-rewrite-info nil)
38493845 (magit-refresh))))
38503846
38513847 (defun magit-rewrite-abort ()
38523848 (interactive)
38533849 (let* ((info (magit-read-rewrite-info))
3854 (orig (cadr (assq 'orig info))))
3850 (orig (cadr (assq 'orig info))))
38553851 (or info
3856 (error "No rewrite in progress"))
3852 (error "No rewrite in progress"))
38573853 (or (magit-everything-clean-p)
3858 (error "You have uncommitted changes"))
3854 (error "You have uncommitted changes"))
38593855 (when (yes-or-no-p "Abort rewrite? ")
38603856 (magit-write-rewrite-info nil)
38613857 (magit-run-git "reset" "--hard" orig))))
38683864 (defun magit-rewrite-finish-step (first-p)
38693865 (let ((info (magit-read-rewrite-info)))
38703866 (or info
3871 (error "No rewrite in progress"))
3867 (error "No rewrite in progress"))
38723868 (let* ((pending (cdr (assq 'pending info)))
3873 (first-unused
3874 (let ((rpend (reverse pending)))
3875 (while (and rpend (plist-get (cdr (car rpend)) 'used))
3876 (setq rpend (cdr rpend)))
3877 (car rpend)))
3878 (commit (car first-unused)))
3869 (first-unused
3870 (let ((rpend (reverse pending)))
3871 (while (and rpend (plist-get (cdr (car rpend)) 'used))
3872 (setq rpend (cdr rpend)))
3873 (car rpend)))
3874 (commit (car first-unused)))
38793875 (cond ((not first-unused)
3880 (magit-rewrite-stop t))
3881 ((magit-apply-commit commit t (not first-p))
3882 (magit-rewrite-set-commit-property commit 'used t)
3883 (magit-rewrite-finish-step nil))))))
3876 (magit-rewrite-stop t))
3877 ((magit-apply-commit commit t (not first-p))
3878 (magit-rewrite-set-commit-property commit 'used t)
3879 (magit-rewrite-finish-step nil))))))
38843880
38853881 ;;; Updating, pull, and push
38863882
39063902 "Run git pull against the current remote."
39073903 (interactive)
39083904 (let* ((branch (magit-get-current-branch))
3909 (config-branch (and branch (magit-get "branch" branch "merge")))
3910 (merge-branch (or (and config-branch (not current-prefix-arg))
3911 (magit-read-rev (format "Pull from")))))
3905 (config-branch (and branch (magit-get "branch" branch "merge")))
3906 (merge-branch (or (and config-branch (not current-prefix-arg))
3907 (magit-read-rev (format "Pull from")))))
39123908 (if (and branch (not config-branch))
3913 (magit-set merge-branch "branch" branch "merge"))
3909 (magit-set merge-branch "branch" branch "merge"))
39143910 (apply 'magit-run-git-async "pull" "-v" magit-custom-options)))
39153911
39163912 (eval-when-compile (require 'eshell))
39253921 "Perform arbitrary shell COMMAND."
39263922 (interactive "sCommand: ")
39273923 (let ((args (magit-parse-arguments command))
3928 (magit-process-popup-time 0))
3924 (magit-process-popup-time 0))
39293925 (magit-run* args nil nil nil t)))
39303926
39313927 (defun magit-git-command (command)
39363932 (interactive "sRun git like this: ")
39373933 (require 'pcomplete)
39383934 (let ((args (magit-parse-arguments command))
3939 (magit-process-popup-time 0))
3935 (magit-process-popup-time 0))
39403936 (magit-with-refresh
39413937 (magit-run* (append (cons magit-git-executable
39423938 magit-git-standard-options)
39513947 (magit-define-command push ()
39523948 (interactive)
39533949 (let* ((branch (or (magit-get-current-branch)
3954 (error "Don't push a detached head. That's gross")))
3955 (branch-remote (magit-get-remote branch))
3956 (push-remote (if (or current-prefix-arg
3957 (not branch-remote))
3958 (magit-read-remote (format "Push %s to: " branch)
3959 branch-remote)
3960 branch-remote))
3961 (ref-branch (magit-get "branch" branch "merge")))
3950 (error "Don't push a detached head. That's gross")))
3951 (branch-remote (magit-get-remote branch))
3952 (push-remote (if (or current-prefix-arg
3953 (not branch-remote))
3954 (magit-read-remote (format "Push %s to: " branch)
3955 branch-remote)
3956 branch-remote))
3957 (ref-branch (magit-get "branch" branch "merge")))
39623958 (if (and (not ref-branch)
39633959 (eq magit-set-upstream-on-push 'refuse))
39643960 (error "Not pushing since no upstream has been set.")
39823978 (unless ref-branch
39833979 (magit-set (concat "refs/heads/" branch) "branch" branch "merge"))))))
39843980
3985
39863981 ;;; Log edit mode
39873982
39883983 (defvar magit-log-edit-buffer-name "*magit-edit-log*"
40013996 (define-key map (kbd "C-c C-k") 'magit-log-edit-cancel-log-message)
40023997 (define-key map (kbd "C-c C-]") 'magit-log-edit-cancel-log-message)
40033998 (define-key map (kbd "C-x C-s") (lambda ()
4004 (interactive)
4005 (message "Not saved. Use C-c C-c to finalize this commit message.")))
3999 (interactive)
4000 (message "Not saved. Use C-c C-c to finalize this commit message.")))
40064001 map))
40074002
40084003 (defvar magit-pre-log-edit-window-configuration nil)
40174012 (goto-char (point-min))
40184013 (goto-char (point-min))
40194014 (if (re-search-forward "[ \t\n]*\\'" nil t)
4020 (replace-match "\n" nil nil))))
4015 (replace-match "\n" nil nil))))
40214016
40224017 (defun magit-log-edit-append (str)
40234018 (with-current-buffer (get-buffer-create magit-log-edit-buffer-name)
40284023
40294024 (defun magit-log-edit-get-fields ()
40304025 (let ((buf (get-buffer magit-log-edit-buffer-name))
4031 (result nil))
4026 (result nil))
40324027 (if buf
4033 (with-current-buffer buf
4034 (goto-char (point-min))
4028 (with-current-buffer buf
4029 (goto-char (point-min))
40354030 (while (looking-at "^\\([A-Za-z0-9-_]+\\): *\\(.+\\)?$")
4036 (setq result (acons (intern (downcase (match-string 1)))
4031 (setq result (acons (intern (downcase (match-string 1)))
40374032 (read (or (match-string 2) "nil"))
4038 result))
4039 (forward-line))
4040 (if (not (looking-at (regexp-quote magit-log-header-end)))
4041 (setq result nil))))
4033 result))
4034 (forward-line))
4035 (if (not (looking-at (regexp-quote magit-log-header-end)))
4036 (setq result nil))))
40424037 (nreverse result)))
40434038
40444039 (defun magit-log-edit-set-fields (fields)
40464041 (with-current-buffer buf
40474042 (goto-char (point-min))
40484043 (if (search-forward-regexp (format "^\\([A-Za-z0-9-_]+:.*\n\\)*%s"
4049 (regexp-quote magit-log-header-end))
4050 nil t)
4051 (delete-region (match-beginning 0) (match-end 0)))
4044 (regexp-quote magit-log-header-end))
4045 nil t)
4046 (delete-region (match-beginning 0) (match-end 0)))
40524047 (goto-char (point-min))
40534048 (when fields
4054 (while fields
4049 (while fields
40554050 (insert (capitalize (symbol-name (caar fields))) ": "
40564051 (prin1-to-string (cdar fields)) "\n")
4057 (setq fields (cdr fields)))
4058 (insert magit-log-header-end)))))
4052 (setq fields (cdr fields)))
4053 (insert magit-log-header-end)))))
40594054
40604055 (defun magit-log-edit-set-field (name value)
40614056 (let* ((fields (magit-log-edit-get-fields))
4062 (cell (assq name fields)))
4057 (cell (assq name fields)))
40634058 (cond (cell
4064 (if value
4065 (rplacd cell value)
4066 (setq fields (delq cell fields))))
4067 (t
4068 (if value
4069 (setq fields (append fields (list (cons name value)))))))
4059 (if value
4060 (rplacd cell value)
4061 (setq fields (delq cell fields))))
4062 (t
4063 (if value
4064 (setq fields (append fields (list (cons name value)))))))
40704065 (magit-log-edit-set-fields fields)))
40714066
40724067 (defun magit-log-edit-get-field (name)
40804075 toggled on. When it's toggled on for the first time, return
40814076 'first."
40824077 (let* ((fields (magit-log-edit-get-fields))
4083 (cell (assq name fields)) yesp)
4078 (cell (assq name fields)) yesp)
40844079 (if cell
40854080 (progn
40864081 (setq yesp (equal (cdr cell) "yes"))
40984093 Return nil if the input is toggled off, and its valud if it's
40994094 toggled on."
41004095 (let* ((fields (magit-log-edit-get-fields))
4101 (cell (assq name fields))
4096 (cell (assq name fields))
41024097 result)
41034098 (if cell
41044099 (progn
41274122
41284123 (defun magit-log-edit-push-to-comment-ring (comment)
41294124 (when (or (ring-empty-p log-edit-comment-ring)
4130 (not (equal comment (ring-ref log-edit-comment-ring 0))))
4125 (not (equal comment (ring-ref log-edit-comment-ring 0))))
41314126 (ring-insert log-edit-comment-ring comment)))
41324127
41334128 (defun magit-log-edit-commit ()
41354130 \('git commit ...')"
41364131 (interactive)
41374132 (let* ((fields (magit-log-edit-get-fields))
4138 (amend (equal (cdr (assq 'amend fields)) "yes"))
4139 (allow-empty (equal (cdr (assq 'allow-empty fields)) "yes"))
4140 (commit-all (equal (cdr (assq 'commit-all fields)) "yes"))
4141 (sign-off-field (assq 'sign-off fields))
4142 (sign-off (if sign-off-field
4143 (equal (cdr sign-off-field) "yes")
4144 magit-commit-signoff))
4145 (tag-rev (cdr (assq 'tag-rev fields)))
4146 (tag-name (cdr (assq 'tag-name fields)))
4133 (amend (equal (cdr (assq 'amend fields)) "yes"))
4134 (allow-empty (equal (cdr (assq 'allow-empty fields)) "yes"))
4135 (commit-all (equal (cdr (assq 'commit-all fields)) "yes"))
4136 (sign-off-field (assq 'sign-off fields))
4137 (sign-off (if sign-off-field
4138 (equal (cdr sign-off-field) "yes")
4139 magit-commit-signoff))
4140 (tag-rev (cdr (assq 'tag-rev fields)))
4141 (tag-name (cdr (assq 'tag-name fields)))
41474142 (author (cdr (assq 'author fields)))
41484143 (tag-options (cdr (assq 'tag-options fields))))
41494144 (if (or (not (or allow-empty commit-all amend tag-name (magit-anything-staged-p)))
41544149 (magit-log-edit-set-fields nil)
41554150 (magit-log-edit-cleanup)
41564151 (if (= (buffer-size) 0)
4157 (insert "(Empty description)\n"))
4152 (insert "(Empty description)\n"))
41584153 (let ((commit-buf (current-buffer)))
41594154 (with-current-buffer (magit-find-status-buffer default-directory)
4160 (cond (tag-name
4155 (cond (tag-name
41614156 (apply #'magit-run-git-with-input commit-buf
41624157 "tag" (append tag-options (list tag-name "-a" "-F" "-" tag-rev))))
4163 (t
4164 (apply #'magit-run-async-with-input commit-buf
4165 magit-git-executable
4166 (append magit-git-standard-options
4158 (t
4159 (apply #'magit-run-async-with-input commit-buf
4160 magit-git-executable
4161 (append magit-git-standard-options
41674162 '("commit")
41684163 magit-custom-options
41694164 '("-F" "-")
4170 (if (and commit-all (not allow-empty)) '("--all") '())
4171 (if amend '("--amend") '())
4172 (if allow-empty '("--allow-empty"))
4173 (if sign-off '("--signoff") '())))))))
4165 (if (and commit-all (not allow-empty)) '("--all") '())
4166 (if amend '("--amend") '())
4167 (if allow-empty '("--allow-empty"))
4168 (if sign-off '("--signoff") '())))))))
41744169 (erase-buffer)
41754170 (bury-buffer)
41764171 (when (file-exists-p ".git/MERGE_MSG")
41844179 "Abort edits and erase commit message being composed."
41854180 (interactive)
41864181 (when (or (not magit-log-edit-confirm-cancellation)
4187 (yes-or-no-p
4188 "Really cancel editing the log (any changes will be lost)?"))
4182 (yes-or-no-p
4183 "Really cancel editing the log (any changes will be lost)?"))
41894184 (erase-buffer)
41904185 (bury-buffer)
41914186 (when magit-pre-log-edit-window-configuration
42234218
42244219 (defun magit-pop-to-log-edit (operation)
42254220 (let ((dir default-directory)
4226 (buf (get-buffer-create magit-log-edit-buffer-name)))
4221 (buf (get-buffer-create magit-log-edit-buffer-name)))
42274222 (setq magit-pre-log-edit-window-configuration
4228 (current-window-configuration))
4223 (current-window-configuration))
42294224 (pop-to-buffer buf)
42304225 (when (file-exists-p ".git/MERGE_MSG")
42314226 (insert-file-contents ".git/MERGE_MSG"))
42734268 (defun magit-add-log ()
42744269 (interactive)
42754270 (cond ((magit-rebase-info)
4276 (if (y-or-n-p "Rebase in progress. Continue it? ")
4277 (magit-run-git-async "rebase" "--continue")))
4278 (t
4279 (let ((section (magit-current-section)))
4280 (let ((fun (if (eq (magit-section-type section) 'hunk)
4281 (save-window-excursion
4282 (save-excursion
4283 (magit-visit-item)
4284 (add-log-current-defun)))
4285 nil))
4286 (file (magit-diff-item-file
4287 (cond ((eq (magit-section-type section) 'hunk)
4288 (magit-hunk-item-diff section))
4289 ((eq (magit-section-type section) 'diff)
4290 section)
4291 (t
4292 (error "No change at point"))))))
4293 (magit-log-edit nil)
4294 (goto-char (point-min))
4295 (cond ((not (search-forward-regexp
4296 (format "^\\* %s" (regexp-quote file)) nil t))
4297 ;; No entry for file, create it.
4298 (goto-char (point-max))
4299 (insert (format "\n* %s" file))
4300 (if fun
4301 (insert (format " (%s)" fun)))
4302 (insert ": "))
4303 (fun
4304 ;; found entry for file, look for fun
4305 (let ((limit (or (save-excursion
4306 (and (search-forward-regexp "^\\* "
4307 nil t)
4308 (match-beginning 0)))
4309 (point-max))))
4310 (cond ((search-forward-regexp (format "(.*\\<%s\\>.*):"
4311 (regexp-quote fun))
4312 limit t)
4313 ;; found it, goto end of current entry
4314 (if (search-forward-regexp "^(" limit t)
4315 (backward-char 2)
4316 (goto-char limit)))
4317 (t
4318 ;; not found, insert new entry
4319 (goto-char limit)
4320 (if (bolp)
4321 (open-line 1)
4322 (newline))
4323 (insert (format "(%s): " fun))))))))))))
4271 (if (y-or-n-p "Rebase in progress. Continue it? ")
4272 (magit-run-git-async "rebase" "--continue")))
4273 (t
4274 (let ((section (magit-current-section)))
4275 (let ((fun (if (eq (magit-section-type section) 'hunk)
4276 (save-window-excursion
4277 (save-excursion
4278 (magit-visit-item)
4279 (add-log-current-defun)))
4280 nil))
4281 (file (magit-diff-item-file
4282 (cond ((eq (magit-section-type section) 'hunk)
4283 (magit-hunk-item-diff section))
4284 ((eq (magit-section-type section) 'diff)
4285 section)
4286 (t
4287 (error "No change at point"))))))
4288 (magit-log-edit nil)
4289 (goto-char (point-min))
4290 (cond ((not (search-forward-regexp
4291 (format "^\\* %s" (regexp-quote file)) nil t))
4292 ;; No entry for file, create it.
4293 (goto-char (point-max))
4294 (insert (format "\n* %s" file))
4295 (if fun
4296 (insert (format " (%s)" fun)))
4297 (insert ": "))
4298 (fun
4299 ;; found entry for file, look for fun
4300 (let ((limit (or (save-excursion
4301 (and (search-forward-regexp "^\\* "
4302 nil t)
4303 (match-beginning 0)))
4304 (point-max))))
4305 (cond ((search-forward-regexp (format "(.*\\<%s\\>.*):"
4306 (regexp-quote fun))
4307 limit t)
4308 ;; found it, goto end of current entry
4309 (if (search-forward-regexp "^(" limit t)
4310 (backward-char 2)
4311 (goto-char limit)))
4312 (t
4313 ;; not found, insert new entry
4314 (goto-char limit)
4315 (if (bolp)
4316 (open-line 1)
4317 (newline))
4318 (insert (format "(%s): " fun))))))))))))
43244319
43254320 ;;; Tags
43264321
43504345 (defun magit-wash-stash ()
43514346 (if (search-forward-regexp "stash@{\\(.*?\\)}" (line-end-position) t)
43524347 (let ((stash (match-string-no-properties 0))
4353 (name (match-string-no-properties 1)))
4354 (delete-region (match-beginning 0) (match-end 0))
4355 (goto-char (match-beginning 0))
4356 (fixup-whitespace)
4357 (goto-char (line-beginning-position))
4358 (insert name)
4359 (goto-char (line-beginning-position))
4360 (magit-with-section stash 'stash
4361 (magit-set-section-info stash)
4362 (forward-line)))
4363 (forward-line))
4348 (name (match-string-no-properties 1)))
4349 (delete-region (match-beginning 0) (match-end 0))
4350 (goto-char (match-beginning 0))
4351 (fixup-whitespace)
4352 (goto-char (line-beginning-position))
4353 (insert name)
4354 (goto-char (line-beginning-position))
4355 (magit-with-section stash 'stash
4356 (magit-set-section-info stash)
4357 (forward-line)))
4358 (forward-line))
43644359 t)
43654360
43664361 (defun magit-wash-stashes ()
43694364
43704365 (magit-define-inserter stashes ()
43714366 (magit-git-section 'stashes
4372 "Stashes:" 'magit-wash-stashes
4373 "stash" "list"))
4367 "Stashes:" 'magit-wash-stashes
4368 "stash" "list"))
43744369
43754370 (magit-define-command stash (description)
43764371 "Create new stash of working tree and staging area named DESCRIPTION.
43864381 (interactive)
43874382 (magit-with-refresh
43884383 (magit-run-git "stash" "save"
4389 (format-time-string "Snapshot taken at %Y-%m-%d %H:%M:%S"
4390 (current-time)))
4384 (format-time-string "Snapshot taken at %Y-%m-%d %H:%M:%S"
4385 (current-time)))
43914386 (magit-run-git "stash" "apply" "stash@{0}")))
43924387
43934388 (defvar magit-currently-shown-stash nil)
43944389
43954390 (define-derived-mode magit-stash-mode magit-mode
4396 "Mode for looking at a git stash.
4391 "Mode for looking at a git stash.
43974392
43984393 \\{magit-stash-mode-map}"
43994394 :group 'magit)
44054400 (when (magit-section-p stash)
44064401 (setq stash (magit-section-info stash)))
44074402 (let ((dir default-directory)
4408 (buf (get-buffer-create magit-stash-buffer-name))
4403 (buf (get-buffer-create magit-stash-buffer-name))
44094404 (stash-id (magit-git-string "rev-list" "-1" stash)))
44104405 (cond ((and (equal magit-currently-shown-stash stash-id)
44114406 (with-current-buffer buf
44424437
44434438 (defun magit-apply-commit (commit &optional docommit noerase revert)
44444439 (let* ((parent-id (magit-choose-parent-id commit "cherry-pick"))
4445 (success (magit-run* `(,magit-git-executable
4446 ,@magit-git-standard-options
4447 ,(if revert "revert" "cherry-pick")
4448 ,@(if parent-id
4449 (list "-m" (number-to-string parent-id)))
4450 ,@(if (not docommit) (list "--no-commit"))
4451 ,commit)
4452 nil noerase)))
4440 (success (magit-run* `(,magit-git-executable
4441 ,@magit-git-standard-options
4442 ,(if revert "revert" "cherry-pick")
4443 ,@(if parent-id
4444 (list "-m" (number-to-string parent-id)))
4445 ,@(if (not docommit) (list "--no-commit"))
4446 ,commit)
4447 nil noerase)))
44534448 (when (and (not docommit) success)
44544449 (cond (revert
4455 (magit-log-edit-append
4456 (magit-format-commit commit "Reverting \"%s\"")))
4457 (t
4458 (magit-log-edit-append
4459 (magit-format-commit commit "%s%n%n%b"))
4460 (magit-log-edit-set-field
4461 'author
4462 (magit-format-commit commit "%an <%ae>, %ai")))))
4450 (magit-log-edit-append
4451 (magit-format-commit commit "Reverting \"%s\"")))
4452 (t
4453 (magit-log-edit-append
4454 (magit-format-commit commit "%s%n%n%b"))
4455 (magit-log-edit-set-field
4456 'author
4457 (magit-format-commit commit "%an <%ae>, %ai")))))
44634458 success))
44644459
44654460 (defun magit-apply-item ()
45264521 (interactive "P")
45274522 (make-local-variable 'magit-log-cutoff-length)
45284523 (cond
4529 ((numberp arg)
4530 (setq magit-log-cutoff-length (+ magit-log-cutoff-length arg)))
4531 (arg
4532 (setq magit-log-cutoff-length magit-log-infinite-length))
4533 (t (setq magit-log-cutoff-length (* magit-log-cutoff-length 2))))
4524 ((numberp arg)
4525 (setq magit-log-cutoff-length (+ magit-log-cutoff-length arg)))
4526 (arg
4527 (setq magit-log-cutoff-length magit-log-infinite-length))
4528 (t (setq magit-log-cutoff-length (* magit-log-cutoff-length 2))))
45344529 (let ((old-point (point)))
45354530 (magit-refresh)
45364531 (goto-char old-point)))
45424537 (setq magit-current-range range)
45434538 (magit-create-log-buffer-sections
45444539 (apply #'magit-git-section nil
4545 (magit-rev-range-describe range "Commits")
4546 'magit-wash-log
4547 `("log"
4548 ,(format "--max-count=%s" magit-log-cutoff-length)
4549 ,style
4550 ,@(if magit-have-decorate (list "--decorate=full"))
4551 ,@(if magit-have-graph (list "--graph"))
4552 ,@(if magit-have-abbrev (list "--no-abbrev-commit"))
4553 ,@args
4554 "--"))))
4540 (magit-rev-range-describe range "Commits")
4541 'magit-wash-log
4542 `("log"
4543 ,(format "--max-count=%s" magit-log-cutoff-length)
4544 ,style
4545 ,@(if magit-have-decorate (list "--decorate=full"))
4546 ,@(if magit-have-graph (list "--graph"))
4547 ,@(if magit-have-abbrev (list "--no-abbrev-commit"))
4548 ,@args
4549 "--"))))
45554550
45564551 (define-derived-mode magit-log-mode magit-mode "Magit"
4557 "Mode for looking at git log.
4552 "Mode for looking at git log.
45584553
45594554 \\{magit-log-mode-map}"
45604555 :group 'magit)
45724567 (let* ((log-range (if ask-for-range
45734568 (magit-read-rev-range "Log" "HEAD")
45744569 "HEAD"))
4575 (topdir (magit-get-top-dir default-directory))
4576 (args (nconc (list (magit-rev-range-to-git log-range))
4570 (topdir (magit-get-top-dir default-directory))
4571 (args (nconc (list (magit-rev-range-to-git log-range))
45774572 magit-custom-options
45784573 extra-args)))
45794574 (magit-buffer-switch magit-log-buffer-name)
45804575 (magit-mode-init topdir 'magit-log-mode #'magit-refresh-log-buffer log-range
4581 "--pretty=oneline" args)))
4576 "--pretty=oneline" args)))
45824577
45834578 (define-obsolete-function-alias 'magit-display-log 'magit-log)
45844579
45894584 (magit-define-command log-long (&optional ranged)
45904585 (interactive)
45914586 (let* ((range (if ranged
4592 (magit-read-rev-range "Long log" "HEAD")
4593 "HEAD"))
4594 (topdir (magit-get-top-dir default-directory))
4595 (args (append (list (magit-rev-range-to-git range))
4596 magit-custom-options)))
4587 (magit-read-rev-range "Long log" "HEAD")
4588 "HEAD"))
4589 (topdir (magit-get-top-dir default-directory))
4590 (args (append (list (magit-rev-range-to-git range))
4591 magit-custom-options)))
45974592 (magit-buffer-switch magit-log-buffer-name)
45984593 (magit-mode-init topdir 'magit-log-mode #'magit-refresh-log-buffer range
4599 "--stat" args)))
4594 "--stat" args)))
46004595
46014596 ;;; Reflog
46024597
46174612 args)))))
46184613
46194614 (define-derived-mode magit-reflog-mode magit-log-mode "Magit"
4620 "Mode for looking at git reflog.
4615 "Mode for looking at git reflog.
46214616
46224617 \\{magit-reflog-mode-map}"
46234618 :group 'magit)
47124707 "diff" (magit-diff-U-arg) args))))
47134708
47144709 (define-derived-mode magit-diff-mode magit-mode "Magit"
4715 "Mode for looking at a git diff.
4710 "Mode for looking at a git diff.
47164711
47174712 \\{magit-diff-mode-map}"
47184713 :group 'magit)
47344729 (defun magit-diff-with-mark ()
47354730 (interactive)
47364731 (magit-diff (cons (magit-marked-commit)
4737 (magit-commit-at-point))))
4732 (magit-commit-at-point))))
47384733
47394734 ;;; Wazzup
47404735
47514746 (defun magit-wazzup-toggle-ignore (branch edit)
47524747 (let ((ignore-file ".git/info/wazzup-exclude"))
47534748 (if edit
4754 (setq branch (read-string "Branch to ignore for wazzup: " branch)))
4749 (setq branch (read-string "Branch to ignore for wazzup: " branch)))
47554750 (let ((ignored (magit-file-lines ignore-file)))
47564751 (cond ((member branch ignored)
4757 (when (or (not edit)
4758 (y-or-n-p "Branch %s is already ignored. Unignore? "))
4759 (setq ignored (delete branch ignored))))
4760 (t
4761 (setq ignored (append ignored (list branch)))))
4752 (when (or (not edit)
4753 (y-or-n-p "Branch %s is already ignored. Unignore? "))
4754 (setq ignored (delete branch ignored))))
4755 (t
4756 (setq ignored (append ignored (list branch)))))
47624757 (magit-write-file-lines ignore-file ignored)
47634758 (magit-need-refresh))))
47644759
47694764 (unless head (setq head "HEAD"))
47704765 (magit-create-buffer-sections
47714766 (magit-with-section 'wazzupbuf nil
4772 (insert (format "Wazzup, %s\n\n" branch-desc))
4773 (let* ((excluded (magit-file-lines ".git/info/wazzup-exclude"))
4774 (all-branches (magit-list-interesting-refs))
4775 (branches (if all all-branches
4776 (delq nil (mapcar
4777 (lambda (b)
4778 (and (not
4779 (member (cdr b) excluded))
4780 b))
4781 all-branches))))
4782 (reported (make-hash-table :test #'equal)))
4783 (dolist (branch branches)
4784 (let* ((name (car branch))
4785 (ref (cdr branch))
4786 (hash (magit-rev-parse ref))
4787 (reported-branch (gethash hash reported)))
4788 (unless (or (and reported-branch
4789 (string= (file-name-nondirectory ref)
4790 reported-branch))
4791 (not (magit-git-string "merge-base" head ref)))
4792 (puthash hash (file-name-nondirectory ref) reported)
4793 (let* ((n (length (magit-git-lines "log" "--pretty=oneline"
4794 (concat head ".." ref))))
4795 (section
4796 (let ((magit-section-hidden-default t))
4797 (magit-git-section
4798 (cons ref 'wazzup)
4799 (format "%s unmerged commits in %s%s"
4800 n name
4801 (if (member ref excluded)
4802 " (normally ignored)"
4803 ""))
4804 'magit-wash-log
4805 "log"
4806 (format "--max-count=%s" magit-log-cutoff-length)
4807 "--graph"
4808 "--pretty=oneline"
4809 (format "%s..%s" head ref)
4810 "--"))))
4811 (magit-set-section-info ref section))))))))))
4767 (insert (format "Wazzup, %s\n\n" branch-desc))
4768 (let* ((excluded (magit-file-lines ".git/info/wazzup-exclude"))
4769 (all-branches (magit-list-interesting-refs))
4770 (branches (if all all-branches
4771 (delq nil (mapcar
4772 (lambda (b)
4773 (and (not
4774 (member (cdr b) excluded))
4775 b))
4776 all-branches))))
4777 (reported (make-hash-table :test #'equal)))
4778 (dolist (branch branches)
4779 (let* ((name (car branch))
4780 (ref (cdr branch))
4781 (hash (magit-rev-parse ref))
4782 (reported-branch (gethash hash reported)))
4783 (unless (or (and reported-branch
4784 (string= (file-name-nondirectory ref)
4785 reported-branch))
4786 (not (magit-git-string "merge-base" head ref)))
4787 (puthash hash (file-name-nondirectory ref) reported)
4788 (let* ((n (length (magit-git-lines "log" "--pretty=oneline"
4789 (concat head ".." ref))))
4790 (section
4791 (let ((magit-section-hidden-default t))
4792 (magit-git-section
4793 (cons ref 'wazzup)
4794 (format "%s unmerged commits in %s%s"
4795 n name
4796 (if (member ref excluded)
4797 " (normally ignored)"
4798 ""))
4799 'magit-wash-log
4800 "log"
4801 (format "--max-count=%s" magit-log-cutoff-length)
4802 "--graph"
4803 "--pretty=oneline"
4804 (format "%s..%s" head ref)
4805 "--"))))
4806 (magit-set-section-info ref section))))))))))
48124807
48134808 (define-derived-mode magit-wazzup-mode magit-mode
4814 "Mode for looking at commits that could be merged from other branches.
4809 "Mode for looking at commits that could be merged from other branches.
48154810
48164811 \\{magit-wazzup-mode-map}"
48174812 :group 'magit)
48194814 (defun magit-wazzup (&optional all)
48204815 (interactive "P")
48214816 (let ((topdir (magit-get-top-dir default-directory))
4822 (current-branch (magit-get-current-branch)))
4817 (current-branch (magit-get-current-branch)))
48234818 (magit-buffer-switch "*magit-wazzup*")
48244819 (magit-mode-init topdir 'magit-wazzup-mode
4825 #'magit-refresh-wazzup-buffer
4826 current-branch all)))
4820 #'magit-refresh-wazzup-buffer
4821 current-branch all)))
48274822
48284823 ;;; Miscellaneous
48294824
48304825 (defun magit-ignore-file (file edit local)
48314826 (let ((ignore-file (if local ".git/info/exclude" ".gitignore")))
48324827 (if edit
4833 (setq file (read-string "File to ignore: " file)))
4828 (setq file (read-string "File to ignore: " file)))
48344829 (with-temp-buffer
48354830 (when (file-exists-p ignore-file)
48364831 (insert-file-contents ignore-file))
48374832 (goto-char (point-max))
48384833 (unless (bolp)
4839 (insert "\n"))
4834 (insert "\n"))
48404835 (insert "/" file "\n")
48414836 (write-region nil nil ignore-file))
48424837 (magit-need-refresh)))
48574852
48584853 (defun magit-discard-diff (diff stagedp)
48594854 (let ((kind (magit-diff-item-kind diff))
4860 (file (magit-diff-item-file diff)))
4855 (file (magit-diff-item-file diff)))
48614856 (cond ((eq kind 'deleted)
4862 (when (yes-or-no-p (format "Resurrect %s? " file))
4863 (magit-run-git "reset" "-q" "--" file)
4864 (magit-run-git "checkout" "--" file)))
4865 ((eq kind 'new)
4866 (if (yes-or-no-p (format "Delete %s? " file))
4867 (magit-run-git "rm" "-f" "--" file)))
4868 (t
4869 (if (yes-or-no-p (format "Discard changes to %s? " file))
4870 (if stagedp
4871 (magit-run-git "checkout" "HEAD" "--" file)
4872 (magit-run-git "checkout" "--" file)))))))
4857 (when (yes-or-no-p (format "Resurrect %s? " file))
4858 (magit-run-git "reset" "-q" "--" file)
4859 (magit-run-git "checkout" "--" file)))
4860 ((eq kind 'new)
4861 (if (yes-or-no-p (format "Delete %s? " file))
4862 (magit-run-git "rm" "-f" "--" file)))
4863 (t
4864 (if (yes-or-no-p (format "Discard changes to %s? " file))
4865 (if stagedp
4866 (magit-run-git "checkout" "HEAD" "--" file)
4867 (magit-run-git "checkout" "--" file)))))))
48734868
48744869 (defun magit-discard-item ()
48754870 (interactive)
48834878 (magit-refresh-buffer)))
48844879 ((untracked)
48854880 (if (yes-or-no-p "Delete all untracked files and directories? ")
4886 (magit-run-git "clean" "-df")))
4881 (magit-run-git "clean" "-df")))
48874882 ((unstaged diff hunk)
48884883 (when (yes-or-no-p (if (magit-use-region-p)
4889 "Discard changes in region? "
4890 "Discard hunk? "))
4884 "Discard changes in region? "
4885 "Discard hunk? "))
48914886 (magit-apply-hunk-item-reverse item)))
48924887 ((staged diff hunk)
48934888 (if (magit-file-uptodate-p (magit-diff-item-file
4894 (magit-hunk-item-diff item)))
4895 (when (yes-or-no-p (if (magit-use-region-p)
4896 "Discard changes in region? "
4897 "Discard hunk? "))
4898 (magit-apply-hunk-item-reverse item "--index"))
4889 (magit-hunk-item-diff item)))
4890 (when (yes-or-no-p (if (magit-use-region-p)
4891 "Discard changes in region? "
4892 "Discard hunk? "))
4893 (magit-apply-hunk-item-reverse item "--index"))
48994894 (error "Can't discard this hunk. Please unstage it first")))
49004895 ((unstaged diff)
49014896 (magit-discard-diff item nil))
49024897 ((staged diff)
49034898 (if (magit-file-uptodate-p (magit-diff-item-file item))
4904 (magit-discard-diff item t)
4899 (magit-discard-diff item t)
49054900 (error "Can't discard staged changes to this file. Please unstage it first")))
49064901 ((diff diff)
49074902 (save-excursion
49244919 new-entry put-new-entry-on-new-line)
49254920 "Add a change log entry for current change."
49264921 (interactive (list current-prefix-arg
4927 (prompt-for-change-log-name)))
4922 (prompt-for-change-log-name)))
49284923 (let ((marker
49294924 (save-window-excursion
49304925 (magit-visit-item)
49344929 (goto-char marker)
49354930 (if (>= (magit-max-args-internal 'add-change-log-entry) 5)
49364931 (add-change-log-entry whoami file-name other-window
4937 new-entry put-new-entry-on-new-line)
4932 new-entry put-new-entry-on-new-line)
49384933 (add-change-log-entry whoami file-name other-window new-entry)
49394934 (if put-new-entry-on-new-line
49404935 (display-warning 'magit (format "Emacs %s does not support `put-new-entry-on-new-line' option to `add-change-log-entry'" emacs-version))))))))
49424937 (defun magit-add-change-log-entry-other-window (&optional whoami file-name)
49434938 "Add a change log entry for current change in other window."
49444939 (interactive (if current-prefix-arg
4945 (list current-prefix-arg
4946 (prompt-for-change-log-name))))
4940 (list current-prefix-arg
4941 (prompt-for-change-log-name))))
49474942 (magit-add-change-log-entry whoami file-name t))
49484943
49494944 (defun magit-visit-item (&optional other-window)
49644959 file)))
49654960 ((hunk)
49664961 (let ((file (magit-diff-item-file (magit-hunk-item-diff item)))
4967 (line (magit-hunk-item-target-line item)))
4962 (line (magit-hunk-item-target-line item)))
49684963 (if (not (file-exists-p file))
49694964 (error "Can't visit deleted file: %s" file))
49704965 (funcall
50095004 (magit-section-action (item info "mark")
50105005 ((commit)
50115006 (magit-set-marked-commit (if (eq magit-marked-commit info)
5012 nil
5013 info))))))
5007 nil
5008 info))))))
50145009
50155010 (defun magit-describe-item ()
50165011 (interactive)
50175012 (let ((section (magit-current-section)))
50185013 (message "Section: %s %s-%s %S %S %S"
5019 (magit-section-type section)
5020 (magit-section-beginning section)
5021 (magit-section-end section)
5022 (magit-section-title section)
5023 (magit-section-info section)
5024 (magit-section-context-type section))))
5014 (magit-section-type section)
5015 (magit-section-beginning section)
5016 (magit-section-end section)
5017 (magit-section-title section)
5018 (magit-section-info section)
5019 (magit-section-context-type section))))
50255020
50265021 (defun magit-copy-item-as-kill ()
50275022 "Copy sha1 of commit at point into kill ring."
50375032 "Test whether server is running (works with < 23 as well).
50385033
50395034 Return values:
5040 nil the server is definitely not running.
5041 t the server seems to be running.
5035 nil the server is definitely not running.
5036 t the server seems to be running.
50425037 something else we cannot determine whether it's running without using
5043 commands which may have to wait for a long time."
5038 commands which may have to wait for a long time."
50445039 (require 'server)
50455040 (if (functionp 'server-running-p)
50465041 (server-running-p)
50475042 (condition-case nil
5048 (if (and (boundp 'server-use-tcp)
5043 (if (and (boundp 'server-use-tcp)
50495044 server-use-tcp)
5050 (with-temp-buffer
5051 (insert-file-contents-literally (expand-file-name server-name server-auth-dir))
5052 (or (and (looking-at "127\\.0\\.0\\.1:[0-9]+ \\([0-9]+\\)")
5053 (assq 'comm
5054 (process-attributes
5055 (string-to-number (match-string 1))))
5056 t)
5057 :other))
5058 (delete-process
5059 (make-network-process
5060 :name "server-client-test" :family 'local :server nil :noquery t
5061 :service (expand-file-name server-name server-socket-dir)))
5062 t)
5045 (with-temp-buffer
5046 (insert-file-contents-literally (expand-file-name server-name server-auth-dir))
5047 (or (and (looking-at "127\\.0\\.0\\.1:[0-9]+ \\([0-9]+\\)")
5048 (assq 'comm
5049 (process-attributes
5050 (string-to-number (match-string 1))))
5051 t)
5052 :other))
5053 (delete-process
5054 (make-network-process
5055 :name "server-client-test" :family 'local :server nil :noquery t
5056 :service (expand-file-name server-name server-socket-dir)))
5057 t)
50635058 (file-error nil))))
50645059
50655060 (defun magit-interactive-rebase ()
50685063 (unless (magit-server-running-p)
50695064 (server-start))
50705065 (let* ((section (get-text-property (point) 'magit-section))
5071 (commit (and (member 'commit (magit-section-context-type section))
5072 (magit-section-info section)))
5073 (old-editor (getenv "GIT_EDITOR")))
5066 (commit (and (member 'commit (magit-section-context-type section))
5067 (magit-section-info section)))
5068 (old-editor (getenv "GIT_EDITOR")))
50745069 (setenv "GIT_EDITOR" (locate-file "emacsclient" exec-path))
50755070 (unwind-protect
5076 (magit-run-git-async "rebase" "-i"
5077 (or (and commit (concat commit "^"))
5078 (magit-read-rev "Interactively rebase to" (magit-guess-branch))))
5071 (magit-run-git-async "rebase" "-i"
5072 (or (and commit (concat commit "^"))
5073 (magit-read-rev "Interactively rebase to" (magit-guess-branch))))
50795074 (if old-editor
5080 (setenv "GIT_EDITOR" old-editor)))))
5075 (setenv "GIT_EDITOR" old-editor)))))
50815076
50825077 (define-derived-mode magit-show-branches-mode magit-mode
50835078 "Magit Branches")
51095104 (interactive "P")
51105105 (let* ((branch-section (magit-current-section))
51115106 (args (list "branch"
5112 (if force "-D" "-d")
5113 (when (magit--is-branch-section-remote branch-section) "-r")
5114 (magit-remove-remote (magit--branch-name-from-section branch-section)))))
5107 (if force "-D" "-d")
5108 (when (magit--is-branch-section-remote branch-section) "-r")
5109 (magit-remove-remote (magit--branch-name-from-section branch-section)))))
51155110 (if (and (magit--is-branch-section-remote branch-section)
51165111 (yes-or-no-p "Remove branch in remote repository as well? "))
51175112 (magit-remove-branch-in-remote-repo (magit--branch-name-from-section branch-section))
5118 (apply 'magit-run-git (remq nil args)))))
5113 (apply 'magit-run-git (remq nil args)))))
51195114
51205115 (defun magit--remotes ()
51215116 "Return a list of names for known remotes."
51955190 (cons 'sha1 (match-string 3 branch-line))
51965191 (cons 'msg (match-string 5 branch-line)))
51975192 res))))
5198
5199
5200
52015193
52025194 (defun magit-show-branches ()
52035195 "Show all of the current branches."
52355227 'face 'magit-log-head-label-remote)
52365228 "]")
52375229 "")))
5238 (insert "\n")))))
5230 (insert "\n")))))
52395231 (magit-show-branches-mode)
52405232 (goto-char (point-min))
52415233 (if buffer-existed
52845276 (defun magit-interactive-resolve (file)
52855277 (require 'ediff)
52865278 (let ((merge-status (magit-git-string "ls-files" "-u" "--" file))
5287 (base-buffer (generate-new-buffer (concat file ".base")))
5288 (our-buffer (generate-new-buffer (concat file ".current")))
5289 (their-buffer (generate-new-buffer (concat file ".merged")))
5290 (windows (current-window-configuration)))
5279 (base-buffer (generate-new-buffer (concat file ".base")))
5280 (our-buffer (generate-new-buffer (concat file ".current")))
5281 (their-buffer (generate-new-buffer (concat file ".merged")))
5282 (windows (current-window-configuration)))
52915283 (if (null merge-status)
5292 (error "Cannot resolve %s" file))
5284 (error "Cannot resolve %s" file))
52935285 (with-current-buffer base-buffer
52945286 (if (string-match "^[0-9]+ [0-9a-f]+ 1" merge-status)
52955287 (insert (magit-git-output `("cat-file" "blob" ,(concat ":1:" file))))))
53115303 (setq magit-ediff-windows windows)
53125304 (make-local-variable 'ediff-quit-hook)
53135305 (add-hook 'ediff-quit-hook
5314 (lambda ()
5315 (let ((buffer-A ediff-buffer-A)
5316 (buffer-B ediff-buffer-B)
5317 (buffer-C ediff-buffer-C)
5318 (buffer-Ancestor ediff-ancestor-buffer)
5319 (file magit-ediff-file)
5320 (file-buffer)
5321 (windows magit-ediff-windows))
5322 (ediff-cleanup-mess)
5323 (find-file file)
5324 (setq file-buffer (current-buffer))
5325 (erase-buffer)
5326 (insert-buffer-substring buffer-C)
5327 (kill-buffer buffer-A)
5328 (kill-buffer buffer-B)
5329 (kill-buffer buffer-C)
5330 (when (bufferp buffer-Ancestor) (kill-buffer buffer-Ancestor))
5331 (set-window-configuration windows)
5332 (magit-save-some-buffers
5333 "Conflict resolution finished; you may save the buffer"
5334 (lambda () (eq (current-buffer) file-buffer)))))))))
5306 (lambda ()
5307 (let ((buffer-A ediff-buffer-A)
5308 (buffer-B ediff-buffer-B)
5309 (buffer-C ediff-buffer-C)
5310 (buffer-Ancestor ediff-ancestor-buffer)
5311 (file magit-ediff-file)
5312 (file-buffer)
5313 (windows magit-ediff-windows))
5314 (ediff-cleanup-mess)
5315 (find-file file)
5316 (setq file-buffer (current-buffer))
5317 (erase-buffer)
5318 (insert-buffer-substring buffer-C)
5319 (kill-buffer buffer-A)
5320 (kill-buffer buffer-B)
5321 (kill-buffer buffer-C)
5322 (when (bufferp buffer-Ancestor) (kill-buffer buffer-Ancestor))
5323 (set-window-configuration windows)
5324 (magit-save-some-buffers
5325 "Conflict resolution finished; you may save the buffer"
5326 (lambda () (eq (current-buffer) file-buffer)))))))))
53355327
53365328 (defun magit-interactive-resolve-item ()
53375329 (interactive)