~ubuntu-branches/ubuntu/intrepid/git-core/intrepid-security

« back to all changes in this revision

Viewing changes to git-gui/lib/commit.tcl

  • Committer: Package Import Robot
  • Author(s): Gerrit Pape
  • Date: 2007-10-04 08:27:01 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20071004082701-rsd058ontoqz4i30
Tags: 1:1.5.3.4-1
new upstream point release (closes: #445188).

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        set msg {}
26
26
        set parents [list]
27
27
        if {[catch {
28
 
                        set fd [open "| git cat-file commit $curHEAD" r]
 
28
                        set fd [git_read cat-file commit $curHEAD]
29
29
                        fconfigure $fd -encoding binary -translation lf
30
30
                        if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
31
31
                                set enc utf-8
37
37
                                        set enc [string tolower [string range $line 9 end]]
38
38
                                }
39
39
                        }
40
 
                        set msg [encoding convertfrom $enc [read $fd]]
 
40
                        set msg [read $fd]
 
41
                        close $fd
 
42
 
 
43
                        set enc [tcl_encoding $enc]
 
44
                        if {$enc ne {}} {
 
45
                                set msg [encoding convertfrom $enc $msg]
 
46
                        }
41
47
                        set msg [string trim $msg]
42
 
                        close $fd
43
48
                } err]} {
44
49
                error_popup "Error loading commit data for amend:\n\n$err"
45
50
                return
58
63
        $ui_comm insert end $msg
59
64
        $ui_comm edit reset
60
65
        $ui_comm edit modified false
61
 
        rescan {set ui_status_value {Ready.}}
 
66
        rescan ui_ready
62
67
}
63
68
 
64
69
set GIT_COMMITTER_IDENT {}
108
113
        $ui_comm delete 0.0 end
109
114
        $ui_comm edit reset
110
115
        $ui_comm edit modified false
111
 
        rescan {set ui_status_value {Ready.}}
 
116
        rescan ui_ready
112
117
}
113
118
 
114
119
proc commit_tree {} {
115
120
        global HEAD commit_type file_states ui_comm repo_config
116
 
        global ui_status_value pch_error
 
121
        global pch_error
117
122
 
118
123
        if {[committer_ident] eq {}} return
119
124
        if {![lock_index update]} return
132
137
The rescan will be automatically started now.
133
138
}
134
139
                unlock_index
135
 
                rescan {set ui_status_value {Ready.}}
 
140
                rescan ui_ready
136
141
                return
137
142
        }
138
143
 
148
153
                U? {
149
154
                        error_popup "Unmerged files cannot be committed.
150
155
 
151
 
File [short_path $path] has merge conflicts.  You must resolve them and add the file before committing.
 
156
File [short_path $path] has merge conflicts.  You must resolve them and stage the file before committing.
152
157
"
153
158
                        unlock_index
154
159
                        return
164
169
        if {!$files_ready && ![string match *merge $curType]} {
165
170
                info_popup {No changes to commit.
166
171
 
167
 
You must add at least 1 file before you can commit.
 
172
You must stage at least 1 file before you can commit.
168
173
}
169
174
                unlock_index
170
175
                return
206
211
                return
207
212
        }
208
213
 
209
 
        set ui_status_value {Calling pre-commit hook...}
 
214
        ui_status {Calling pre-commit hook...}
210
215
        set pch_error {}
211
216
        set fd_ph [open "| $pchook" r]
212
 
        fconfigure $fd_ph -blocking 0 -translation binary
 
217
        fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
213
218
        fileevent $fd_ph readable \
214
219
                [list commit_prehook_wait $fd_ph $curHEAD $msg]
215
220
}
216
221
 
217
222
proc commit_prehook_wait {fd_ph curHEAD msg} {
218
 
        global pch_error ui_status_value
 
223
        global pch_error
219
224
 
220
225
        append pch_error [read $fd_ph]
221
226
        fconfigure $fd_ph -blocking 1
222
227
        if {[eof $fd_ph]} {
223
228
                if {[catch {close $fd_ph}]} {
224
 
                        set ui_status_value {Commit declined by pre-commit hook.}
 
229
                        ui_status {Commit declined by pre-commit hook.}
225
230
                        hook_failed_popup pre-commit $pch_error
226
231
                        unlock_index
227
232
                } else {
234
239
}
235
240
 
236
241
proc commit_writetree {curHEAD msg} {
237
 
        global ui_status_value
238
 
 
239
 
        set ui_status_value {Committing changes...}
240
 
        set fd_wt [open "| git write-tree" r]
 
242
        ui_status {Committing changes...}
 
243
        set fd_wt [git_read write-tree]
241
244
        fileevent $fd_wt readable \
242
245
                [list commit_committree $fd_wt $curHEAD $msg]
243
246
}
244
247
 
245
248
proc commit_committree {fd_wt curHEAD msg} {
246
249
        global HEAD PARENT MERGE_HEAD commit_type
247
 
        global all_heads current_branch
248
 
        global ui_status_value ui_comm selected_commit_type
 
250
        global current_branch
 
251
        global ui_comm selected_commit_type
249
252
        global file_states selected_paths rescan_active
250
253
        global repo_config
251
254
 
252
255
        gets $fd_wt tree_id
253
256
        if {$tree_id eq {} || [catch {close $fd_wt} err]} {
254
257
                error_popup "write-tree failed:\n\n$err"
255
 
                set ui_status_value {Commit failed.}
 
258
                ui_status {Commit failed.}
256
259
                unlock_index
257
260
                return
258
261
        }
260
263
        # -- Verify this wasn't an empty change.
261
264
        #
262
265
        if {$commit_type eq {normal}} {
263
 
                set fd_ot [open "| git cat-file commit $PARENT" r]
 
266
                set fd_ot [git_read cat-file commit $PARENT]
264
267
                fconfigure $fd_ot -encoding binary -translation lf
265
268
                set old_tree [gets $fd_ot]
266
269
                close $fd_ot
280
283
A rescan will be automatically started now.
281
284
}
282
285
                        unlock_index
283
 
                        rescan {set ui_status_value {No changes to commit.}}
 
286
                        rescan {ui_status {No changes to commit.}}
284
287
                        return
285
288
                }
286
289
        }
289
292
        #
290
293
        set msg_p [gitdir COMMIT_EDITMSG]
291
294
        set msg_wt [open $msg_p w]
 
295
        fconfigure $msg_wt -translation lf
292
296
        if {[catch {set enc $repo_config(i18n.commitencoding)}]} {
293
297
                set enc utf-8
294
298
        }
295
 
        fconfigure $msg_wt -encoding binary -translation binary
296
 
        puts -nonewline $msg_wt [encoding convertto $enc $msg]
 
299
        set use_enc [tcl_encoding $enc]
 
300
        if {$use_enc ne {}} {
 
301
                fconfigure $msg_wt -encoding $use_enc
 
302
        } else {
 
303
                puts stderr "warning: Tcl does not support encoding '$enc'."
 
304
                fconfigure $msg_wt -encoding utf-8
 
305
        }
 
306
        puts -nonewline $msg_wt $msg
297
307
        close $msg_wt
298
308
 
299
309
        # -- Create the commit.
305
315
        lappend cmd <$msg_p
306
316
        if {[catch {set cmt_id [eval git $cmd]} err]} {
307
317
                error_popup "commit-tree failed:\n\n$err"
308
 
                set ui_status_value {Commit failed.}
 
318
                ui_status {Commit failed.}
309
319
                unlock_index
310
320
                return
311
321
        }
327
337
                        git update-ref -m $reflogm HEAD $cmt_id $curHEAD
328
338
                } err]} {
329
339
                error_popup "update-ref failed:\n\n$err"
330
 
                set ui_status_value {Commit failed.}
 
340
                ui_status {Commit failed.}
331
341
                unlock_index
332
342
                return
333
343
        }
342
352
 
343
353
        # -- Let rerere do its thing.
344
354
        #
345
 
        if {[file isdirectory [gitdir rr-cache]]} {
 
355
        if {[get_config rerere.enabled] eq {}} {
 
356
                set rerere [file isdirectory [gitdir rr-cache]]
 
357
        } else {
 
358
                set rerere [is_config_true rerere.enabled]
 
359
        }
 
360
        if {$rerere} {
346
361
                catch {git rerere}
347
362
        }
348
363
 
364
379
        $ui_comm delete 0.0 end
365
380
        $ui_comm edit reset
366
381
        $ui_comm edit modified false
 
382
        if {$::GITGUI_BCK_exists} {
 
383
                catch {file delete [gitdir GITGUI_BCK]}
 
384
                set ::GITGUI_BCK_exists 0
 
385
        }
367
386
 
368
387
        if {[is_enabled singlecommit]} do_quit
369
388
 
370
 
        # -- Make sure our current branch exists.
371
 
        #
372
 
        if {$commit_type eq {initial}} {
373
 
                lappend all_heads $current_branch
374
 
                set all_heads [lsort -unique $all_heads]
375
 
                populate_branch_menu
376
 
        }
377
 
 
378
389
        # -- Update in memory status
379
390
        #
380
391
        set selected_commit_type new
416
427
        display_all_files
417
428
        unlock_index
418
429
        reshow_diff
419
 
        set ui_status_value \
420
 
                "Created commit [string range $cmt_id 0 7]: $subject"
 
430
        ui_status "Created commit [string range $cmt_id 0 7]: $subject"
421
431
}