Merge branch 'master' of git://factorcode.org/git/factor
[factor/jcg.git] / extra / git-tool / remote / remote.factor
blobe5291a84591c74f61ba60b90f4616f5efda8bbd9
2 USING: accessors calendar git-tool git-tool io.directories
3 io.monitors io.pathnames kernel locals math namespaces
4 sequences splitting system threads ui ui.gadgets
5 ui.gadgets.buttons ui.gadgets.labels ui.gadgets.packs ;
7 USING: git-tool ;
9 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
11 IN: git-tool.remote
13 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
15 TUPLE: <git-remote-gadget> < pack
16   repository
17   branch
18   remote
19   remote-branch
20   fetch-period
21   push
22   closed
23   last-refresh ;
25 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
27 : current-branch ( REPO -- branch )
28   { "git" "branch" } git-process stdout>> [ "* " head? ] find nip 2 tail ;
30 : list-branches ( REPO -- branches )
31   { "git" "branch" } git-process stdout>>
32   [ empty? not ] filter
33   [ 2 tail ] map ;
35 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
37 : list-remotes ( REPO -- remotes )
38   { "git" "remote" } git-process stdout>> [ empty? not ] filter ;
40 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
42 :: list-remote-branches ( REPO REMOTE -- branches )
43   [let | OUT [ REPO { "git" "remote" "show" REMOTE } git-process stdout>> ] |
45     "  Tracked remote branches" OUT member?
46       [
47         OUT
48         "  Tracked remote branches" OUT index 1 + tail first " " split
49         [ empty? not ] filter
50       ]
51       [
52         OUT
53         OUT [ "  New remote branches" head? ] find drop
54         1 + tail first " " split
55         [ empty? not ] filter
56       ]
57     if ] ;
59 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
61 :: refresh-git-remote-gadget ( GADGET -- )
63   [let | REPO [ GADGET repository>> ] |
65     GADGET clear-gadget
67     GADGET
69     ! Repository label
71     "Repository: " REPO [ current-directory get ] with-directory append
72     <label>
73     add-gadget
75     ! Branch button
76     
77     <shelf>
79       "Branch: " <label> add-gadget
81       REPO current-branch
82       [
83         drop
84         
85         <pile>
86           REPO list-branches
88           [| BRANCH |
90             BRANCH
91             [
92               drop
93               REPO { "git" "checkout" BRANCH } git-process popup-if-error
94               GADGET refresh-git-remote-gadget
95             ]
96             <bevel-button> add-gadget
98           ]
99           each
101         "Select a branch" open-window
102         
103       ]
104       <bevel-button> add-gadget
106     add-gadget
108     ! Remote button
110     <shelf>
112       "Remote: " <label> add-gadget
114       GADGET remote>>
115       [
116         drop
118         <pile>
120           REPO list-remotes
122           [| REMOTE |
124             REMOTE
125             [
126               drop
127               GADGET REMOTE >>remote drop
128               GADGET "master" >>remote-branch drop
129               GADGET refresh-git-remote-gadget
130             ]
131             <bevel-button> add-gadget
133           ]
134           each
136         "Select a remote" open-window
137         
138       ]
139       <bevel-button> add-gadget
141     add-gadget
143     ! Remote branch button
145     <shelf>
147       "Remote branch: " <label> add-gadget
149       GADGET remote-branch>>
150       [
151         drop
153         <pile>
155           REPO GADGET remote>> list-remote-branches
157           [| REMOTE-BRANCH |
159             REMOTE-BRANCH
160             [
161               drop
162               GADGET REMOTE-BRANCH >>remote-branch drop
163               GADGET refresh-git-remote-gadget
164             ]
165             <bevel-button> add-gadget
166           ]
167         
168           each
170         "Select a remote branch" open-window
172       ]
173       <bevel-button> add-gadget
175     add-gadget
177     ! Fetch button
179     "Fetch"
180     [
181       drop
182       [let | REMOTE [ GADGET remote>> ] |
183         REPO { "git" "fetch" REMOTE } git-process popup-if-error ]
184       
185       GADGET refresh-git-remote-gadget
186     ]
187     <bevel-button> add-gadget
189     ! Available changes
191     [let | REMOTE        [ GADGET remote>>        ]
192            REMOTE-BRANCH [ GADGET remote-branch>> ] |
194       [let | ARG [ { ".." REMOTE "/" REMOTE-BRANCH } concat ] |
196         [let | PROCESS [ REPO { "git" "log" ARG } git-process ] |
198           PROCESS stdout>>
199             [
200               <shelf>
201               
202                 "Changes available:" <label> add-gadget
204                 "View"
205                 [
206                   drop
207                   PROCESS popup-process-window
208                 ]
209                 <bevel-button> add-gadget
211                 "Merge"
212                 [
213                   drop
215                   [let | ARG [ { REMOTE "/" REMOTE-BRANCH } concat ] |
217                     REPO { "git" "merge" ARG } git-process popup-process-window
219                   ]
221                   GADGET refresh-git-remote-gadget
223                 ]
224                 <bevel-button> add-gadget
226               add-gadget
228             ]
229           when
231         ] ] ]
234     ! Pushable changes
236     [let | REMOTE        [ GADGET remote>>        ]
237            REMOTE-BRANCH [ GADGET remote-branch>> ] |
239       [let | ARG [ { REMOTE "/" REMOTE-BRANCH ".." } concat ] |
241         [let | PROCESS [ REPO { "git" "log" ARG } git-process ] |
243           PROCESS stdout>>
244             [
245               <shelf>
246               
247                 "Pushable changes: " <label> add-gadget
249                 "View"
250                 [
251                   drop
252                   PROCESS popup-process-window
253                 ]
254                 <bevel-button> add-gadget
256                 "Push"
257                 [
258                   drop
260                   REPO { "git" "push" REMOTE REMOTE-BRANCH }
261                   git-process
262                   popup-process-window
264                   GADGET refresh-git-remote-gadget
266                 ]
267                 <bevel-button> add-gadget
269               add-gadget
271             ]
272           when
274         ] ] ]
275     
276     drop
278   ] ;
280 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
282 :: start-fetch-thread ( GADGET -- )
284   GADGET f >>closed drop
285   
286   [
288     [
290       GADGET closed>>
291         [ f ]
292         [
293           [let | REPO          [ GADGET repository>> ]
294                  REMOTE-BRANCH [ GADGET remote-branch>> ] |
295             
296             REPO { "git" "fetch" REMOTE-BRANCH } git-process drop ]
298           GADGET fetch-period>> sleep
300           t
301         ]
302       if
303       
305     ]
306     loop
307     
308   ]
309   
310   in-thread ;
312 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
314 :: start-monitor-thread ( GADGET -- )
316   GADGET f >>closed drop
318   [
319     [
320       [let | MONITOR [ GADGET repository>> t <monitor> ] |
322         [
323           GADGET closed>>
324           [ f ]
325           [
326             
327             [let | PATH [ MONITOR next-change drop ] |
329               ".git" PATH subseq?
330                 [ ]
331                 [
332                   micros
333                   GADGET last-refresh>> 0 or -
334                   1000000 >
335                     [
336                       GADGET micros >>last-refresh drop
337                       GADGET refresh-git-remote-gadget
338                     ]
339                   when
340                 ]
341               if ]
343             t
345           ]
346           if
347         ]
348         loop
349       ]
350     ]
351     with-monitors
352   ]
353   in-thread ;
355 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
357 M: <git-remote-gadget> pref-dim* ( gadget -- dim ) drop { 500 500 } ;
359 M:: <git-remote-gadget> graft*   ( GADGET -- )
360   GADGET start-fetch-thread
361   GADGET start-monitor-thread ;
363 M:: <git-remote-gadget> ungraft* ( GADGET -- ) GADGET t >>closed drop ;
365 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
367 :: git-remote-tool ( REPO -- )
369   <git-remote-gadget> new-gadget
370   
371     { 0 1 } >>orientation
372     1       >>fill
374     REPO >>repository
376     "origin" >>remote
378     "master" >>remote-branch
380     5 minutes >>fetch-period
382   dup refresh-git-remote-gadget
384   "git-remote-tool" open-window ;
386 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
388 : factor-git-remote-tool ( -- ) "resource:" git-remote-tool ;
390 ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
392 MAIN: factor-git-remote-tool