blob: 96288fcc332e0083a56fcbb9248bc10ac536388e [file] [log] [blame]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -04001# git-gui diff viewer
2# Copyright (C) 2006, 2007 Shawn Pearce
3
Michael Lutza43c5f52012-02-12 16:55:17 +01004proc apply_tab_size {{firsttab {}}} {
5 global have_tk85 repo_config ui_diff
6
7 set w [font measure font_diff "0"]
8 if {$have_tk85 && $firsttab != 0} {
9 $ui_diff configure -tabs [list [expr {$firsttab * $w}] [expr {($firsttab + $repo_config(gui.tabsize)) * $w}]]
10 } elseif {$have_tk85 || $repo_config(gui.tabsize) != 8} {
11 $ui_diff configure -tabs [expr {$repo_config(gui.tabsize) * $w}]
12 } else {
13 $ui_diff configure -tabs {}
14 }
15}
16
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040017proc clear_diff {} {
18 global ui_diff current_diff_path current_diff_header
19 global ui_index ui_workdir
20
21 $ui_diff conf -state normal
22 $ui_diff delete 0.0 end
23 $ui_diff conf -state disabled
24
25 set current_diff_path {}
26 set current_diff_header {}
27
28 $ui_index tag remove in_diff 0.0 end
29 $ui_workdir tag remove in_diff 0.0 end
30}
31
Alexander Gavrilov7cf45662008-11-16 21:46:48 +030032proc reshow_diff {{after {}}} {
Shawn O. Pearce699d5602007-07-05 23:16:13 -040033 global file_states file_lists
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040034 global current_diff_path current_diff_side
Alexander Gavrilov25b8fb12008-07-27 10:35:38 +040035 global ui_diff
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040036
37 set p $current_diff_path
38 if {$p eq {}} {
39 # No diff is being shown.
Alexander Gavrilov29853b92008-08-31 01:02:56 +040040 } elseif {$current_diff_side eq {}} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040041 clear_diff
Alexander Gavrilov29853b92008-08-31 01:02:56 +040042 } elseif {[catch {set s $file_states($p)}]
43 || [lsearch -sorted -exact $file_lists($current_diff_side) $p] == -1} {
44
45 if {[find_next_diff $current_diff_side $p {} {[^O]}]} {
Alexander Gavrilov7cf45662008-11-16 21:46:48 +030046 next_diff $after
Alexander Gavrilov29853b92008-08-31 01:02:56 +040047 } else {
48 clear_diff
49 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040050 } else {
Alexander Gavrilov25b8fb12008-07-27 10:35:38 +040051 set save_pos [lindex [$ui_diff yview] 0]
Alexander Gavrilov7cf45662008-11-16 21:46:48 +030052 show_diff $p $current_diff_side {} $save_pos $after
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040053 }
54}
55
Alexander Gavrilov3fe01622008-09-18 01:07:34 +040056proc force_diff_encoding {enc} {
57 global current_diff_path
Pratyush Yadav5f0a5162019-08-26 01:35:27 +053058
Alexander Gavrilov3fe01622008-09-18 01:07:34 +040059 if {$current_diff_path ne {}} {
60 force_path_encoding $current_diff_path $enc
61 reshow_diff
62 }
63}
64
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040065proc handle_empty_diff {} {
66 global current_diff_path file_states file_lists
Alexander Gavrilov584fa9c2009-02-07 19:24:01 +030067 global diff_empty_count
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040068
69 set path $current_diff_path
70 set s $file_states($path)
Clément Poulain1fbacca2010-07-30 09:11:02 +010071 if {[lindex $s 0] ne {_M} || [has_textconv $path]} return
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040072
Alexander Gavrilov584fa9c2009-02-07 19:24:01 +030073 # Prevent infinite rescan loops
74 incr diff_empty_count
75 if {$diff_empty_count > 1} return
76
Christian Stimming1ac17952007-07-21 14:21:34 +020077 info_popup [mc "No differences detected.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040078
Christian Stimming1ac17952007-07-21 14:21:34 +020079%s has no changes.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040080
81The modification date of this file was updated by another application, but the content within the file was not changed.
82
Christian Stimming1ac17952007-07-21 14:21:34 +020083A rescan will be automatically started to find other files which may have the same state." [short_path $path]]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040084
85 clear_diff
86 display_file $path __
Shawn O. Pearce699d5602007-07-05 23:16:13 -040087 rescan ui_ready 0
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040088}
89
Alexander Gavrilov3e348382008-09-20 12:19:18 +040090proc show_diff {path w {lno {}} {scroll_pos {}} {callback {}}} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040091 global file_states file_lists
Alexander Gavrilov3e348382008-09-20 12:19:18 +040092 global is_3way_diff is_conflict_diff diff_active repo_config
Shawn O. Pearce699d5602007-07-05 23:16:13 -040093 global ui_diff ui_index ui_workdir
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040094 global current_diff_path current_diff_side current_diff_header
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +040095 global current_diff_queue
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -040096
97 if {$diff_active || ![lock_index read]} return
98
99 clear_diff
100 if {$lno == {}} {
101 set lno [lsearch -sorted -exact $file_lists($w) $path]
102 if {$lno >= 0} {
103 incr lno
104 }
105 }
106 if {$lno >= 1} {
107 $w tag add in_diff $lno.0 [expr {$lno + 1}].0
Alexander Gavrilov29853b92008-08-31 01:02:56 +0400108 $w see $lno.0
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400109 }
110
111 set s $file_states($path)
112 set m [lindex $s 0]
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400113 set is_conflict_diff 0
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400114 set current_diff_path $path
115 set current_diff_side $w
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400116 set current_diff_queue {}
Michele Ballabioc8c48542007-09-13 15:19:05 +0200117 ui_status [mc "Loading diff of %s..." [escape_path $path]]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400118
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400119 set cont_info [list $scroll_pos $callback]
120
Michael Lutza43c5f52012-02-12 16:55:17 +0100121 apply_tab_size 0
122
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400123 if {[string first {U} $m] >= 0} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400124 merge_load_stages $path [list show_unmerged_diff $cont_info]
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400125 } elseif {$m eq {_O}} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400126 show_other_diff $path $w $m $cont_info
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400127 } else {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400128 start_show_diff $cont_info
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400129 }
Alex Riesena0a0c682016-06-28 10:59:25 +0200130
131 global current_diff_path selected_paths
132 set selected_paths($current_diff_path) 1
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400133}
134
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400135proc show_unmerged_diff {cont_info} {
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400136 global current_diff_path current_diff_side
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400137 global merge_stages ui_diff is_conflict_diff
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400138 global current_diff_queue
139
140 if {$merge_stages(2) eq {}} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400141 set is_conflict_diff 1
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400142 lappend current_diff_queue \
Bert Wesargc7ec31a2010-11-29 09:21:57 +0100143 [list [mc "LOCAL: deleted\nREMOTE:\n"] d= \
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400144 [list ":1:$current_diff_path" ":3:$current_diff_path"]]
145 } elseif {$merge_stages(3) eq {}} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400146 set is_conflict_diff 1
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400147 lappend current_diff_queue \
Bert Wesargc7ec31a2010-11-29 09:21:57 +0100148 [list [mc "REMOTE: deleted\nLOCAL:\n"] d= \
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400149 [list ":1:$current_diff_path" ":2:$current_diff_path"]]
150 } elseif {[lindex $merge_stages(1) 0] eq {120000}
151 || [lindex $merge_stages(2) 0] eq {120000}
152 || [lindex $merge_stages(3) 0] eq {120000}} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400153 set is_conflict_diff 1
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400154 lappend current_diff_queue \
Bert Wesargc7ec31a2010-11-29 09:21:57 +0100155 [list [mc "LOCAL:\n"] d= \
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400156 [list ":1:$current_diff_path" ":2:$current_diff_path"]]
157 lappend current_diff_queue \
Bert Wesargc7ec31a2010-11-29 09:21:57 +0100158 [list [mc "REMOTE:\n"] d= \
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400159 [list ":1:$current_diff_path" ":3:$current_diff_path"]]
160 } else {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400161 start_show_diff $cont_info
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400162 return
163 }
164
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400165 advance_diff_queue $cont_info
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400166}
167
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400168proc advance_diff_queue {cont_info} {
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400169 global current_diff_queue ui_diff
170
171 set item [lindex $current_diff_queue 0]
172 set current_diff_queue [lrange $current_diff_queue 1 end]
173
174 $ui_diff conf -state normal
175 $ui_diff insert end [lindex $item 0] [lindex $item 1]
176 $ui_diff conf -state disabled
177
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400178 start_show_diff $cont_info [lindex $item 2]
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400179}
180
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400181proc show_other_diff {path w m cont_info} {
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400182 global file_states file_lists
183 global is_3way_diff diff_active repo_config
184 global ui_diff ui_index ui_workdir
185 global current_diff_path current_diff_side current_diff_header
186
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400187 # - Git won't give us the diff, there's nothing to compare to!
188 #
189 if {$m eq {_O}} {
Johannes Sixtf2df8a52008-10-03 10:28:49 +0200190 set max_sz 100000
Shawn O. Pearce3b9dfde2007-09-09 20:13:10 -0400191 set type unknown
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400192 if {[catch {
Shawn O. Pearce3b9dfde2007-09-09 20:13:10 -0400193 set type [file type $path]
194 switch -- $type {
195 directory {
196 set type submodule
197 set content {}
198 set sz 0
199 }
200 link {
Michele Ballabio2d19f8e2007-09-09 21:04:45 +0200201 set content [file readlink $path]
202 set sz [string length $content]
Shawn O. Pearce3b9dfde2007-09-09 20:13:10 -0400203 }
204 file {
Michele Ballabio2d19f8e2007-09-09 21:04:45 +0200205 set fd [open $path r]
Shawn O. Pearce1ffca602008-01-23 00:37:10 -0500206 fconfigure $fd \
207 -eofchar {} \
Alexander Gavrilov72e6b002008-09-18 01:07:32 +0400208 -encoding [get_path_encoding $path]
Michele Ballabio2d19f8e2007-09-09 21:04:45 +0200209 set content [read $fd $max_sz]
210 close $fd
211 set sz [file size $path]
212 }
Shawn O. Pearce3b9dfde2007-09-09 20:13:10 -0400213 default {
214 error "'$type' not supported"
215 }
216 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400217 } err ]} {
218 set diff_active 0
219 unlock_index
Michele Ballabioc8c48542007-09-13 15:19:05 +0200220 ui_status [mc "Unable to display %s" [escape_path $path]]
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -0400221 error_popup [strcat [mc "Error loading file:"] "\n\n$err"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400222 return
223 }
224 $ui_diff conf -state normal
Shawn O. Pearce3b9dfde2007-09-09 20:13:10 -0400225 if {$type eq {submodule}} {
Vasco Almeidaa3d97af2016-05-08 10:52:57 +0000226 $ui_diff insert end \
227 "* [mc "Git Repository (subproject)"]\n" \
228 d_info
Shawn O. Pearce3b9dfde2007-09-09 20:13:10 -0400229 } elseif {![catch {set type [exec file $path]}]} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400230 set n [string length $path]
231 if {[string equal -length $n $path $type]} {
232 set type [string range $type $n end]
233 regsub {^:?\s*} $type {} type
234 }
Bert Wesarg88b21c22010-12-06 22:01:01 +0000235 $ui_diff insert end "* $type\n" d_info
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400236 }
237 if {[string first "\0" $content] != -1} {
238 $ui_diff insert end \
Michele Ballabioc8c48542007-09-13 15:19:05 +0200239 [mc "* Binary file (not showing content)."] \
Bert Wesarg88b21c22010-12-06 22:01:01 +0000240 d_info
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400241 } else {
242 if {$sz > $max_sz} {
Johannes Sixt7f15b002008-10-03 13:13:42 +0200243 $ui_diff insert end [mc \
244"* Untracked file is %d bytes.
245* Showing only first %d bytes.
Bert Wesarg88b21c22010-12-06 22:01:01 +0000246" $sz $max_sz] d_info
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400247 }
248 $ui_diff insert end $content
249 if {$sz > $max_sz} {
Johannes Sixt7f15b002008-10-03 13:13:42 +0200250 $ui_diff insert end [mc "
251* Untracked file clipped here by %s.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400252* To see the entire file, use an external editor.
Bert Wesarg88b21c22010-12-06 22:01:01 +0000253" [appname]] d_info
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400254 }
255 }
256 $ui_diff conf -state disabled
257 set diff_active 0
258 unlock_index
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400259 set scroll_pos [lindex $cont_info 0]
Alexander Gavrilov25b8fb12008-07-27 10:35:38 +0400260 if {$scroll_pos ne {}} {
261 update
262 $ui_diff yview moveto $scroll_pos
263 }
Shawn O. Pearce699d5602007-07-05 23:16:13 -0400264 ui_ready
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400265 set callback [lindex $cont_info 1]
266 if {$callback ne {}} {
267 eval $callback
268 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400269 return
270 }
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400271}
272
Bert Wesarg45903072010-11-16 10:21:52 +0100273proc get_conflict_marker_size {path} {
274 set size 7
275 catch {
276 set fd_rc [eval [list git_read check-attr "conflict-marker-size" -- $path]]
277 set ret [gets $fd_rc line]
278 close $fd_rc
279 if {$ret > 0} {
280 regexp {.*: conflict-marker-size: (\d+)$} $line line size
281 }
282 }
283 return $size
284}
285
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400286proc start_show_diff {cont_info {add_opts {}}} {
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400287 global file_states file_lists
Jens Lehmann246295b2009-07-21 19:32:31 +0200288 global is_3way_diff is_submodule_diff diff_active repo_config
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400289 global ui_diff ui_index ui_workdir
290 global current_diff_path current_diff_side current_diff_header
291
292 set path $current_diff_path
293 set w $current_diff_side
294
295 set s $file_states($path)
296 set m [lindex $s 0]
297 set is_3way_diff 0
Jens Lehmann246295b2009-07-21 19:32:31 +0200298 set is_submodule_diff 0
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400299 set diff_active 1
300 set current_diff_header {}
Bert Wesarg45903072010-11-16 10:21:52 +0100301 set conflict_size [get_conflict_marker_size $path]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400302
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400303 set cmd [list]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400304 if {$w eq $ui_index} {
305 lappend cmd diff-index
306 lappend cmd --cached
Jens Lehmanne0db1dd2014-04-08 21:30:51 +0200307 if {[git-version >= "1.7.2"]} {
308 lappend cmd --ignore-submodules=dirty
309 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400310 } elseif {$w eq $ui_workdir} {
Alexander Gavrilovff515d82008-08-31 01:00:49 +0400311 if {[string first {U} $m] >= 0} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400312 lappend cmd diff
313 } else {
314 lappend cmd diff-files
315 }
316 }
Clément Poulain1fbacca2010-07-30 09:11:02 +0100317 if {![is_config_false gui.textconv] && [git-version >= 1.6.1]} {
318 lappend cmd --textconv
319 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400320
Jens Lehmanna9ae14a2010-01-23 23:04:12 +0100321 if {[string match {160000 *} [lindex $s 2]]
322 || [string match {160000 *} [lindex $s 3]]} {
323 set is_submodule_diff 1
324
325 if {[git-version >= "1.6.6"]} {
326 lappend cmd --submodule
327 }
328 }
329
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400330 lappend cmd -p
Pat Thoyts8f855992010-10-22 16:14:38 +0100331 lappend cmd --color
Tilman Vogel54531e72011-01-21 11:59:45 +0100332 set cmd [concat $cmd $repo_config(gui.diffopts)]
Clemens Buchacher55ba8a32008-08-30 18:45:27 +0200333 if {$repo_config(gui.diffcontext) >= 1} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400334 lappend cmd "-U$repo_config(gui.diffcontext)"
335 }
336 if {$w eq $ui_index} {
337 lappend cmd [PARENT]
338 }
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400339 if {$add_opts ne {}} {
340 eval lappend cmd $add_opts
341 } else {
342 lappend cmd --
343 lappend cmd $path
344 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400345
Jens Lehmanna9ae14a2010-01-23 23:04:12 +0100346 if {$is_submodule_diff && [git-version < "1.6.6"]} {
Jens Lehmannaf413de2009-08-26 22:25:15 +0200347 if {$w eq $ui_index} {
Shawn O. Pearce118d9382009-08-26 17:39:45 -0700348 set cmd [list submodule summary --cached -- $path]
Jens Lehmannaf413de2009-08-26 22:25:15 +0200349 } else {
Shawn O. Pearce118d9382009-08-26 17:39:45 -0700350 set cmd [list submodule summary --files -- $path]
Jens Lehmannaf413de2009-08-26 22:25:15 +0200351 }
Jens Lehmann246295b2009-07-21 19:32:31 +0200352 }
353
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400354 if {[catch {set fd [eval git_read --nice $cmd]} err]} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400355 set diff_active 0
356 unlock_index
Michele Ballabioc8c48542007-09-13 15:19:05 +0200357 ui_status [mc "Unable to display %s" [escape_path $path]]
Shawn O. Pearce31bb1d12007-09-14 01:50:09 -0400358 error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400359 return
360 }
361
Shawn O. Pearceca53c3f2008-09-04 21:46:56 -0700362 set ::current_diff_inheader 1
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400363 fconfigure $fd \
364 -blocking 0 \
Alexander Gavrilov72e6b002008-09-18 01:07:32 +0400365 -encoding [get_path_encoding $path] \
Shawn O. Pearce1ffca602008-01-23 00:37:10 -0500366 -translation lf
Bert Wesarg45903072010-11-16 10:21:52 +0100367 fileevent $fd readable [list read_diff $fd $conflict_size $cont_info]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400368}
369
Pat Thoyts8f855992010-10-22 16:14:38 +0100370proc parse_color_line {line} {
371 set start 0
372 set result ""
373 set markup [list]
374 set regexp {\033\[((?:\d+;)*\d+)?m}
Bert Wesarg46a04312010-11-15 11:00:33 +0100375 set need_reset 0
Pat Thoyts8f855992010-10-22 16:14:38 +0100376 while {[regexp -indices -start $start $regexp $line match code]} {
377 foreach {begin end} $match break
378 append result [string range $line $start [expr {$begin - 1}]]
Bert Wesarg46a04312010-11-15 11:00:33 +0100379 set pos [string length $result]
380 set col [eval [linsert $code 0 string range $line]]
Pat Thoyts8f855992010-10-22 16:14:38 +0100381 set start [incr end]
Bert Wesarg46a04312010-11-15 11:00:33 +0100382 if {$col eq "0" || $col eq ""} {
383 if {!$need_reset} continue
384 set need_reset 0
385 } else {
386 set need_reset 1
387 }
388 lappend markup $pos $col
Pat Thoyts8f855992010-10-22 16:14:38 +0100389 }
390 append result [string range $line $start end]
391 if {[llength $markup] < 4} {set markup {}}
392 return [list $result $markup]
393}
394
Bert Wesarg45903072010-11-16 10:21:52 +0100395proc read_diff {fd conflict_size cont_info} {
Jens Lehmann246295b2009-07-21 19:32:31 +0200396 global ui_diff diff_active is_submodule_diff
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400397 global is_3way_diff is_conflict_diff current_diff_header
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400398 global current_diff_queue
Alexander Gavrilov584fa9c2009-02-07 19:24:01 +0300399 global diff_empty_count
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400400
401 $ui_diff conf -state normal
402 while {[gets $fd line] >= 0} {
Pat Thoyts8f855992010-10-22 16:14:38 +0100403 foreach {line markup} [parse_color_line $line] break
404 set line [string map {\033 ^} $line]
405
Bert Wesarg6459d7c2010-12-09 21:47:57 +0100406 set tags {}
407
Bert Wesargc976bbf2010-12-09 21:47:52 +0100408 # -- Check for start of diff header.
409 if { [string match {diff --git *} $line]
410 || [string match {diff --cc *} $line]
411 || [string match {diff --combined *} $line]} {
412 set ::current_diff_inheader 1
413 }
414
415 # -- Check for end of diff header (any hunk line will do this).
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400416 #
Bert Wesargc976bbf2010-12-09 21:47:52 +0100417 if {[regexp {^@@+ } $line]} {set ::current_diff_inheader 0}
418
Bert Wesarg963ceab2010-12-09 21:47:56 +0100419 # -- Automatically detect if this is a 3 way diff.
420 #
Michael Lutza43c5f52012-02-12 16:55:17 +0100421 if {[string match {@@@ *} $line]} {
422 set is_3way_diff 1
423 apply_tab_size 1
424 }
Bert Wesarg963ceab2010-12-09 21:47:56 +0100425
Shawn O. Pearceca53c3f2008-09-04 21:46:56 -0700426 if {$::current_diff_inheader} {
Bert Wesargd1c7f8a2010-12-09 21:47:58 +0100427
428 # -- These two lines stop a diff header and shouldn't be in there
429 if { [string match {Binary files * and * differ} $line]
430 || [regexp {^\* Unmerged path } $line]} {
431 set ::current_diff_inheader 0
432 } else {
433 append current_diff_header $line "\n"
434 }
Bert Wesargc976bbf2010-12-09 21:47:52 +0100435
436 # -- Cleanup uninteresting diff header lines.
437 #
Shawn O. Pearceca53c3f2008-09-04 21:46:56 -0700438 if { [string match {diff --git *} $line]
439 || [string match {diff --cc *} $line]
440 || [string match {diff --combined *} $line]
441 || [string match {--- *} $line]
Bert Wesargebd143f2010-12-09 21:47:53 +0100442 || [string match {+++ *} $line]
443 || [string match {index *} $line]} {
Shawn O. Pearceca53c3f2008-09-04 21:46:56 -0700444 continue
445 }
Bert Wesarg97b8ee12010-12-09 21:47:54 +0100446
447 # -- Name it symlink, not 120000
448 # Note, that the original line is in $current_diff_header
449 regsub {^(deleted|new) file mode 120000} $line {\1 symlink} line
Bert Wesargc976bbf2010-12-09 21:47:52 +0100450
Bert Wesargbf594392010-12-09 21:47:59 +0100451 } elseif { $line eq {\ No newline at end of file}} {
452 # -- Handle some special lines
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400453 } elseif {$is_3way_diff} {
454 set op [string range $line 0 1]
455 switch -- $op {
456 { } {set tags {}}
457 {@@} {set tags d_@}
458 { +} {set tags d_s+}
459 { -} {set tags d_s-}
460 {+ } {set tags d_+s}
461 {- } {set tags d_-s}
462 {--} {set tags d_--}
463 {++} {
Bert Wesarg45903072010-11-16 10:21:52 +0100464 set regexp [string map [list %conflict_size $conflict_size]\
465 {^\+\+([<>=]){%conflict_size}(?: |$)}]
466 if {[regexp $regexp $line _g op]} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400467 set is_conflict_diff 1
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400468 set line [string replace $line 0 1 { }]
469 set tags d$op
470 } else {
471 set tags d_++
472 }
473 }
474 default {
475 puts "error: Unhandled 3 way diff marker: {$op}"
476 set tags {}
477 }
478 }
Jens Lehmann246295b2009-07-21 19:32:31 +0200479 } elseif {$is_submodule_diff} {
480 if {$line == ""} continue
Jens Lehmanna9ae14a2010-01-23 23:04:12 +0100481 if {[regexp {^Submodule } $line]} {
Bert Wesarg88b21c22010-12-06 22:01:01 +0000482 set tags d_info
Jens Lehmanna9ae14a2010-01-23 23:04:12 +0100483 } elseif {[regexp {^\* } $line]} {
Jens Lehmann246295b2009-07-21 19:32:31 +0200484 set line [string replace $line 0 1 {Submodule }]
Bert Wesarg88b21c22010-12-06 22:01:01 +0000485 set tags d_info
Jens Lehmann246295b2009-07-21 19:32:31 +0200486 } else {
487 set op [string range $line 0 2]
488 switch -- $op {
489 { <} {set tags d_-}
490 { >} {set tags d_+}
491 { W} {set tags {}}
492 default {
493 puts "error: Unhandled submodule diff marker: {$op}"
494 set tags {}
495 }
496 }
497 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400498 } else {
499 set op [string index $line 0]
500 switch -- $op {
501 { } {set tags {}}
502 {@} {set tags d_@}
503 {-} {set tags d_-}
504 {+} {
Bert Wesarg45903072010-11-16 10:21:52 +0100505 set regexp [string map [list %conflict_size $conflict_size]\
506 {^\+([<>=]){%conflict_size}(?: |$)}]
507 if {[regexp $regexp $line _g op]} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400508 set is_conflict_diff 1
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400509 set tags d$op
510 } else {
511 set tags d_+
512 }
513 }
514 default {
515 puts "error: Unhandled 2 way diff marker: {$op}"
516 set tags {}
517 }
518 }
519 }
Pat Thoyts8f855992010-10-22 16:14:38 +0100520 set mark [$ui_diff index "end - 1 line linestart"]
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400521 $ui_diff insert end $line $tags
522 if {[string index $line end] eq "\r"} {
523 $ui_diff tag add d_cr {end - 2c}
524 }
525 $ui_diff insert end "\n" $tags
Pat Thoyts8f855992010-10-22 16:14:38 +0100526
527 foreach {posbegin colbegin posend colend} $markup {
528 set prefix clr
Pat Thoyts3f2fb172010-11-19 22:22:20 +0000529 foreach style [lsort -integer [split $colbegin ";"]] {
Pat Thoyts8f855992010-10-22 16:14:38 +0100530 if {$style eq "7"} {append prefix i; continue}
Pat Thoyts9af64132010-11-19 10:00:49 +0000531 if {$style != 4 && ($style < 30 || $style > 47)} {continue}
Pat Thoyts8f855992010-10-22 16:14:38 +0100532 set a "$mark linestart + $posbegin chars"
533 set b "$mark linestart + $posend chars"
534 catch {$ui_diff tag add $prefix$style $a $b}
535 }
536 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400537 }
538 $ui_diff conf -state disabled
539
540 if {[eof $fd]} {
541 close $fd
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400542
543 if {$current_diff_queue ne {}} {
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400544 advance_diff_queue $cont_info
Alexander Gavrilovb2ca4142008-08-31 01:05:22 +0400545 return
546 }
547
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400548 set diff_active 0
549 unlock_index
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400550 set scroll_pos [lindex $cont_info 0]
Alexander Gavrilov25b8fb12008-07-27 10:35:38 +0400551 if {$scroll_pos ne {}} {
552 update
553 $ui_diff yview moveto $scroll_pos
554 }
Shawn O. Pearce699d5602007-07-05 23:16:13 -0400555 ui_ready
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400556
557 if {[$ui_diff index end] eq {2.0}} {
558 handle_empty_diff
Alexander Gavrilov584fa9c2009-02-07 19:24:01 +0300559 } else {
560 set diff_empty_count 0
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400561 }
Alexander Gavrilov584fa9c2009-02-07 19:24:01 +0300562
Alexander Gavrilov3e348382008-09-20 12:19:18 +0400563 set callback [lindex $cont_info 1]
564 if {$callback ne {}} {
565 eval $callback
566 }
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400567 }
568}
569
Pratyush Yadav62bd9992019-08-18 00:01:43 +0530570proc apply_or_revert_hunk {x y revert} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400571 global current_diff_path current_diff_header current_diff_side
Pratyush Yadava4fa2f02019-08-26 01:43:23 +0530572 global ui_diff ui_index file_states last_revert last_revert_enc
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400573
574 if {$current_diff_path eq {} || $current_diff_header eq {}} return
575 if {![lock_index apply_hunk]} return
576
Pratyush Yadav62bd9992019-08-18 00:01:43 +0530577 set apply_cmd {apply --whitespace=nowarn}
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400578 set mi [lindex $file_states($current_diff_path) 0]
579 if {$current_diff_side eq $ui_index} {
Christian Stimming1ac17952007-07-21 14:21:34 +0200580 set failed_msg [mc "Failed to unstage selected hunk."]
Pratyush Yadav62bd9992019-08-18 00:01:43 +0530581 lappend apply_cmd --reverse --cached
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400582 if {[string index $mi 0] ne {M}} {
583 unlock_index
584 return
585 }
586 } else {
Pratyush Yadav62bd9992019-08-18 00:01:43 +0530587 if {$revert} {
588 set failed_msg [mc "Failed to revert selected hunk."]
589 lappend apply_cmd --reverse
590 } else {
591 set failed_msg [mc "Failed to stage selected hunk."]
592 lappend apply_cmd --cached
593 }
594
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400595 if {[string index $mi 1] ne {M}} {
596 unlock_index
597 return
598 }
599 }
600
601 set s_lno [lindex [split [$ui_diff index @$x,$y] .] 0]
602 set s_lno [$ui_diff search -backwards -regexp ^@@ $s_lno.0 0.0]
603 if {$s_lno eq {}} {
604 unlock_index
605 return
606 }
607
608 set e_lno [$ui_diff search -forwards -regexp ^@@ "$s_lno + 1 lines" end]
609 if {$e_lno eq {}} {
610 set e_lno end
611 }
612
Pratyush Yadava4fa2f02019-08-26 01:43:23 +0530613 set wholepatch "$current_diff_header[$ui_diff get $s_lno $e_lno]"
614
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400615 if {[catch {
Alexander Gavrilov72e6b002008-09-18 01:07:32 +0400616 set enc [get_path_encoding $current_diff_path]
Shawn O. Pearce0b812612007-07-09 01:17:09 -0400617 set p [eval git_write $apply_cmd]
Alexander Gavrilov72e6b002008-09-18 01:07:32 +0400618 fconfigure $p -translation binary -encoding $enc
Pratyush Yadava4fa2f02019-08-26 01:43:23 +0530619 puts -nonewline $p $wholepatch
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400620 close $p} err]} {
Vasco Almeidaa3d97af2016-05-08 10:52:57 +0000621 error_popup "$failed_msg\n\n$err"
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400622 unlock_index
623 return
624 }
625
Pratyush Yadava4fa2f02019-08-26 01:43:23 +0530626 if {$revert} {
627 # Save a copy of this patch for undoing reverts.
628 set last_revert $wholepatch
629 set last_revert_enc $enc
630 }
631
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400632 $ui_diff conf -state normal
633 $ui_diff delete $s_lno $e_lno
634 $ui_diff conf -state disabled
635
Pratyush Yadav62bd9992019-08-18 00:01:43 +0530636 # Check if the hunk was the last one in the file.
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400637 if {[$ui_diff get 1.0 end] eq "\n"} {
638 set o _
639 } else {
640 set o ?
641 }
642
Pratyush Yadav62bd9992019-08-18 00:01:43 +0530643 # Update the status flags.
644 if {$revert} {
645 set mi [string index $mi 0]$o
646 } elseif {$current_diff_side eq $ui_index} {
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400647 set mi ${o}M
648 } elseif {[string index $mi 0] eq {_}} {
649 set mi M$o
650 } else {
651 set mi ?$o
652 }
653 unlock_index
654 display_file $current_diff_path $mi
Alexander Gavrilov29853b92008-08-31 01:02:56 +0400655 # This should trigger shift to the next changed file
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400656 if {$o eq {_}} {
Alexander Gavrilov29853b92008-08-31 01:02:56 +0400657 reshow_diff
Shawn O. Pearcef522c9b2007-05-07 23:35:48 -0400658 }
659}
Johannes Sixt58219882008-06-27 09:22:01 +0200660
Pratyush Yadav5f0a5162019-08-26 01:35:27 +0530661proc apply_or_revert_range_or_line {x y revert} {
Johannes Sixt58219882008-06-27 09:22:01 +0200662 global current_diff_path current_diff_header current_diff_side
Pratyush Yadava4fa2f02019-08-26 01:43:23 +0530663 global ui_diff ui_index file_states last_revert
Johannes Sixt58219882008-06-27 09:22:01 +0200664
Jeff Eplerff07c3b2009-12-07 18:22:43 -0600665 set selected [$ui_diff tag nextrange sel 0.0]
666
667 if {$selected == {}} {
668 set first [$ui_diff index "@$x,$y"]
669 set last $first
670 } else {
671 set first [lindex $selected 0]
672 set last [lindex $selected 1]
673 }
674
675 set first_l [$ui_diff index "$first linestart"]
676 set last_l [$ui_diff index "$last lineend"]
677
Johannes Sixt58219882008-06-27 09:22:01 +0200678 if {$current_diff_path eq {} || $current_diff_header eq {}} return
679 if {![lock_index apply_hunk]} return
680
Pratyush Yadav5f0a5162019-08-26 01:35:27 +0530681 set apply_cmd {apply --whitespace=nowarn}
Johannes Sixt58219882008-06-27 09:22:01 +0200682 set mi [lindex $file_states($current_diff_path) 0]
683 if {$current_diff_side eq $ui_index} {
684 set failed_msg [mc "Failed to unstage selected line."]
685 set to_context {+}
Pratyush Yadav5f0a5162019-08-26 01:35:27 +0530686 lappend apply_cmd --reverse --cached
Johannes Sixt58219882008-06-27 09:22:01 +0200687 if {[string index $mi 0] ne {M}} {
688 unlock_index
689 return
690 }
691 } else {
Pratyush Yadav5f0a5162019-08-26 01:35:27 +0530692 if {$revert} {
693 set failed_msg [mc "Failed to revert selected line."]
694 set to_context {+}
695 lappend apply_cmd --reverse
696 } else {
697 set failed_msg [mc "Failed to stage selected line."]
698 set to_context {-}
699 lappend apply_cmd --cached
700 }
701
Johannes Sixt58219882008-06-27 09:22:01 +0200702 if {[string index $mi 1] ne {M}} {
703 unlock_index
704 return
705 }
706 }
707
Jeff Eplerff07c3b2009-12-07 18:22:43 -0600708 set wholepatch {}
Johannes Sixt58219882008-06-27 09:22:01 +0200709
Jeff Eplerff07c3b2009-12-07 18:22:43 -0600710 while {$first_l < $last_l} {
711 set i_l [$ui_diff search -backwards -regexp ^@@ $first_l 0.0]
712 if {$i_l eq {}} {
713 # If there's not a @@ above, then the selected range
714 # must have come before the first_l @@
715 set i_l [$ui_diff search -regexp ^@@ $first_l $last_l]
Johannes Sixt58219882008-06-27 09:22:01 +0200716 }
Jeff Eplerff07c3b2009-12-07 18:22:43 -0600717 if {$i_l eq {}} {
718 unlock_index
719 return
720 }
721 # $i_l is now at the beginning of a line
722
723 # pick start line number from hunk header
724 set hh [$ui_diff get $i_l "$i_l + 1 lines"]
725 set hh [lindex [split $hh ,] 0]
726 set hln [lindex [split $hh -] 1]
727
728 # There is a special situation to take care of. Consider this
729 # hunk:
730 #
731 # @@ -10,4 +10,4 @@
732 # context before
733 # -old 1
734 # -old 2
735 # +new 1
736 # +new 2
737 # context after
738 #
739 # We used to keep the context lines in the order they appear in
740 # the hunk. But then it is not possible to correctly stage only
741 # "-old 1" and "+new 1" - it would result in this staged text:
742 #
743 # context before
744 # old 2
745 # new 1
746 # context after
747 #
748 # (By symmetry it is not possible to *un*stage "old 2" and "new
749 # 2".)
750 #
751 # We resolve the problem by introducing an asymmetry, namely,
752 # when a "+" line is *staged*, it is moved in front of the
753 # context lines that are generated from the "-" lines that are
754 # immediately before the "+" block. That is, we construct this
755 # patch:
756 #
757 # @@ -10,4 +10,5 @@
758 # context before
759 # +new 1
760 # old 1
761 # old 2
762 # context after
763 #
764 # But we do *not* treat "-" lines that are *un*staged in a
765 # special way.
766 #
767 # With this asymmetry it is possible to stage the change "old
768 # 1" -> "new 1" directly, and to stage the change "old 2" ->
769 # "new 2" by first staging the entire hunk and then unstaging
770 # the change "old 1" -> "new 1".
771 #
772 # Applying multiple lines adds complexity to the special
773 # situation. The pre_context must be moved after the entire
774 # first block of consecutive staged "+" lines, so that
775 # staging both additions gives the following patch:
776 #
777 # @@ -10,4 +10,6 @@
778 # context before
779 # +new 1
780 # +new 2
781 # old 1
782 # old 2
783 # context after
784
785 # This is non-empty if and only if we are _staging_ changes;
786 # then it accumulates the consecutive "-" lines (after
787 # converting them to context lines) in order to be moved after
788 # "+" change lines.
789 set pre_context {}
790
791 set n 0
792 set m 0
793 set i_l [$ui_diff index "$i_l + 1 lines"]
794 set patch {}
795 while {[$ui_diff compare $i_l < "end - 1 chars"] &&
796 [$ui_diff get $i_l "$i_l + 2 chars"] ne {@@}} {
797 set next_l [$ui_diff index "$i_l + 1 lines"]
798 set c1 [$ui_diff get $i_l]
799 if {[$ui_diff compare $first_l <= $i_l] &&
800 [$ui_diff compare $i_l < $last_l] &&
801 ($c1 eq {-} || $c1 eq {+})} {
802 # a line to stage/unstage
803 set ln [$ui_diff get $i_l $next_l]
804 if {$c1 eq {-}} {
805 set n [expr $n+1]
806 set patch "$patch$pre_context$ln"
807 set pre_context {}
808 } else {
809 set m [expr $m+1]
810 set patch "$patch$ln"
811 }
812 } elseif {$c1 ne {-} && $c1 ne {+}} {
813 # context line
814 set ln [$ui_diff get $i_l $next_l]
815 set patch "$patch$pre_context$ln"
Heiko Voigt1fcd24d2013-05-09 18:30:02 +0200816 # Skip the "\ No newline at end of
817 # file". Depending on the locale setting
818 # we don't know what this line looks
819 # like exactly. The only thing we do
820 # know is that it starts with "\ "
821 if {![string match {\\ *} $ln]} {
822 set n [expr $n+1]
823 set m [expr $m+1]
824 }
Jeff Eplerff07c3b2009-12-07 18:22:43 -0600825 set pre_context {}
826 } elseif {$c1 eq $to_context} {
827 # turn change line into context line
828 set ln [$ui_diff get "$i_l + 1 chars" $next_l]
829 if {$c1 eq {-}} {
830 set pre_context "$pre_context $ln"
831 } else {
832 set patch "$patch $ln"
833 }
834 set n [expr $n+1]
835 set m [expr $m+1]
836 } else {
837 # a change in the opposite direction of
838 # to_context which is outside the range of
839 # lines to apply.
840 set patch "$patch$pre_context"
841 set pre_context {}
842 }
843 set i_l $next_l
844 }
845 set patch "$patch$pre_context"
846 set wholepatch "$wholepatch@@ -$hln,$n +$hln,$m @@\n$patch"
847 set first_l [$ui_diff index "$next_l + 1 lines"]
Johannes Sixt58219882008-06-27 09:22:01 +0200848 }
Johannes Sixt58219882008-06-27 09:22:01 +0200849
850 if {[catch {
Alexander Gavrilov72e6b002008-09-18 01:07:32 +0400851 set enc [get_path_encoding $current_diff_path]
Johannes Sixt58219882008-06-27 09:22:01 +0200852 set p [eval git_write $apply_cmd]
Alexander Gavrilov72e6b002008-09-18 01:07:32 +0400853 fconfigure $p -translation binary -encoding $enc
Johannes Sixt58219882008-06-27 09:22:01 +0200854 puts -nonewline $p $current_diff_header
Jeff Eplerff07c3b2009-12-07 18:22:43 -0600855 puts -nonewline $p $wholepatch
Johannes Sixt58219882008-06-27 09:22:01 +0200856 close $p} err]} {
Vasco Almeidaa3d97af2016-05-08 10:52:57 +0000857 error_popup "$failed_msg\n\n$err"
Pratyush Yadav2ccdfb12019-08-26 04:23:13 +0530858 unlock_index
859 return
Johannes Sixt58219882008-06-27 09:22:01 +0200860 }
861
Pratyush Yadava4fa2f02019-08-26 01:43:23 +0530862 if {$revert} {
863 # Save a copy of this patch for undoing reverts.
864 set last_revert $current_diff_header$wholepatch
865 set last_revert_enc $enc
866 }
867
868 unlock_index
869}
870
871# Undo the last line/hunk reverted. When hunks and lines are reverted, a copy
872# of the diff applied is saved. Re-apply that diff to undo the revert.
873#
874# Right now, we only use a single variable to hold the copy, and not a
875# stack/deque for simplicity, so multiple undos are not possible. Maybe this
876# can be added if the need for something like this is felt in the future.
877proc undo_last_revert {} {
878 global last_revert current_diff_path current_diff_header
879 global last_revert_enc
880
881 if {$last_revert eq {}} return
882 if {![lock_index apply_hunk]} return
883
884 set apply_cmd {apply --whitespace=nowarn}
885 set failed_msg [mc "Failed to undo last revert."]
886
887 if {[catch {
888 set enc $last_revert_enc
889 set p [eval git_write $apply_cmd]
890 fconfigure $p -translation binary -encoding $enc
891 puts -nonewline $p $last_revert
892 close $p} err]} {
893 error_popup "$failed_msg\n\n$err"
894 unlock_index
895 return
896 }
897
898 set last_revert {}
899
Johannes Sixt58219882008-06-27 09:22:01 +0200900 unlock_index
901}