Skip to content

Commit 0984e3a

Browse files
committed
Merge git://git.kernel.org/pub/scm/gitk/gitk
* git://git.kernel.org/pub/scm/gitk/gitk: gitk: Work around leftover temporary save file gitk: Show diff of commits at end of compare-commits output gitk: Update Swedish translation (280t0f0u)
2 parents 6e4ece6 + 9bedb0e commit 0984e3a

File tree

2 files changed

+618
-259
lines changed

2 files changed

+618
-259
lines changed

gitk-git/gitk

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,6 +2526,7 @@ proc savestuff {w} {
25262526
if {$stuffsaved} return
25272527
if {![winfo viewable .]} return
25282528
catch {
2529+
if {[file exists ~/.gitk-new]} {file delete -force ~/.gitk-new}
25292530
set f [open "~/.gitk-new" w]
25302531
if {$::tcl_platform(platform) eq {windows}} {
25312532
file attributes "~/.gitk-new" -hidden true
@@ -3167,6 +3168,28 @@ proc flist_hl {only} {
31673168
set gdttype [mc "touching paths:"]
31683169
}
31693170

3171+
proc gitknewtmpdir {} {
3172+
global diffnum gitktmpdir gitdir
3173+
3174+
if {![info exists gitktmpdir]} {
3175+
set gitktmpdir [file join [file dirname $gitdir] \
3176+
[format ".gitk-tmp.%s" [pid]]]
3177+
if {[catch {file mkdir $gitktmpdir} err]} {
3178+
error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3179+
unset gitktmpdir
3180+
return {}
3181+
}
3182+
set diffnum 0
3183+
}
3184+
incr diffnum
3185+
set diffdir [file join $gitktmpdir $diffnum]
3186+
if {[catch {file mkdir $diffdir} err]} {
3187+
error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3188+
return {}
3189+
}
3190+
return $diffdir
3191+
}
3192+
31703193
proc save_file_from_commit {filename output what} {
31713194
global nullfile
31723195

@@ -3201,11 +3224,10 @@ proc external_diff_get_one_file {diffid filename diffdir} {
32013224
}
32023225

32033226
proc external_diff {} {
3204-
global gitktmpdir nullid nullid2
3227+
global nullid nullid2
32053228
global flist_menu_file
32063229
global diffids
3207-
global diffnum
3208-
global gitdir extdifftool
3230+
global extdifftool
32093231

32103232
if {[llength $diffids] == 1} {
32113233
# no reference commit given
@@ -3227,22 +3249,8 @@ proc external_diff {} {
32273249
}
32283250

32293251
# make sure that several diffs wont collide
3230-
if {![info exists gitktmpdir]} {
3231-
set gitktmpdir [file join [file dirname $gitdir] \
3232-
[format ".gitk-tmp.%s" [pid]]]
3233-
if {[catch {file mkdir $gitktmpdir} err]} {
3234-
error_popup "[mc "Error creating temporary directory %s:" $gitktmpdir] $err"
3235-
unset gitktmpdir
3236-
return
3237-
}
3238-
set diffnum 0
3239-
}
3240-
incr diffnum
3241-
set diffdir [file join $gitktmpdir $diffnum]
3242-
if {[catch {file mkdir $diffdir} err]} {
3243-
error_popup "[mc "Error creating temporary directory %s:" $diffdir] $err"
3244-
return
3245-
}
3252+
set diffdir [gitknewtmpdir]
3253+
if {$diffdir eq {}} return
32463254

32473255
# gather files to diff
32483256
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
@@ -7400,7 +7408,7 @@ proc getblobdiffline {bdf ids} {
74007408
$ctext conf -state normal
74017409
while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
74027410
if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
7403-
close $bdf
7411+
catch {close $bdf}
74047412
return 0
74057413
}
74067414
if {![string compare -length 5 "diff " $line]} {
@@ -7552,7 +7560,7 @@ proc getblobdiffline {bdf ids} {
75527560
}
75537561
$ctext conf -state disabled
75547562
if {[eof $bdf]} {
7555-
close $bdf
7563+
catch {close $bdf}
75567564
return 0
75577565
}
75587566
return [expr {$nr >= 1000? 2: 1}]
@@ -8273,8 +8281,11 @@ proc do_cmp_commits {a b} {
82738281
appendshortlink $a [mc "Commit "] " $heada\n"
82748282
appendshortlink $b [mc " differs from\n "] \
82758283
" $headb\n"
8276-
$ctext insert end [mc "- stopping\n"]
8277-
break
8284+
$ctext insert end [mc "Diff of commits:\n\n"]
8285+
$ctext conf -state disabled
8286+
update
8287+
diffcommits $a $b
8288+
return
82788289
}
82798290
}
82808291
if {$skipa} {
@@ -8300,6 +8311,31 @@ proc do_cmp_commits {a b} {
83008311
$ctext conf -state disabled
83018312
}
83028313

8314+
proc diffcommits {a b} {
8315+
global diffcontext diffids blobdifffd diffinhdr
8316+
8317+
set tmpdir [gitknewtmpdir]
8318+
set fna [file join $tmpdir "commit-[string range $a 0 7]"]
8319+
set fnb [file join $tmpdir "commit-[string range $b 0 7]"]
8320+
if {[catch {
8321+
exec git diff-tree -p --pretty $a >$fna
8322+
exec git diff-tree -p --pretty $b >$fnb
8323+
} err]} {
8324+
error_popup [mc "Error writing commit to file: %s" $err]
8325+
return
8326+
}
8327+
if {[catch {
8328+
set fd [open "| diff -U$diffcontext $fna $fnb" r]
8329+
} err]} {
8330+
error_popup [mc "Error diffing commits: %s" $err]
8331+
return
8332+
}
8333+
set diffids [list commits $a $b]
8334+
set blobdifffd($diffids) $fd
8335+
set diffinhdr 0
8336+
filerun $fd [list getblobdiffline $fd $diffids]
8337+
}
8338+
83038339
proc diffvssel {dirn} {
83048340
global rowmenuid selectedline
83058341

0 commit comments

Comments
 (0)