Permalink
Browse files

Fix for persistent hunk ranges when adding sub-modules.

* (egg-get-hunk-range): Normalize hunk range no matter how many line
  numbers it contains
  • Loading branch information...
1 parent f5fc719 commit 8e243ff56a9e2e23b837c4af194e2ce6b68fc8d6 Max Mikhanosha committed May 4, 2012
Showing with 24 additions and 5 deletions.
  1. +24 −5 egg.el
View
@@ -2686,11 +2686,30 @@ the section.
(save-match-data
(split-string hunk-header "[ @,\+,-]+" t)))
(range
- (mapcar 'string-to-number range-as-strings)))
- (if (/= 6 (length range))
- range
- (append (subseq range 0 2)
- (subseq range 4))))))
+ (mapcar 'string-to-number range-as-strings))
+ (len (length range)))
+ ;; normalize hunk range, sorted in order of most frequent
+ (cond
+ ;; Normal hunk
+ ((= 4 len) range)
+ ;; 3 way diff when merging, never seen >6
+ ((= 6 len) (append (subseq range 0 2)
+ (subseq range 4 2)))
+ ;; Adding sub-modules
+ ((= 2 len) (append range range))
+ ;; Adding symbolic links
+ ((= 3 len) (append range (list (second range))))
+ ;; Never seen this 5 line numbers hunk, treat as 4
+ ((= 5 len) (subseq range 0 4))
+ ;; Never seen 1 line number hunk
+ ((= 1 len) (list (car range) (car range) (car range) (car range)))
+ ;; never seen hunk header with no line numbers
+ ((zerop len) (list 1 1 1 1))
+ ;; more then 6 numbers
+ (t (warn "Weird hunk header %S" hunk-header)
+ ;; treat as 6 line one
+ (append (subseq range 0 2)
+ (subseq range 4 2)))))))
(defun egg-ensure-hunk-ranges-cache ()
"Returns `egg-hunk-ranges-cache' re-creating it if its NIL."

0 comments on commit 8e243ff

Please sign in to comment.