Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
git
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security
Insights
Files
105c21d
Documentation
arm
compat
contrib
git-gui
lib
about.tcl
blame.tcl
branch.tcl
branch_checkout.tcl
branch_create.tcl
branch_delete.tcl
branch_rename.tcl
browser.tcl
checkout_op.tcl
choose_font.tcl
choose_repository.tcl
choose_rev.tcl
class.tcl
commit.tcl
console.tcl
database.tcl
date.tcl
diff.tcl
encoding.tcl
error.tcl
git-gui.ico
index.tcl
logo.tcl
merge.tcl
option.tcl
remote.tcl
remote_branch_delete.tcl
shortcut.tcl
status_bar.tcl
transport.tcl
win32.tcl
win32_shortcut.js
macosx
po
windows
.gitignore
GIT-VERSION-GEN
Makefile
git-gui.sh
gitk-git
gitweb
mozilla-sha1
perl
ppc
t
templates
xdiff
.gitignore
.mailmap
COPYING
GIT-VERSION-GEN
INSTALL
Makefile
README
RelNotes
alloc.c
archive-tar.c
archive-zip.c
archive.c
archive.h
attr.c
attr.h
base85.c
blob.c
blob.h
builtin-add.c
builtin-annotate.c
builtin-apply.c
builtin-archive.c
builtin-blame.c
builtin-branch.c
builtin-bundle.c
builtin-cat-file.c
builtin-check-attr.c
builtin-check-ref-format.c
builtin-checkout-index.c
builtin-clean.c
builtin-commit-tree.c
builtin-commit.c
builtin-config.c
builtin-count-objects.c
builtin-describe.c
builtin-diff-files.c
builtin-diff-index.c
builtin-diff-tree.c
builtin-diff.c
builtin-fast-export.c
builtin-fetch--tool.c
builtin-fetch-pack.c
builtin-fetch.c
builtin-fmt-merge-msg.c
builtin-for-each-ref.c
builtin-fsck.c
builtin-gc.c
builtin-grep.c
builtin-http-fetch.c
builtin-init-db.c
builtin-log.c
builtin-ls-files.c
builtin-ls-remote.c
builtin-ls-tree.c
builtin-mailinfo.c
builtin-mailsplit.c
builtin-merge-base.c
builtin-merge-file.c
builtin-merge-ours.c
builtin-mv.c
builtin-name-rev.c
builtin-pack-objects.c
builtin-pack-refs.c
builtin-prune-packed.c
builtin-prune.c
builtin-push.c
builtin-read-tree.c
builtin-reflog.c
builtin-rerere.c
builtin-reset.c
builtin-rev-list.c
builtin-rev-parse.c
builtin-revert.c
builtin-rm.c
builtin-send-pack.c
builtin-shortlog.c
builtin-show-branch.c
builtin-show-ref.c
builtin-stripspace.c
builtin-symbolic-ref.c
builtin-tag.c
builtin-tar-tree.c
builtin-unpack-objects.c
builtin-update-index.c
builtin-update-ref.c
builtin-upload-archive.c
builtin-verify-pack.c
builtin-verify-tag.c
builtin-write-tree.c
builtin.h
bundle.c
bundle.h
cache-tree.c
cache-tree.h
cache.h
check-builtins.sh
check-racy.c
color.c
color.h
combine-diff.c
command-list.txt
commit.c
commit.h
config.c
config.mak.in
configure.ac
connect.c
convert.c
copy.c
csum-file.c
csum-file.h
ctype.c
daemon.c
date.c
decorate.c
decorate.h
delta.h
diff-delta.c
diff-lib.c
diff.c
diff.h
diffcore-break.c
diffcore-delta.c
diffcore-order.c
diffcore-pickaxe.c
diffcore-rename.c
diffcore.h
dir.c
dir.h
dump-cache-tree.c
entry.c
environment.c
exec_cmd.c
exec_cmd.h
fast-import.c
fetch-pack.h
fixup-builtins
generate-cmdlist.sh
git-add--interactive.perl
git-am.sh
git-archimport.perl
git-bisect.sh
git-checkout.sh
git-clone.sh
git-compat-util.h
git-cvsexportcommit.perl
git-cvsimport.perl
git-cvsserver.perl
git-filter-branch.sh
git-help--browse.sh
git-instaweb.sh
git-lost-found.sh
git-merge-octopus.sh
git-merge-one-file.sh
git-merge-resolve.sh
git-merge-stupid.sh
git-merge.sh
git-mergetool.sh
git-parse-remote.sh
git-pull.sh
git-quiltimport.sh
git-rebase--interactive.sh
git-rebase.sh
git-relink.perl
git-remote.perl
git-repack.sh
git-request-pull.sh
git-send-email.perl
git-sh-setup.sh
git-stash.sh
git-submodule.sh
git-svn.perl
git.c
git.spec.in
grep.c
grep.h
hash-object.c
hash.c
hash.h
help.c
http-push.c
http-walker.c
http.c
http.h
ident.c
imap-send.c
index-pack.c
interpolate.c
interpolate.h
list-objects.c
list-objects.h
lockfile.c
log-tree.c
log-tree.h
mailmap.c
mailmap.h
match-trees.c
merge-file.c
merge-index.c
merge-recursive.c
merge-tree.c
mktag.c
mktree.c
object-refs.c
object.c
object.h
pack-check.c
pack-redundant.c
pack-write.c
pack.h
pager.c
parse-options.c
parse-options.h
patch-delta.c
patch-id.c
patch-ids.c
patch-ids.h
path-list.c
path-list.h
path.c
pkt-line.c
pkt-line.h
pretty.c
progress.c
progress.h
quote.c
quote.h
reachable.c
reachable.h
read-cache.c
receive-pack.c
reflog-walk.c
reflog-walk.h
refs.c
refs.h
remote.c
remote.h
revision.c
revision.h
run-command.c
run-command.h
send-pack.h
server-info.c
setup.c
sha1_file.c
sha1_name.c
shallow.c
shell.c
show-index.c
sideband.c
sideband.h
strbuf.c
strbuf.h
symlinks.c
tag.c
tag.h
tar.h
test-absolute-path.c
test-chmtime.c
test-date.c
test-delta.c
test-genrandom.c
test-match-trees.c
test-parse-options.c
test-sha1.c
test-sha1.sh
trace.c
transport.c
transport.h
tree-diff.c
tree-walk.c
tree-walk.h
tree.c
tree.h
unpack-file.c
unpack-trees.c
unpack-trees.h
update-server-info.c
upload-pack.c
usage.c
utf8.c
utf8.h
var.c
walker.c
walker.h
write_or_die.c
ws.c
wt-status.c
wt-status.h
xdiff-interface.c
xdiff-interface.h
Breadcrumbs
git
/
git-gui
/
lib
/
diff.tcl
Blame
Blame
Latest commit
History
History
364 lines (327 loc) · 8.35 KB
Breadcrumbs
git
/
git-gui
/
lib
/
diff.tcl
Top
File metadata and controls
Code
Blame
364 lines (327 loc) · 8.35 KB
Raw
# git-gui diff viewer # Copyright (C) 2006, 2007 Shawn Pearce proc clear_diff {} { global ui_diff current_diff_path current_diff_header global ui_index ui_workdir $ui_diff conf -state normal $ui_diff delete 0.0 end $ui_diff conf -state disabled set current_diff_path {} set current_diff_header {} $ui_index tag remove in_diff 0.0 end $ui_workdir tag remove in_diff 0.0 end } proc reshow_diff {} { global file_states file_lists global current_diff_path current_diff_side set p $current_diff_path if {$p eq {}} { # No diff is being shown. } elseif {$current_diff_side eq {} || [catch {set s $file_states($p)}] || [lsearch -sorted -exact $file_lists($current_diff_side) $p] == -1} { clear_diff } else { show_diff $p $current_diff_side } } proc handle_empty_diff {} { global current_diff_path file_states file_lists set path $current_diff_path set s $file_states($path) if {[lindex $s 0] ne {_M}} return info_popup [mc "No differences detected. %s has no changes. The modification date of this file was updated by another application, but the content within the file was not changed. A rescan will be automatically started to find other files which may have the same state." [short_path $path]] clear_diff display_file $path __ rescan ui_ready 0 } proc show_diff {path w {lno {}}} { global file_states file_lists global is_3way_diff diff_active repo_config global ui_diff ui_index ui_workdir global current_diff_path current_diff_side current_diff_header if {$diff_active || ![lock_index read]} return clear_diff if {$lno == {}} { set lno [lsearch -sorted -exact $file_lists($w) $path] if {$lno >= 0} { incr lno } } if {$lno >= 1} { $w tag add in_diff $lno.0 [expr {$lno + 1}].0 } set s $file_states($path) set m [lindex $s 0] set is_3way_diff 0 set diff_active 1 set current_diff_path $path set current_diff_side $w set current_diff_header {} ui_status [mc "Loading diff of %s..." [escape_path $path]] # - Git won't give us the diff, there's nothing to compare to! # if {$m eq {_O}} { set max_sz [expr {128 * 1024}] set type unknown if {[catch { set type [file type $path] switch -- $type { directory { set type submodule set content {} set sz 0 } link { set content [file readlink $path] set sz [string length $content] } file { set fd [open $path r] fconfigure $fd -eofchar {} set content [read $fd $max_sz] close $fd set sz [file size $path] } default { error "'$type' not supported" } } } err ]} { set diff_active 0 unlock_index ui_status [mc "Unable to display %s" [escape_path $path]] error_popup [strcat [mc "Error loading file:"] "\n\n$err"] return } $ui_diff conf -state normal if {$type eq {submodule}} { $ui_diff insert end [append \ "* " \ [mc "Git Repository (subproject)"] \ "\n"] d_@ } elseif {![catch {set type [exec file $path]}]} { set n [string length $path] if {[string equal -length $n $path $type]} { set type [string range $type $n end] regsub {^:?\s*} $type {} type } $ui_diff insert end "* $type\n" d_@ } if {[string first "\0" $content] != -1} { $ui_diff insert end \ [mc "* Binary file (not showing content)."] \ d_@ } else { if {$sz > $max_sz} { $ui_diff insert end \ "* Untracked file is $sz bytes. * Showing only first $max_sz bytes. " d_@ } $ui_diff insert end $content if {$sz > $max_sz} { $ui_diff insert end " * Untracked file clipped here by [appname]. * To see the entire file, use an external editor. " d_@ } } $ui_diff conf -state disabled set diff_active 0 unlock_index ui_ready return } set cmd [list] if {$w eq $ui_index} { lappend cmd diff-index lappend cmd --cached } elseif {$w eq $ui_workdir} { if {[string index $m 0] eq {U}} { lappend cmd diff } else { lappend cmd diff-files } } lappend cmd -p lappend cmd --no-color if {$repo_config(gui.diffcontext) >= 0} { lappend cmd "-U$repo_config(gui.diffcontext)" } if {$w eq $ui_index} { lappend cmd [PARENT] } lappend cmd -- lappend cmd $path if {[catch {set fd [eval git_read --nice $cmd]} err]} { set diff_active 0 unlock_index ui_status [mc "Unable to display %s" [escape_path $path]] error_popup [strcat [mc "Error loading diff:"] "\n\n$err"] return } fconfigure $fd \ -blocking 0 \ -encoding binary \ -translation binary fileevent $fd readable [list read_diff $fd] } proc read_diff {fd} { global ui_diff diff_active global is_3way_diff current_diff_header $ui_diff conf -state normal while {[gets $fd line] >= 0} { # -- Cleanup uninteresting diff header lines. # if { [string match {diff --git *} $line] || [string match {diff --cc *} $line] || [string match {diff --combined *} $line] || [string match {--- *} $line] || [string match {+++ *} $line]} { append current_diff_header $line "\n" continue } if {[string match {index *} $line]} continue if {$line eq {deleted file mode 120000}} { set line "deleted symlink" } # -- Automatically detect if this is a 3 way diff. # if {[string match {@@@ *} $line]} {set is_3way_diff 1} if {[string match {mode *} $line] || [string match {new file *} $line] || [regexp {^(old|new) mode *} $line] || [string match {deleted file *} $line] || [string match {deleted symlink} $line] || [string match {Binary files * and * differ} $line] || $line eq {\ No newline at end of file} || [regexp {^\* Unmerged path } $line]} { set tags {} } elseif {$is_3way_diff} { set op [string range $line 0 1] switch -- $op { { } {set tags {}} {@@} {set tags d_@} { +} {set tags d_s+} { -} {set tags d_s-} {+ } {set tags d_+s} {- } {set tags d_-s} {--} {set tags d_--} {++} { if {[regexp {^\+\+([<>]{7} |={7})} $line _g op]} { set line [string replace $line 0 1 { }] set tags d$op } else { set tags d_++ } } default { puts "error: Unhandled 3 way diff marker: {$op}" set tags {} } } } else { set op [string index $line 0] switch -- $op { { } {set tags {}} {@} {set tags d_@} {-} {set tags d_-} {+} { if {[regexp {^\+([<>]{7} |={7})} $line _g op]} { set line [string replace $line 0 0 { }] set tags d$op } else { set tags d_+ } } default { puts "error: Unhandled 2 way diff marker: {$op}" set tags {} } } } $ui_diff insert end $line $tags if {[string index $line end] eq "\r"} { $ui_diff tag add d_cr {end - 2c} } $ui_diff insert end "\n" $tags } $ui_diff conf -state disabled if {[eof $fd]} { close $fd set diff_active 0 unlock_index ui_ready if {[$ui_diff index end] eq {2.0}} { handle_empty_diff } } } proc apply_hunk {x y} { global current_diff_path current_diff_header current_diff_side global ui_diff ui_index file_states if {$current_diff_path eq {} || $current_diff_header eq {}} return if {![lock_index apply_hunk]} return set apply_cmd {apply --cached --whitespace=nowarn} set mi [lindex $file_states($current_diff_path) 0] if {$current_diff_side eq $ui_index} { set failed_msg [mc "Failed to unstage selected hunk."] lappend apply_cmd --reverse if {[string index $mi 0] ne {M}} { unlock_index return } } else { set failed_msg [mc "Failed to stage selected hunk."] if {[string index $mi 1] ne {M}} { unlock_index return } } set s_lno [lindex [split [$ui_diff index @$x,$y] .] 0] set s_lno [$ui_diff search -backwards -regexp ^@@ $s_lno.0 0.0] if {$s_lno eq {}} { unlock_index return } set e_lno [$ui_diff search -forwards -regexp ^@@ "$s_lno + 1 lines" end] if {$e_lno eq {}} { set e_lno end } if {[catch { set p [eval git_write $apply_cmd] fconfigure $p -translation binary -encoding binary puts -nonewline $p $current_diff_header puts -nonewline $p [$ui_diff get $s_lno $e_lno] close $p} err]} { error_popup [append $failed_msg "\n\n$err"] unlock_index return } $ui_diff conf -state normal $ui_diff delete $s_lno $e_lno $ui_diff conf -state disabled if {[$ui_diff get 1.0 end] eq "\n"} { set o _ } else { set o ? } if {$current_diff_side eq $ui_index} { set mi ${o}M } elseif {[string index $mi 0] eq {_}} { set mi M$o } else { set mi ?$o } unlock_index display_file $current_diff_path $mi if {$o eq {_}} { clear_diff } else { set current_diff_path $current_diff_path } }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
You can’t perform that action at this time.