-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph_commands.ml
470 lines (466 loc) · 15.1 KB
/
graph_commands.ml
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
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
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
open Jj_tui.Logging
module Make (Vars : Global_vars.Vars) = struct
open Lwd_infix
open Vars
open Notty
open Jj_tui
open Nottui
open! Jj_tui.Util
open Jj_commands.Shared
open Jj_commands.Make (Vars)
open Jj_widgets.Make (Vars)
module Process = Jj_process.Make (Vars)
open Process
open Jj_tui.Process_wrappers.Make (Process)
(* Helper functions from graph_view *)
let bookmark_select_prompt get_bookmark_list name func =
Selection_prompt
( name
, (fun () -> get_bookmark_list () |> Lwd.pure)
, (fun x bookmark_name -> bookmark_name |> Base.String.is_substring ~substring:x)
, func )
;;
let custom_commit ?(edit = true) msg =
let rev = Vars.get_hovered_rev () in
jj [ "describe"; "-r"; rev; "-m"; msg ] |> ignore;
(jj @@ [ "new"; "--insert-after"; rev ] @ if edit then [] else [ "--no-edit" ])
|> ignore
;;
(* Define all graph commands *)
let get_command_registry get_commands =
[
{
id = "show_help"
; description = "Show help"
; sorting_key = 0.0
; make_cmd =
(fun () ->
Fun
(fun _ ->
show_popup
@@ Some (commands_list_ui ~include_arrows:true (get_commands ()), "Help");
ui_state.input $= `Mode (fun _ -> `Unhandled)))
}
; {
id = "prev"
; sorting_key = 1.0
; description = "Move the working copy to the previous child"
; make_cmd = (fun () -> Cmd [ "prev" ])
}
; {
id = "new_base"
; sorting_key = 2.0
; description = "Make new child commit"
; make_cmd = (fun () -> Cmd_with_revs (Active [ "new" ]))
}
; {
id = "new_no_edit"
; sorting_key = 3.0
; description = "Same as 'new', but without editing the new commit"
; make_cmd = (fun () -> Cmd_with_revs (Active [ "new"; "--no-edit" ]))
}
; {
id = "new_inline"
; sorting_key = 4.0
; description = "Make a new change and insert it after the selected rev"
; make_cmd =
(fun () ->
Dynamic
(fun () -> Cmd ([ "new"; "--insert-after" ] @ Vars.get_active_revs ())))
}
; {
id = "new_inline_no_edit"
; sorting_key = 5.0
; description = "Same as 'new insert', but without editing the new commit"
; make_cmd =
(fun () ->
Dynamic
(fun () ->
Cmd ([ "new"; "--no-edit"; "--insert-after" ] @ Vars.get_active_revs ())))
}
; {
id = "new_before"
; sorting_key = 6.0
; description = "Make a new change and insert it before the selected rev"
; make_cmd =
(fun () ->
Dynamic
(fun () -> Cmd ([ "new"; "--insert-before" ] @ Vars.get_active_revs ())))
}
; {
id = "new_before_no_edit"
; sorting_key = 7.0
; description = "Same as 'new insert', but without editing the new commit"
; make_cmd =
(fun () ->
Dynamic
(fun () ->
Cmd ([ "new"; "--no-edit"; "--insert-before" ] @ Vars.get_active_revs ())))
}
; {
id = "duplicate"
; sorting_key = 6.0
; description = "Duplicate the current selected commits "
; make_cmd =
(fun () -> Dynamic (fun () -> Cmd ([ "duplicate" ] @ Vars.get_active_revs ())))
}
; {
id = "undo"
; sorting_key = 7.0
; description = "Undo the last operation"
; make_cmd = (fun () -> Cmd [ "undo" ])
}
; {
id = "commit_base"
; sorting_key = 8.0
; description =
"Describe this change and start working on a new rev (same as `describe` then \
`new`)"
; make_cmd =
(fun () ->
PromptThen ("commit msg", fun msg -> Fun (fun () -> custom_commit msg)))
}
; {
id = "commit_no_edit"
; sorting_key = 9.0
; description = "Same as commit but without editing the new commit"
; make_cmd =
(fun () ->
PromptThen
("commit msg", fun msg -> Fun (fun () -> custom_commit ~edit:false msg)))
}
; {
id = "split"
; sorting_key = 10.0
; description = "Split the current commit interacively"
; make_cmd = (fun () -> Dynamic_r (fun rev -> Cmd_I [ "split"; "-r"; rev; "-i" ]))
}
; {
id = "squash_into_parent"
; sorting_key = 11.0
; description = "Squash into parent"
; make_cmd =
(fun () ->
Fun
(fun _ ->
let rev = Vars.get_hovered_rev () in
let source_msg, dest_msg = get_messages rev (rev ^ "-") in
let new_msg = [ dest_msg; source_msg ] |> String.concat_non_empty "\n" in
jj [ "squash"; "--quiet"; "-r"; rev; "-m"; new_msg ] |> ignore))
}
; {
id = "squash_into_rev"
; sorting_key = 12.0
; description = "Squash into any commit"
; make_cmd =
(fun () ->
PromptThen
( "target revision"
, fun target ->
Dynamic_r
(fun rev ->
let src_msg, dest_msg = get_messages rev target in
let new_msg =
[ dest_msg; src_msg ] |> String.concat_non_empty "\n"
in
Cmd
[
"squash"
; "--quiet"
; "-m"
; new_msg
; "--from"
; rev
; "--into"
; target
]) ))
}
; {
id = "squash_unsquash"
; sorting_key = 13.0
; description = "Interactivaly unsquash"
; make_cmd =
(fun () -> Dynamic_r (fun rev -> Cmd_I [ "unsquash"; "-r"; rev; "-i" ]))
}
; {
id = "squash_interactive_parent"
; sorting_key = 14.0
; description = "Interactively choose what to squash into parent"
; make_cmd = (fun () -> Dynamic_r (fun rev -> Cmd_I [ "squash"; "-r"; rev; "-i" ]))
}
; {
id = "squash_interactive_rev"
; sorting_key = 15.0
; description = "Interactively choose what to squash into a commit"
; make_cmd =
(fun () ->
Dynamic_r
(fun rev ->
Prompt_I ("target revision", [ "squash"; "-i"; "--from"; rev; "--into" ])))
}
; {
id = "edit"
; sorting_key = 16.0
; description = "Edit the selected revision"
; make_cmd = (fun () -> Dynamic_r (fun rev -> Cmd [ "edit"; rev ]))
}
; {
id = "describe"
; sorting_key = 17.0
; description = "Describe this revision"
; make_cmd =
(fun () ->
Dynamic_r (fun rev -> Prompt ("description", [ "describe"; "-r"; rev; "-m" ])))
}
; {
id = "describe_editor"
; sorting_key = 18.0
; description = "Describe this revision using an editor"
; make_cmd = (fun () -> Dynamic_r (fun rev -> Cmd_I [ "describe"; "-r"; rev ]))
}
; {
id = "resolve"
; sorting_key = 19.0
; description = "Resolve conflicts at this revision"
; make_cmd = (fun () -> Dynamic_r (fun rev -> Cmd_I [ "resolve"; "-r"; rev ]))
}
; {
id = "rebase_single"
; sorting_key = 20.0
; description = "Rebase single revision "
; make_cmd =
(fun () ->
Dynamic_r
(fun rev -> Prompt ("Dest rev for " ^ rev, [ "rebase"; "-r"; rev; "-d" ])))
}
; {
id = "rebase_with_descendants"
; sorting_key = 21.0
; description = "Rebase revision and its decendents"
; make_cmd =
(fun () ->
Dynamic_r
(fun rev ->
Prompt
( Printf.sprintf "Dest rev for %s and it's decendents" rev
, [ "rebase"; "-s"; rev; "-d" ] )))
}
; {
id = "rebase_with_bookmark"
; sorting_key = 22.0
; description = "Rebase revision and all other revissions on its bookmark"
; make_cmd =
(fun () ->
Dynamic_r
(fun rev ->
Prompt
("Dest rev for bookmark including " ^ rev, [ "rebase"; "-b"; rev; "-d" ])))
}
; {
id = "git_push"
; sorting_key = 23.0
; description = "git push"
; make_cmd =
(fun () ->
Fun
(fun _ ->
let revs = Vars.get_active_revs () in
let subcmds =
[
{
key = Key.key_of_string_exn "y"
; sort_key = 0.0
; description = "proceed"
; cmd =
Cmd
([ "git"; "push"; "--allow-new" ]
@ (revs |> List.concat_map (fun x -> [ "-r"; x ])))
}
; {
key = Key.key_of_string_exn "n"
; sort_key = 1.0
; description = "exit"
; cmd =
Fun
(fun _ ->
ui_state.input $= `Normal;
show_popup None)
}
]
|> List.map (fun x -> x.key, x)
|> Key_map.Key_Map.of_list
in
let log =
jj_no_log
~get_stderr:true
([ "git"; "push"; "--allow-new"; "--dry-run" ]
@ (revs |> List.concat_map (fun x -> [ "-r"; x ])))
|> AnsiReverse.colored_string
|> Ui.atom
|> Lwd.pure
in
let ui = W.vbox [ log; commands_list_ui subcmds ] in
show_popup @@ Some (ui, "Git push will:");
ui_state.input $= `Mode (command_input ~is_sub:true subcmds)))
}
; {
id = "git_fetch"
; sorting_key = 24.0
; description = "git fetch"
; make_cmd = (fun () -> Cmd [ "git"; "fetch" ])
}
; {
id = "git_fetch_all"
; sorting_key = 25.0
; description = "git fetch all remotes"
; make_cmd = (fun () -> Cmd [ "git"; "fetch"; "--all-remotes" ])
}
; {
id = "parallelize"
; sorting_key = 26.0
; description =
"Parallelize commits. Takes 2 commits and makes them have the\n\
same parent and child. Run `jj parallelize` --help for details"
; make_cmd =
(fun () ->
PromptThen
( "list commits to parallelize"
, fun x -> Cmd ([ "paralellize" ] @ (x |> String.split_on_char ' ')) ))
}
; {
id = "abandon"
; sorting_key = 27.0
; description = "Abandon this change(removes just this change and rebases parents)"
; make_cmd =
(fun () ->
Dynamic
(fun () ->
let revs = Vars.get_active_revs () in
Cmd ([ "abandon" ] @ revs)
|> confirm_prompt
("abandon the revisions:\n" ^ (revs |> String.concat "\n"))))
}
; {
id = "bookmark_create"
; sorting_key = 28.0
; description = "Create new bookmark"
; make_cmd =
(fun () ->
PromptThen
( "Bookmark name to create"
, fun x ->
Cmd_r
([ "bookmark"; "create" ]
@ [ x |> String.map (fun c -> if c = ' ' then '_' else c) ]) ))
}
; {
id = "bookmark_delete"
; sorting_key = 29.0
; description = "Delete bookmark"
; make_cmd =
(fun () ->
bookmark_select_prompt
branches_no_remote
"Bookmark to delete"
(fun bookmark ->
Cmd [ "bookmark"; "delete"; bookmark ]
|> confirm_prompt
(Printf.sprintf
"delete the bookmark: '%s' This will also delete it on the \
remote next \"git push\"."
bookmark)))
}
; {
id = "bookmark_forget"
; sorting_key = 30.0
; description = "Forget bookmark"
; make_cmd =
(fun () ->
bookmark_select_prompt
branches_no_remote
"Bookmark to forget"
(fun bookmark ->
Cmd [ "bookmark"; "forget"; bookmark ]
|> confirm_prompt
(Printf.sprintf
"forget the bookmark: '%s' . This will not delete it on the \
remote."
bookmark)))
}
; {
id = "bookmark_rename"
; sorting_key = 31.0
; description = "Rename bookmark"
; make_cmd =
(fun () ->
bookmark_select_prompt
branches_no_remote
"Select the bookmark to rename (only local/tracked bookmarks are shown)"
(fun curr_name ->
Prompt ("New bookmark name", [ "bookmark"; "rename"; curr_name ])))
}
; {
id = "bookmark_set"
; sorting_key = 32.0
; description = "Set bookmark to this change"
; make_cmd =
(fun () ->
Dynamic_r
(fun rev ->
bookmark_select_prompt
branches_no_remote
("Select the bookmark to set to rev: " ^ rev)
(fun bookmark ->
Cmd [ "bookmark"; "set"; "-r"; get_hovered_rev (); "-B"; bookmark ])))
}
; {
id = "bookmark_track"
; sorting_key = 33.0
; description = "track given remote bookmark"
; make_cmd =
(fun () ->
bookmark_select_prompt
branches_remotes_not_tracked
"Select the bookmark to begin tracking"
(fun bookmark -> Cmd [ "bookmark"; "track"; bookmark ]))
}
; {
id = "bookmark_untrack"
; sorting_key = 34.0
; description = "untrack given remote bookmark"
; make_cmd =
(fun () ->
bookmark_select_prompt
branches_remotes_tracked
"Select the bookmark to untrack"
(fun bookmark -> Cmd [ "bookmark"; "untrack"; bookmark ]))
}
; {
id = "filter"
; sorting_key = 35.0
; description = "Filter using revset"
; make_cmd =
(fun () ->
PromptThen
( "Filter using revset"
, fun revset ->
Fun
(fun () ->
if revset = ""
then Vars.ui_state.revset $= None
else Vars.ui_state.revset $= Some revset) ))
}
; {
id = "absorb"
; sorting_key = 36.0
; description =
"Absorb: Move changes of each file in this commit into the closest mutable \
parent that modified that file"
; make_cmd = (fun () -> Dynamic_r (fun r -> Cmd [ "absorb"; "--from"; r ]))
}
]
|> List.to_seq
|> Seq.map (fun x -> x.id, x)
|> Hashtbl.of_seq
;;
end