unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob afc9c539a7dc41ffacb1004bcc112c471aee7d9a 13429 bytes (raw)
name: gnu/home/services/version-control.scm 	 # note: path name is non-authoritative(*)

  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
 
(define-module (gnu home services version-control)
  #:use-module (srfi srfi-1)
  #:use-module (srfi srfi-9)
  #:use-module (srfi srfi-11)
  #:use-module (srfi srfi-26)
  #:use-module (ice-9 match)
  #:use-module (gnu home services)
  #:use-module (gnu home services utils)
  #:use-module (gnu services configuration)
  #:use-module (gnu packages version-control)
  #:use-module (guix packages)
  #:use-module (guix gexp)
  #:use-module (guix records)
  #:use-module ((guix import utils) #:select (flatten))

  #:export (home-git-configuration
            home-git-extension
            home-git-service-type
            serialize-git-config

            home-hg-configuration
            home-hg-extension
            serialize-hg-config
            home-hg-service-type))

;;; Commentary:
;;;
;;; Version control related services.
;;;
;;; Code:

;;;
;;; Git.
;;;
;;; (service home-git-service-type
;;;      (home-git-configuration
;;;       (attributes
;;;        '((* . text=auto)
;;;          (*.sh . "text eol=lf")))
;;;       (ignore
;;;        '("*.so" "*.o"))
;;;       (ignore-extra-content
;;;        "*.dll\n*.exe\n")
;;;       (config
;;;        `((http "https://weak.example.com"
;;;                ((ssl-verify . #f)))
;;;          (gpg
;;;           ((program . ,(file-append gnupg "/bin/gpg"))))
;;;          (sendmail
;;;           ((annotate . #t))))
;;;        (config-extra-content (slurp-file-gexp
;;;                                (local-file "./gitconfig")))))
;;;
;;; (simple-service
;;;  'add-something-to-git
;;;  home-git-service-type
;;;  (home-git-extension
;;;   (config
;;;     `((sendmail
;;;        ((annotate . #t)))))))


(define (uglify-field-name field-name)
  "Convert symbol FIELD-NAME to a camel case string.
@code{symbol-name} => \"@code{symbolName}\"."
  (let* ((str (symbol->string field-name))
         (spl-str (string-split str #\-)))
    (apply string-append
           (car spl-str)
           (map string-capitalize (cdr spl-str)))))

(define (serialize-field field-name val)
   (cond
    ((boolean? val) (serialize-boolean field-name val))
    (else
     (list (format #f "\t~a = " (uglify-field-name field-name))
           val "\n"))))

(define (serialize-alist field-name val)
  (generic-serialize-alist append serialize-field val))

(define (serialize-boolean field-name val)
  (serialize-field field-name (if val "true" "false")))

(define serialize-string serialize-field)
(define git-config? list?)

(define (serialize-git-section-header name value)
  (format #f "[~a~a]\n" (uglify-field-name name)
          (if value (format #f " \"~a\"" value) "")))

(define serialize-git-section
  (match-lambda
    ((name options)
     (cons
      (serialize-git-section-header name #f)
      (serialize-alist #f options)))
    ((name value options)
     (cons
      (serialize-git-section-header name value)
      (serialize-alist #f options)))))

;; TODO: cover it with tests
(define (serialize-git-config field-name val)
  #~(string-append #$@(append-map serialize-git-section val)))

(define (git-ignore? patterns)
  (list-of-strings? patterns))
(define (serialize-git-ignore field-name val)
  (string-join val "\n" 'suffix))

(define (git-attributes? attrs)
  (list? attrs))
(define (serialize-git-attributes field-name val)
  (string-join
   (map
    (match-lambda
      ((key . value) (format #f "~a\t~a" key value)))
    val)
   "\n"
   'suffix))

(define-configuration home-git-extension
  (attributes
   (git-attributes '())
   "Alist of pattern attribute pairs for @file{git/attributes.}")
  (ignore
   (git-ignore '())
   "List of patterns for @file{git/ignore.}")
  (config
   (git-config '())
   "List of git sections.  The same format as in
@code{home-git-configuration}."))

(define-configuration home-git-configuration
  (package
   (package git)
   "The Git package to use.")
  (attributes
   (git-attributes '())
   "Alist of pattern attribute pairs for @file{git/attributes.}")
  (attributes-extra-content
   (text-config "")
    "String or value of string-valued g-exps will be added to the end
of the @file{git/attributes} file.")
  (ignore
   (git-ignore '())
   "List of patterns for git/ignore.")
  (ignore-extra-content
   (text-config "")
    "String or value of string-valued g-exps will be added to the end
of the git/ignore file.")
  (config
   (git-config '())
   "List of sections and corresponding options.  Something like this:

@lisp
`((sendmail
   ((annotate . #t))))
@end lisp

will turn into this:

@example
[sendmail]
        annotate = true
@end example")
  (config-extra-content
   (text-config "")
   "String or value of string-valued g-exps will be added to the end
of the configuration file."))

(define (add-git-configuration config)
  (define (filter-fields fields)
    (filter-configuration-fields home-git-configuration-fields fields))
  `(("config/git/attributes"
     ,(mixed-text-file
       "git-attributes"
       (serialize-configuration
        config
	(filter-fields '(attributes)))
       (home-git-configuration-attributes-extra-content config)))
    ("config/git/ignore"
     ,(mixed-text-file
       "git-ignore"
       (serialize-configuration
        config
	(filter-fields '(ignore)))
       (home-git-configuration-ignore-extra-content config)))
    ("config/git/config"
     ,(mixed-text-file
	     "git-config"
	     (serialize-configuration
              config
	      (filter-fields '(config)))
	     (home-git-configuration-config-extra-content config)))))

(define (add-git-packages config)
  (list (home-git-configuration-package config)))

(define (home-git-extensions original-config extension-configs)
  (home-git-configuration
   (inherit original-config)
   (attributes
    (append (home-git-configuration-attributes original-config)
	    (append-map
	     home-git-extension-attributes extension-configs)))
   (ignore
    (append (home-git-configuration-ignore original-config)
	    (append-map
	     home-git-extension-ignore extension-configs)))
   (config
    (append (home-git-configuration-config original-config)
	    (append-map
	     home-git-extension-config extension-configs)))))

(define home-git-service-type
  (service-type (name 'home-git)
                (extensions
                 (list (service-extension
                        home-files-service-type
                        add-git-configuration)
                       (service-extension
                        home-profile-service-type
                        add-git-packages)))
		(compose identity)
		(extend home-git-extensions)
                (default-value (home-git-configuration))
                (description "Install and configure Git.")))

(define (generate-home-git-documentation)
  (generate-documentation
   `((home-git-configuration
      ,home-git-configuration-fields))
   'home-git-configuration))

\f
;;;
;;; Mercurial.
;;;
;;; (home-hg-configuration
;;;   (regexp-ignore '("^\\.pc/"))
;;;   (glob-ignore '("*.elc" "*~"))
;;;   (config
;;;    '((commands
;;;       ((commit.post-status . #t)))
;;;      (ui
;;;       ((username . "Alice Bobson <charlie@example.org")))
;;;      (defaults
;;;        (log . "-v")))))
;;;

;; TODO: Add separate field for name and email?
(define-configuration/no-serialization home-hg-configuration
  (package
    (package mercurial)
    "The Mercurial package to use.")
  (regexp-ignore
   (list-of-strings '())
   "List of regular expressions to ignore globally.  The default syntax
is Python/Perl-style regular expression (see @command{man 5 hgignore}).

The @code{*-ignore} fields are equivalent to adding @code{ui.ignore =
/file/with/ignore/rules} in your @file{hgrc}.")
  (glob-ignore
   (list-of-strings '())
   "List of globs to ignore globally.")
  (rootglob-ignore
   (list-of-strings '())
   "List of @dfn{rootglobs} to ignore globally.")
  (config
   (ini-config '())
   "List of list representing the contents of the @file{hgrc}
configuration file.  The syntax is similar to that of the Git service.
The key of a pair can be a symbol or string, and the value can be a
boolean, string, symbol, number, gexp (@pxref{gexp,,,guix.info}), or a
list of one the above.

@lisp
(config
 `((commands
    ((commit.post-status . #t)))
   (graph
    ((width . 4)))
   (hooks
    ((incoming.email . ,(local-file \"/path/to/email/hook\"))))))
@end lisp

will turn into this:

@example
[commands]
    commit.post-status = True
[graph]
    width = 4
[hooks]
  incoming.email = /gnu/store/123...-email-hook
@end example"))

(define (serialize-hg-config config)
  (define (serialize-boolean val)
    (list (if val "True" "False")))

  (define (serialize-list val)
    (interpose (map serialize-val val) ", "))

  (define (serialize-val val)
    (cond
     ((list? val) (serialize-list val))
     ((boolean? val) (serialize-boolean val))
     ((or (number? val) (symbol? val)) (list (maybe-object->string val)))
     (else (list val))))

  (define (serialize-field key val)
    (let ((val (serialize-val val))
          (key (symbol->string key)))
      `(,key " = " ,@val "\n")))

  (flatten (generic-serialize-ini-config
            #:combine-ini interpose
            #:combine-alist list
            #:combine-section-alist cons
            #:serialize-field serialize-field
            #:fields config)))

(define* (serialize-hg-ignores #:key regexp glob rootglob)
  (define (add-ignore lst type)
    (if (not (null? lst))
        (string-append (format #f "syntax: ~a\n" type)
                       (string-join lst "\n" 'suffix))
        ""))

  (string-join (map (cut add-ignore <> <>)
                    (list regexp glob rootglob)
                         '(regexp glob rootglob))
               "\n"))

(define (home-hg-files-service config)
  (define rest cdr)

  (define (compare-sections section1 section2)
    (string<? (symbol->string (first section1))
              (symbol->string (first section2))))

  (define (fold-sections section1 section2)
    (cond
     ((equal? (first section1) (first section2))
      (list (list (first section1)
                  (append (second section1) (second section2)))))
     (else
      (list section1 section2))))

  (define (merge-sections config)
    (let ((sorted-config (sort config compare-sections)))
      (fold (lambda (section acc)
              (if (null? acc)
                  (list section)
                  (append (fold-sections section (first acc))
                          (rest acc))))
            '()
            sorted-config)))

  (let* ((ignores (serialize-hg-ignores
                   #:regexp
                   (home-hg-configuration-regexp-ignore config)
                   #:glob
                   (home-hg-configuration-glob-ignore config)
                   #:rootglob
                   (home-hg-configuration-rootglob-ignore config)))
         (final-config (merge-sections
                        (append (home-hg-configuration-config config)
                                `((ui
                                   ((ignore . ,(plain-file "hg-ignores"
                                                           ignores)))))))))
    `(("config/hg/hgrc"
       ,(apply mixed-text-file
               "hgrc"
               (serialize-hg-config final-config))))))

(define-configuration/no-serialization home-hg-extension
  (regexp-ignore
   (list-of-strings '())
   "List of regular expressions to ignore globally.")
  (glob-ignore
   (list-of-strings '())
   "List of glob expressions to ignore globally.")
  (rootglob-ignore
   (list-of-strings '())
   "List of @dfn{rootglobs} to ignore globally.")
  (config
   (ini-config '())
   "List of lists representing the contents of the @file{hgrc} file."))

(define (home-hg-extensions original-config extension-configs)
  (home-hg-configuration
   (inherit original-config)
   (regexp-ignore
    (append (home-hg-configuration-regexp-ignore original-config)
            (append-map
             home-hg-extension-regexp-ignore extension-configs)))
   (glob-ignore
    (append (home-hg-configuration-glob-ignore original-config)
            (append-map
             home-hg-extension-glob-ignore extension-configs)))
   (rootglob-ignore
    (append (home-hg-configuration-rootglob-ignore original-config)
            (append-map
             home-hg-extension-rootglob-ignore extension-configs)))
   (config
    (append (home-hg-configuration-config original-config)
            (append-map
             home-hg-extension-config extension-configs)))))

(define (home-hg-profile-service config)
  (list (home-hg-configuration-package config)))

(define home-hg-service-type
  (service-type (name 'home-hg)
                (extensions
                 (list (service-extension
                        home-files-service-type
                        home-hg-files-service)
                       (service-extension
                        home-profile-service-type
                        home-hg-profile-service)))
                (compose identity)
                (extend home-hg-extensions)
                (default-value (home-hg-configuration))
                (description "\
Install and configure the Mercurial version control system.")))

(define (generate-home-hg-documentation)
  (string-append
   (generate-documentation
    `((home-hg-configuration
       ,home-hg-configuration-fields))
    'home-hg-configuration)
   "\n\n"
   (generate-documentation
    `((home-hg-extension
       ,home-hg-extension-fields))
    'home-hg-extension)))

debug log:

solving afc9c539a7 ...
found afc9c539a7 in https://yhetil.org/guix-patches/20211023180654.3760-1-go.wigust@gmail.com/

applying [1/1] https://yhetil.org/guix-patches/20211023180654.3760-1-go.wigust@gmail.com/
diff --git a/gnu/home/services/version-control.scm b/gnu/home/services/version-control.scm
new file mode 100644
index 0000000000..afc9c539a7

Checking patch gnu/home/services/version-control.scm...
Applied patch gnu/home/services/version-control.scm cleanly.

index at:
100644 afc9c539a7dc41ffacb1004bcc112c471aee7d9a	gnu/home/services/version-control.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).