forked from miketang84/mp-5.x
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mp_vcs.mpsl
198 lines (164 loc) · 5.81 KB
/
mp_vcs.mpsl
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
/*
Minimum Profit - A Text Editor
Version Control System support
Angel Ortega <angel@triptico.com> et al.
This software is released into the public domain.
NO WARRANTY. See file LICENSE for details.
*/
/** mp_doc commit subclass **/
global mp_doc_vcs = new(mp_doc, { name: '.COMMIT_MESSAGE', no_state: 1 });
/** data **/
mp.vcs = {
git: {
id: 'Git',
check: [ '.git', '../.git', '../../.git', '../../../.git' ],
opts: {
"git add '%s'" => NULL,
'git log' => { unique_log: 1 },
"git log '%s'" => { unique_log: 1 },
'git log -p' => { unique_log: 1, diff: 1 },
"git log -p '%s'" => { unique_log: 1, diff: 1 },
'git diff' => { unique_log: 1, diff: 1 },
"git diff '%s'" => { unique_log: 1, diff: 1 },
'git status' => NULL,
"git blame '%s'" => { unique_log: 1 },
"git stash" => NULL,
"git stash apply" => NULL,
"git push" => NULL,
"git pull" => NULL,
"git commit -a" => { commit_cmd: "git commit -a -F '%s'" }
}
},
svn: {
id: 'SVN',
check: [ '.svn', '../.svn', '../../.svn', '../../../.svn' ],
opts: {
'svn diff' => { unique_log: 1, diff: 1 },
'svn status' => NULL,
'svn log' => { unique_log: 1 },
'svn log --diff' => { unique_log: 1, diff: 1 },
"svn diff '%s'" => { unique_log: 1, diff: 1 },
"svn log '%s'" => { unique_log: 1 },
"svn log '%s' --diff" => { unique_log: 1, diff: 1 },
"svn add '%s'" => NULL,
"svn annotate '%s'" => { unique_log: 1 },
"svn update" => NULL,
"svn revert '%s'" => NULL,
"svn commit" => { commit_cmd: "svn commit -F '%s'" }
}
},
mercurial: {
id: 'Mercurial',
check: [ '.hg', '../.hg', '../../.hg' ],
opts: {
'hg diff' => { unique_log: 1, diff: 1 },
'hg status' => NULL,
'hg log' => { unique_log: 1 },
"hg diff '%s'" => { unique_log: 1, diff: 1 },
"hg log '%s'" => { unique_log: 1 },
"hg add '%s'" => NULL,
"hg push" => NULL,
"hg pull" => NULL,
"hg annotate '%s'" => { unique_log: 1 },
"hg commit -A" => { commit_cmd: "hg commit -A -l '%s'" }
}
}
};
sub mp.vcs_form()
{
local vcs = NULL;
/* find which VCS apply to current directory */
foreach (n, mp.vcs) {
foreach (dir, n.check) {
if (stat(dir) != NULL) {
vcs = n;
break;
}
}
if (vcs != NULL)
break;
}
if (vcs == NULL)
mp.alert(L("This directory is not under a supported version control system"));
else {
local opts = vcs.opts->map(sub (v, i) { i; })->sort();
local cmd_list = opts->map(sub (e) {
sprintf(e, regex(mp.active.name, '/[^\/\\]+$/'));
});
local form = mp.form(
[
{
label: sprintf(L("Available %s commands"), vcs.id) + ':',
type: 'list',
list: cmd_list,
value: mp.vcs_target
}
]
);
if (form != NULL) {
mp.vcs_target = form[0];
local opt = vcs.opts[opts[mp.vcs_target]];
local cmd = cmd_list[mp.vcs_target];
if (opt.commit_cmd) {
/* create a commit message editor document */
local msg = new(mp_doc_vcs);
msg.vcs = {
commit_cmd: opt.commit_cmd,
log_name: sprintf(L("<%s output>"), vcs.id)
};
mp.add(msg);
}
else {
local log;
/* unique log for this command? */
if (opt.unique_log) {
log = mp.open(sprintf(L("<%s output>"), cmd));
log.txt.lines = [ '' ];
log.txt.y = 0;
}
else {
/* common log */
log = mp.open(sprintf(L("<%s output>"), vcs.id));
log->move_eof();
log->insert(cmd + ":\n\n");
}
log->actions.exec_command(cmd);
if (opt.unique_log) {
if (opt.diff)
log.syntax = mp.get_syntax("diff");
log->move_bof();
}
else
log->insert_newline();
log.txt.mod = 0;
log.undo_q = [];
log.read_only = 1;
}
}
}
};
/** code **/
sub mp_doc_vcs.query_close(doc)
/* mp_doc.query_close overload for commit messages */
{
local r;
/* call superclass query close */
if ((r = mp_doc.query_close(doc)) == 1) {
/* has the commit message been saved? */
if (stat(doc.name) != NULL) {
local cmd = sprintf(doc.vcs.commit_cmd, doc.name);
local log = mp.open(doc.vcs.log_name);
log->move_eof();
log->insert(cmd + ":\n\n");
log->actions.exec_command(cmd);
log->insert_newline();
log.txt.mod = 0;
log.undo_q = [];
log.read_only = 1;
/* bring doc to active back */
mp.open(doc.name);
}
unlink(doc.name);
}
return r;
}