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
|
(refdb-set-value dbname "timeline" uuid key (any->string (get-val rec key))))
'("user" "comment"))
(refdb-set-value dbname "extra" uuid "parents" (string-intersperse (get-val rec "parents") ","))
(refdb-set-value dbname "timeline" uuid "timestamp" (seconds->std-time-str (get-val rec "timestamp")))
(refdb-set-value dbname "timeline" uuid "timestamp_sec" (any->string (get-val rec "timestamp")))
))))
timeline))))
(define help
"fossilrebase - register commits in a refdb, edit them by hand then execute them
WARNING: It is highly recommended you do this on a disconnected copy of your fossil database!!
Usage: fossilrebase cmd [params ...]
where cmd is one of:
genrefdb fname b1,b2... : generate a refdb of all the commits for branches matching patterns listed, edit with \"refdb edit fname\"
dumpcmds fname : from refdb fname dump fossil commands to implement the rebase you want to do.
")
(define (main)
(if (< (length (command-line-arguments)) 1)
(begin
(print help)
(exit 1))
(match (command-line-arguments)
(("genrefdb" fname branches) (gen-refdb fname branches))
(("dumpcmds" fname) (dump-cmds))
(else
(print "Sorry, didn't know what to do with \"" (string-intersperse (command-line-arguments) " ") "\"")
(exit 1)))))
(main)
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
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
|
(refdb-set-value dbname "timeline" uuid key (any->string (get-val rec key))))
'("user" "comment"))
(refdb-set-value dbname "extra" uuid "parents" (string-intersperse (get-val rec "parents") ","))
(refdb-set-value dbname "timeline" uuid "timestamp" (seconds->std-time-str (get-val rec "timestamp")))
(refdb-set-value dbname "timeline" uuid "timestamp_sec" (any->string (get-val rec "timestamp")))
))))
timeline))))
;; tag0 tag1 tag2 cherrypick backout hide usedate recomment user
;; comment timestamp timestamp_sec
;;
(define (get-node-details db node-id)
(let* ((result #f)
(count 0))
(for-each-row
(lambda (rowkey tag0 cherrypick do-commit backout hide usedate recomment user comment timestamp timestamp_sec)
(set! result `((uuid . ,rowkey)
(tag0 . ,tag0)
(cherrypick . ,cherrypick)
(do-commit . ,do-commit)
(backout . ,backout)
(hide . ,hide)
(usedate . ,usedate)
(recomment . ,recomment)
(user . ,user)
(comment . ,comment)
(timestamp . ,timestamp)
(timestamp_sec . ,timestamp_sec)))
(set! count (+ count 1)))
db
"SELECT rowkey,tag0,cherrypick,do_commit,backout,hide,usedate,recomment,user,comment,timestamp,timestamp_sec FROM timeline WHERE rowkey LIKE ?;"
node-id)
(if (> count 1)
(print "WARNING: more than one node matches " node-id ", found " count " nodes"))
result))
;; get branches to create
;;
(define (get-new-branches db)
(let* ((res '()))
(for-each-row
(lambda (rowkey node mode)
(set! res (cons `((branch . ,rowkey)
(node . ,node)
(mode . ,mode))
res)))
db
"SELECT rowkey,node,mode FROM branches;")
res))
;; get cherrypicks
;;
(define (get-cherry-picks db)
(let* ((res '()))
(for-each-row
(lambda (rowkey tag0 cherrypick do-commit usedate comment recomment)
(set! res (cons `((uuid . ,rowkey)
(tag0 . ,tag0)
(cherrypick . ,cherrypick)
(do-commit . ,do-commit)
(usedate . ,usedate)
(comment . ,comment)
(recomment . ,recomment))
res)))
db
"SELECT rowkey,tag0,cherrypick,do_commit,usedate,comment,recomment FROM timeline WHERE cherrypick != '' AND cherrypick NOT NULL;")
res))
;; always private and same time as parent node + 1 second
;;
;; fossil branch new BRANCH-NAME BASIS ?OPTIONS?
;;
;; Create a new branch BRANCH-NAME off of check-in BASIS.
;; Supported options for this subcommand include:
;; --private branch is private (i.e., remains local)
;; --bgcolor COLOR use COLOR instead of automatic background
;; --nosign do not sign contents on this branch
;; --date-override DATE DATE to use instead of 'now'
;; --user-override USER USER to use instead of the current default
;;
;; DATE may be "now" or "YYYY-MM-DDTHH:MM:SS.SSS". If in
;; year-month-day form, it may be truncated, the "T" may be
;; replaced by a space, and it may also name a timezone offset
;; from UTC as "-HH:MM" (westward) or "+HH:MM" (eastward).
;; Either no timezone suffix or "Z" means UTC.
;;
(define (create-branch db branch-name parent-node)
(let* ((parent-info (get-node-details db (conc parent-node "%"))))
(if (not parent-info)
(print "ERROR: no info found for node " parent-node)
(let* ((parent-date (alist-ref 'timestamp parent-info))
(parent-user (alist-ref 'user parent-info)))
(print "fossil branch new " branch-name " " parent-node " --private --date-override '" parent-date "'")
;; (print "Creating private branch " branch-name " from node " parent-node)
;; (pp parent-info)
;; (print "")
))))
(define (do-cherrypick db cherrypick)
(let* ((tag0 (alist-ref 'tag0 cherrypick))
(uuid (alist-ref 'uuid cherrypick))
(nodeinf (get-node-details db uuid))
(nodedate (alist-ref 'timestamp nodeinf))
(user (alist-ref 'user nodeinf))
(targ (alist-ref 'cherrypick cherrypick)) ;; do fossil up to this node
(do-commit (alist-ref 'do-commit cherrypick)) ;; if yes do a commit
(usedate (alist-ref 'usedate cherrypick)) ;; if no use current time
(comment (alist-ref 'comment cherrypick))
(recomment (alist-ref 'recomment cherrypick)))
(print "fossil up " targ)
(print "fossil merge --cherrypick " uuid)
(if (member do-commit '("x" "yes"))
(print "fossil commit -m '" comment "' "
(if (equal? usedate "no")
""
(conc " --date-override '" nodedate "'"))
" --user-override " user
" --private"))))
;;
(define (gen-rebase-commands dbname)
(let* ((sqldbname (conc dbname ".db")))
(print "Create sqlite db " sqldbname "...")
(system (conc "refdb dump2sqlite3 " dbname " " sqldbname))
(let* ((db (open-database sqldbname))
(branches (get-new-branches db))
(cherrypicks (get-cherry-picks db)))
;; create the branches
(for-each
(lambda (branchdat)
(create-branch db
(alist-ref 'branch branchdat)
(alist-ref 'node branchdat)))
branches)
;; create the cherrypicks
(for-each
(lambda (cherrypick)
(do-cherrypick db cherrypick))
cherrypicks)
)))
(define help
"fossilrebase - register commits in a refdb, edit them by hand then execute them
WARNING: It is highly recommended you do this on a disconnected copy of your fossil database!!
Usage: fossilrebase cmd [params ...]
where cmd is one of:
genrefdb fname b1,b2... : generate a refdb of all the commits for branches matching patterns listed, edit with \"refdb edit fname\"
dumpcmds fname : from refdb fname dump fossil commands to implement the rebase you want to do.
")
(define (main)
(if (< (length (command-line-arguments)) 1)
(begin
(print help)
(exit 1))
(match (command-line-arguments)
(("genrefdb" fname branches) (gen-refdb fname branches))
(("dumpcmds" fname) (gen-rebase-commands fname))
(else
(print "Sorry, didn't know what to do with \"" (string-intersperse (command-line-arguments) " ") "\"")
(exit 1)))))
(main)
|