-
Notifications
You must be signed in to change notification settings - Fork 6
feat(file): add blob buffer support #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,6 +21,7 @@ | |||||||||||||||||||||||||||||||||||||||||
| (require 'majutsu-config) | ||||||||||||||||||||||||||||||||||||||||||
| (require 'majutsu-selection) | ||||||||||||||||||||||||||||||||||||||||||
| (require 'majutsu-section) | ||||||||||||||||||||||||||||||||||||||||||
| (require 'majutsu-file) | ||||||||||||||||||||||||||||||||||||||||||
| (require 'magit-diff) ; for faces/font-lock keywords | ||||||||||||||||||||||||||||||||||||||||||
| (require 'diff-mode) | ||||||||||||||||||||||||||||||||||||||||||
| (require 'smerge-mode) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -88,8 +89,6 @@ otherwise fall back to the current buffer's `tab-width'." | |||||||||||||||||||||||||||||||||||||||||
| "Face for the (binary) label in diffstat entries." | ||||||||||||||||||||||||||||||||||||||||||
| :group 'majutsu) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;;; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defvar majutsu-diff--tab-width-cache nil | ||||||||||||||||||||||||||||||||||||||||||
| "Alist mapping file names to cached tab widths.") | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -303,7 +302,7 @@ The list is in the same order as the diff headers appear." | |||||||||||||||||||||||||||||||||||||||||
| (goto-char (point-min)) | ||||||||||||||||||||||||||||||||||||||||||
| (let (files) | ||||||||||||||||||||||||||||||||||||||||||
| (while (re-search-forward "^diff --git a/\\(.*\\) b/\\(.*\\)$" nil t) | ||||||||||||||||||||||||||||||||||||||||||
| (push (match-string 2) files)) | ||||||||||||||||||||||||||||||||||||||||||
| (push (match-string-no-properties 2) files)) | ||||||||||||||||||||||||||||||||||||||||||
| (nreverse files)))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-jump-to-diffstat-or-diff (&optional expand) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -418,7 +417,7 @@ first \"diff --git\" header." | |||||||||||||||||||||||||||||||||||||||||
| (magit-insert-heading | ||||||||||||||||||||||||||||||||||||||||||
| (propertize heading 'font-lock-face 'magit-diff-file-heading)) | ||||||||||||||||||||||||||||||||||||||||||
| (while (looking-at majutsu-diff-statline-re) | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((file (match-string 1)) | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((file (match-string-no-properties 1)) | ||||||||||||||||||||||||||||||||||||||||||
| (sep (match-string 2)) | ||||||||||||||||||||||||||||||||||||||||||
| (cnt (match-string 3)) | ||||||||||||||||||||||||||||||||||||||||||
| (add (match-string 4)) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -472,8 +471,8 @@ Assumes point is at the start of the diff output." | |||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff-wash-file () | ||||||||||||||||||||||||||||||||||||||||||
| "Parse a single file section at point and wrap it in Magit sections." | ||||||||||||||||||||||||||||||||||||||||||
| (when (looking-at "^diff --git a/\\(.*\\) b/\\(.*\\)$") | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((file-a (match-string 1)) | ||||||||||||||||||||||||||||||||||||||||||
| (file-b (match-string 2)) | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((file-a (match-string-no-properties 1)) | ||||||||||||||||||||||||||||||||||||||||||
| (file-b (match-string-no-properties 2)) | ||||||||||||||||||||||||||||||||||||||||||
| (file (or file-b file-a)) | ||||||||||||||||||||||||||||||||||||||||||
| (headers nil) | ||||||||||||||||||||||||||||||||||||||||||
| (diff-header (buffer-substring-no-properties | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -698,31 +697,146 @@ works with the simplified jj diff we render here." | |||||||||||||||||||||||||||||||||||||||||
| (when-let* ((file (majutsu-file-at-point))) | ||||||||||||||||||||||||||||||||||||||||||
| (find-file (expand-file-name file default-directory)))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff--range-value (range prefix) | ||||||||||||||||||||||||||||||||||||||||||
| "Return the value in RANGE for argument starting with PREFIX." | ||||||||||||||||||||||||||||||||||||||||||
| (when range | ||||||||||||||||||||||||||||||||||||||||||
| (when-let* ((arg (seq-find (lambda (item) (string-prefix-p prefix item)) range))) | ||||||||||||||||||||||||||||||||||||||||||
| (substring arg (length prefix))))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff--on-removed-line-p () | ||||||||||||||||||||||||||||||||||||||||||
| "Return non-nil if point is on a removed diff line." | ||||||||||||||||||||||||||||||||||||||||||
| (eq (char-after (line-beginning-position)) ?-)) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff--default-revset () | ||||||||||||||||||||||||||||||||||||||||||
| "Return the revset implied by the current diff buffer." | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((range majutsu-buffer-diff-range) | ||||||||||||||||||||||||||||||||||||||||||
| (removed (majutsu-diff--on-removed-line-p)) | ||||||||||||||||||||||||||||||||||||||||||
| (from (majutsu-diff--range-value range "--from=")) | ||||||||||||||||||||||||||||||||||||||||||
| (to (majutsu-diff--range-value range "--to=")) | ||||||||||||||||||||||||||||||||||||||||||
| (revisions (majutsu-diff--range-value range "--revisions="))) | ||||||||||||||||||||||||||||||||||||||||||
| (cond | ||||||||||||||||||||||||||||||||||||||||||
| ((and range (equal (car range) "-r") (cadr range)) (cadr range)) | ||||||||||||||||||||||||||||||||||||||||||
| (revisions revisions) | ||||||||||||||||||||||||||||||||||||||||||
| (from (if (and removed from) from (or to from))) | ||||||||||||||||||||||||||||||||||||||||||
| (t "@")))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff--hunk-line (section goto-from) | ||||||||||||||||||||||||||||||||||||||||||
| "Return the line number in SECTION for GOTO-FROM side." | ||||||||||||||||||||||||||||||||||||||||||
| (with-slots (content from-range to-range) section | ||||||||||||||||||||||||||||||||||||||||||
| (let ((start (car (if goto-from from-range to-range)))) | ||||||||||||||||||||||||||||||||||||||||||
| (when start | ||||||||||||||||||||||||||||||||||||||||||
| (let ((line start) | ||||||||||||||||||||||||||||||||||||||||||
| (target (point))) | ||||||||||||||||||||||||||||||||||||||||||
| (save-excursion | ||||||||||||||||||||||||||||||||||||||||||
| (goto-char content) | ||||||||||||||||||||||||||||||||||||||||||
| (while (< (point) target) | ||||||||||||||||||||||||||||||||||||||||||
| (let ((ch (char-after (line-beginning-position)))) | ||||||||||||||||||||||||||||||||||||||||||
| (cond | ||||||||||||||||||||||||||||||||||||||||||
| ((eq ch ?+) (unless goto-from (setq line (1+ line)))) | ||||||||||||||||||||||||||||||||||||||||||
| ((eq ch ?-) (when goto-from (setq line (1+ line)))) | ||||||||||||||||||||||||||||||||||||||||||
| (t (setq line (1+ line))))) | ||||||||||||||||||||||||||||||||||||||||||
| (forward-line 1))) | ||||||||||||||||||||||||||||||||||||||||||
| line))))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff--hunk-column (section goto-from) | ||||||||||||||||||||||||||||||||||||||||||
| "Return the column for SECTION based on GOTO-FROM side." | ||||||||||||||||||||||||||||||||||||||||||
| (let ((bol (line-beginning-position))) | ||||||||||||||||||||||||||||||||||||||||||
| (if (or (< (point) (oref section content)) | ||||||||||||||||||||||||||||||||||||||||||
| (and (not goto-from) (eq (char-after bol) ?-))) | ||||||||||||||||||||||||||||||||||||||||||
| 0 | ||||||||||||||||||||||||||||||||||||||||||
| (let ((col (current-column))) | ||||||||||||||||||||||||||||||||||||||||||
| (if (memq (char-after bol) '(?+ ?-)) | ||||||||||||||||||||||||||||||||||||||||||
| (max 0 (1- col)) | ||||||||||||||||||||||||||||||||||||||||||
| col))))) | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+741
to
+750
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Column is off-by-one on context lines. In unified diff format, context lines are prefixed with a space character. The current code only adjusts for Suggested fix (let ((col (current-column)))
- (if (memq (char-after bol) '(?+ ?-))
+ (if (memq (char-after bol) '(?+ ?- ?\s))
(max 0 (1- col))
col)))))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff--goto-line-col (buffer line col) | ||||||||||||||||||||||||||||||||||||||||||
| "Move point in BUFFER to LINE and COL." | ||||||||||||||||||||||||||||||||||||||||||
| (with-current-buffer buffer | ||||||||||||||||||||||||||||||||||||||||||
| (widen) | ||||||||||||||||||||||||||||||||||||||||||
| (goto-char (point-min)) | ||||||||||||||||||||||||||||||||||||||||||
| (forward-line (max 0 (1- line))) | ||||||||||||||||||||||||||||||||||||||||||
| (move-to-column col))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff--visit-workspace-p () | ||||||||||||||||||||||||||||||||||||||||||
| "Return non-nil if the current diff should visit the workspace file. | ||||||||||||||||||||||||||||||||||||||||||
| This is true when diffing the working copy (@) on the new/right side." | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((range majutsu-buffer-diff-range) | ||||||||||||||||||||||||||||||||||||||||||
| (to (majutsu-diff--range-value range "--to=")) | ||||||||||||||||||||||||||||||||||||||||||
| (revisions (majutsu-diff--range-value range "--revisions="))) | ||||||||||||||||||||||||||||||||||||||||||
| (cond | ||||||||||||||||||||||||||||||||||||||||||
| ;; Explicit --to=@ means we're looking at working copy changes | ||||||||||||||||||||||||||||||||||||||||||
| ((equal to "@") t) | ||||||||||||||||||||||||||||||||||||||||||
| ;; No range specified defaults to -r @ (working copy) | ||||||||||||||||||||||||||||||||||||||||||
| ((null range) t) | ||||||||||||||||||||||||||||||||||||||||||
| ;; Single revision diff (-r @) shows working copy | ||||||||||||||||||||||||||||||||||||||||||
| ((and revisions (equal revisions "@")) t) | ||||||||||||||||||||||||||||||||||||||||||
| ;; Otherwise we're looking at committed changes | ||||||||||||||||||||||||||||||||||||||||||
| (t nil)))) | ||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;;;###autoload | ||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff-visit-file () | ||||||||||||||||||||||||||||||||||||||||||
| "Visit the file at point. | ||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff-visit-file (&optional force-workspace) | ||||||||||||||||||||||||||||||||||||||||||
| "From a diff, visit the appropriate version of the file at point. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| When point is on a hunk section, jump to the corresponding line in the | ||||||||||||||||||||||||||||||||||||||||||
| file." | ||||||||||||||||||||||||||||||||||||||||||
| (interactive) | ||||||||||||||||||||||||||||||||||||||||||
| (let ((section (magit-current-section))) | ||||||||||||||||||||||||||||||||||||||||||
| (cond | ||||||||||||||||||||||||||||||||||||||||||
| ((and section (magit-section-match 'jj-hunk section)) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-goto-diff-line)) | ||||||||||||||||||||||||||||||||||||||||||
| ((majutsu-file-at-point) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-visit-file)) | ||||||||||||||||||||||||||||||||||||||||||
| (t | ||||||||||||||||||||||||||||||||||||||||||
| (user-error "No file at point"))))) | ||||||||||||||||||||||||||||||||||||||||||
| If point is on an added or context line, visit the new/right side. | ||||||||||||||||||||||||||||||||||||||||||
| If point is on a removed line, visit the old/left side. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| For diffs of the working copy (@), this visits the actual file in | ||||||||||||||||||||||||||||||||||||||||||
| the workspace. For diffs of committed changes, this visits the | ||||||||||||||||||||||||||||||||||||||||||
| blob from the appropriate revision. | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| With prefix argument FORCE-WORKSPACE, always visit the workspace file | ||||||||||||||||||||||||||||||||||||||||||
| regardless of what the diff is about." | ||||||||||||||||||||||||||||||||||||||||||
| (interactive "P") | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((section (magit-current-section)) | ||||||||||||||||||||||||||||||||||||||||||
| (file (majutsu-file-at-point))) | ||||||||||||||||||||||||||||||||||||||||||
| (unless file | ||||||||||||||||||||||||||||||||||||||||||
| (user-error "No file at point")) | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((goto-from (and section (magit-section-match 'jj-hunk section) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff--on-removed-line-p))) | ||||||||||||||||||||||||||||||||||||||||||
| (goto-workspace (or force-workspace | ||||||||||||||||||||||||||||||||||||||||||
| (and (majutsu-diff--visit-workspace-p) | ||||||||||||||||||||||||||||||||||||||||||
| (not goto-from)))) | ||||||||||||||||||||||||||||||||||||||||||
| (line (and section (magit-section-match 'jj-hunk section) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff--hunk-line section goto-from))) | ||||||||||||||||||||||||||||||||||||||||||
| (col (and section (magit-section-match 'jj-hunk section) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff--hunk-column section goto-from)))) | ||||||||||||||||||||||||||||||||||||||||||
| (if goto-workspace | ||||||||||||||||||||||||||||||||||||||||||
| ;; Visit workspace file | ||||||||||||||||||||||||||||||||||||||||||
| (let ((full-path (expand-file-name file default-directory))) | ||||||||||||||||||||||||||||||||||||||||||
| (if (file-exists-p full-path) | ||||||||||||||||||||||||||||||||||||||||||
| (progn | ||||||||||||||||||||||||||||||||||||||||||
| (find-file full-path) | ||||||||||||||||||||||||||||||||||||||||||
| (when (and line col) | ||||||||||||||||||||||||||||||||||||||||||
| (goto-char (point-min)) | ||||||||||||||||||||||||||||||||||||||||||
| (forward-line (1- line)) | ||||||||||||||||||||||||||||||||||||||||||
| (move-to-column col))) | ||||||||||||||||||||||||||||||||||||||||||
| (user-error "File does not exist in workspace: %s" file))) | ||||||||||||||||||||||||||||||||||||||||||
| ;; Visit blob | ||||||||||||||||||||||||||||||||||||||||||
| (let* ((revset (majutsu-diff--default-revset)) | ||||||||||||||||||||||||||||||||||||||||||
| (buf (majutsu-find-file revset file))) | ||||||||||||||||||||||||||||||||||||||||||
| (when (and buf line col) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff--goto-line-col buf line col))))))) | ||||||||||||||||||||||||||||||||||||||||||
0WD0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;;; Section Keymaps | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defvar-keymap majutsu-diff-section-map | ||||||||||||||||||||||||||||||||||||||||||
| :doc "Keymap for diff sections." | ||||||||||||||||||||||||||||||||||||||||||
| "<remap> <majutsu-visit-thing>" #'majutsu-diff-visit-file) | ||||||||||||||||||||||||||||||||||||||||||
| "<remap> <majutsu-visit-thing>" #'majutsu-diff-visit-file | ||||||||||||||||||||||||||||||||||||||||||
| "C-j" #'majutsu-diff-visit-workspace-file | ||||||||||||||||||||||||||||||||||||||||||
| "C-<return>" #'majutsu-diff-visit-workspace-file) | ||||||||||||||||||||||||||||||||||||||||||
0WD0 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;;;###autoload | ||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff-visit-workspace-file () | ||||||||||||||||||||||||||||||||||||||||||
| "From a diff, visit the workspace version of the file at point. | ||||||||||||||||||||||||||||||||||||||||||
| Always visits the actual file in the working tree, regardless of | ||||||||||||||||||||||||||||||||||||||||||
| what the diff is about." | ||||||||||||||||||||||||||||||||||||||||||
| (interactive) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff-visit-file t)) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defvar-keymap majutsu-file-section-map | ||||||||||||||||||||||||||||||||||||||||||
| :doc "Keymap for `jj-file' sections." | ||||||||||||||||||||||||||||||||||||||||||
| :parent majutsu-diff-section-map) | ||||||||||||||||||||||||||||||||||||||||||
| :parent majutsu-diff-section-map | ||||||||||||||||||||||||||||||||||||||||||
| "v" #'majutsu-find-file-at-point) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defvar-keymap majutsu-hunk-section-map | ||||||||||||||||||||||||||||||||||||||||||
| :doc "Keymap for `jj-hunk' sections." | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -858,21 +972,6 @@ file." | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;;; Diff Commands | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff-clear-selections () | ||||||||||||||||||||||||||||||||||||||||||
| "Clear all diff selections." | ||||||||||||||||||||||||||||||||||||||||||
| (interactive) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-selection-clear 'from) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-selection-clear 'to) | ||||||||||||||||||||||||||||||||||||||||||
| (when (consp transient--suffixes) | ||||||||||||||||||||||||||||||||||||||||||
| (dolist (obj transient--suffixes) | ||||||||||||||||||||||||||||||||||||||||||
| (when (and (cl-typep obj 'majutsu-diff-range-option) | ||||||||||||||||||||||||||||||||||||||||||
| (memq (oref obj selection-key) '(revisions from to))) | ||||||||||||||||||||||||||||||||||||||||||
| (transient-infix-set obj nil)))) | ||||||||||||||||||||||||||||||||||||||||||
| (when transient--prefix | ||||||||||||||||||||||||||||||||||||||||||
| (transient--redisplay)) | ||||||||||||||||||||||||||||||||||||||||||
| (when (called-interactively-p 'interactive) | ||||||||||||||||||||||||||||||||||||||||||
| (message "Cleared diff selections"))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff-less-context (&optional count) | ||||||||||||||||||||||||||||||||||||||||||
| "Decrease the context for diff hunks by COUNT lines." | ||||||||||||||||||||||||||||||||||||||||||
| (interactive "p") | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -942,17 +1041,13 @@ With prefix STYLE, cycle between `all' and `t'." | |||||||||||||||||||||||||||||||||||||||||
| "Refresh the current diff buffer." | ||||||||||||||||||||||||||||||||||||||||||
| (interactive) | ||||||||||||||||||||||||||||||||||||||||||
| (when majutsu-buffer-diff-args | ||||||||||||||||||||||||||||||||||||||||||
| (let* (;; Avoid ANSI; let our painting run lazily. | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-jj-global-arguments | ||||||||||||||||||||||||||||||||||||||||||
| (cons "--color=never" | ||||||||||||||||||||||||||||||||||||||||||
| (seq-remove (lambda (arg) | ||||||||||||||||||||||||||||||||||||||||||
| (string-prefix-p "--color" arg)) | ||||||||||||||||||||||||||||||||||||||||||
| majutsu-jj-global-arguments))) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-process-apply-ansi-colors nil)) | ||||||||||||||||||||||||||||||||||||||||||
| (magit-insert-section (diffbuf) | ||||||||||||||||||||||||||||||||||||||||||
| (magit-run-section-hook 'majutsu-diff-sections-hook)) | ||||||||||||||||||||||||||||||||||||||||||
| (when (eq majutsu-diff-refine-hunk 'all) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff--update-hunk-refinement))))) | ||||||||||||||||||||||||||||||||||||||||||
| ;; Avoid ANSI; let our painting run lazily. | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu--with-no-color | ||||||||||||||||||||||||||||||||||||||||||
| (let ((majutsu-process-apply-ansi-colors nil)) | ||||||||||||||||||||||||||||||||||||||||||
| (magit-insert-section (diffbuf) | ||||||||||||||||||||||||||||||||||||||||||
| (magit-run-section-hook 'majutsu-diff-sections-hook)) | ||||||||||||||||||||||||||||||||||||||||||
| (when (eq majutsu-diff-refine-hunk 'all) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff--update-hunk-refinement)))))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;;;###autoload | ||||||||||||||||||||||||||||||||||||||||||
| (defun majutsu-diff-dwim (&optional args range filesets) | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -962,7 +1057,7 @@ With prefix STYLE, cycle between `all' and `t'." | |||||||||||||||||||||||||||||||||||||||||
| (`(commit . ,rev) rev) | ||||||||||||||||||||||||||||||||||||||||||
| (_ "@"))) | ||||||||||||||||||||||||||||||||||||||||||
| (range (or range | ||||||||||||||||||||||||||||||||||||||||||
| (list (concat "--revisions=" (majutsu--normalize-id-value rev)))))) | ||||||||||||||||||||||||||||||||||||||||||
| (list (concat "--revisions=" (substring-no-properties rev)))))) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff-setup-buffer args range filesets))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;;;###autoload | ||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -972,7 +1067,7 @@ With prefix STYLE, cycle between `all' and `t'." | |||||||||||||||||||||||||||||||||||||||||
| REVSET is passed to jj diff using `--revisions='." | ||||||||||||||||||||||||||||||||||||||||||
| (interactive (cons (majutsu-read-revset "Diff revset") | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff-arguments))) | ||||||||||||||||||||||||||||||||||||||||||
| (let ((range (list (concat "--revisions=" (majutsu--normalize-id-value revset))))) | ||||||||||||||||||||||||||||||||||||||||||
| (let ((range (list (concat "--revisions=" (substring-no-properties revset))))) | ||||||||||||||||||||||||||||||||||||||||||
| (majutsu-diff-setup-buffer args range filesets))) | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| ;; TODO: implement more DWIM cases | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
jj diff default behavior working copy parent revision💡 Result:
In Jujutsu (jj):
jj diff(no args) defaults tojj diff -r @, i.e. it shows the diff for the working-copy revision@compared to its parent revision@-. If@is a merge, jj effectively merges the parents and diffs that merge-result against@. [1][2]jj diff -r <REV>means “diff<REV>vs its parent<REV>-”. [1][2]jj diff --from A(with no--to) means “diff A →@”, because an omitted side defaults to the working-copy commit. Likewise,jj diff --to Bmeans “diff@→ B”. [1][2]jj diffreflects your current working directory state unless you pass--ignore-working-copy. [2]Sources: Jujutsu CLI reference /
jj diffdocs [1],jj-diff(1)man page [2].🌐 Web query:
jj removed lines diff revision mapping@-``💡 Result:
In Jujutsu (
jj) revsets,@means “the working-copy change”, and@-means the parent of the working copy (the change you’re based on). (jj-vcs.github.io)How to interpret “removed lines” in a
jj diffjj diff(by default) is effectively comparing@- → @(parent → working copy). (jj-vcs.github.io)--git), lines starting with-are lines that exist in thefromrevision (e.g.,@-) but not in thetorevision (e.g.,@). The hunk header@@ -old_start,old_len +new_start,new_len @@is the line-range mapping for old vs new.Useful commands:
(jj-vcs.github.io)
If you want the revision associated with removed lines
Once a line is deleted, it won’t appear in
annotateof@. Instead, annotate the file in@-(before the deletion):jj file annotate -r `@-` path/to/fileThis shows which change introduced each line in that file version. (docs.jj-vcs.dev)
Citations:
🏁 Script executed:
Repository: 0WD0/majutsu
Length of output: 38
🏁 Script executed:
Repository: 0WD0/majutsu
Length of output: 226
🏁 Script executed:
Repository: 0WD0/majutsu
Length of output: 71
🏁 Script executed:
Repository: 0WD0/majutsu
Length of output: 612
🏁 Script executed:
Repository: 0WD0/majutsu
Length of output: 1101
Add fallback to
@-for removed lines in default diffs.When
jj diffruns with no explicit range, it compares@-(parent) to@(working copy). Removed lines exist in@-but not in@. The current code falls through to(t "@"), which tries to open the removed line in the working copy where it doesn't exist.Suggested fix
(defun majutsu-diff--default-revset () "Return the revset implied by the current diff buffer." (let* ((range majutsu-buffer-diff-range) (removed (majutsu-diff--on-removed-line-p)) (from (majutsu-diff--range-value range "--from=")) (to (majutsu-diff--range-value range "--to=")) (revisions (majutsu-diff--range-value range "--revisions="))) (cond ((and range (equal (car range) "-r") (cadr range)) (cadr range)) (revisions revisions) (from (if (and removed from) from (or to from))) + ((and removed (null range)) "@-") (t "@"))))🤖 Prompt for AI Agents