summaryrefslogtreecommitdiffstats
path: root/git-difme.scm
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2016-07-18 23:57:18 +0000
committerrsiddharth <s@ricketyspace.net>2016-07-18 23:57:18 +0000
commit18f9aaf8e7c14ef42470c779d96aa56a1198560c (patch)
treea8f4fe92d68e85db7f564dd66cbb19c24cc33f77 /git-difme.scm
parentf944254dc1a12703981451e9a1c575ddd179591c (diff)
file regex can be a rule.
* git-difme (build-stage-regex): remove function. (difme-stage-commit?): new function. (difme): use `difme-stage-commit?` * README.org: add info about file regex as a rule.
Diffstat (limited to 'git-difme.scm')
-rw-r--r--git-difme.scm25
1 files changed, 16 insertions, 9 deletions
diff --git a/git-difme.scm b/git-difme.scm
index fbe9dba..13fbe9c 100644
--- a/git-difme.scm
+++ b/git-difme.scm
@@ -126,13 +126,21 @@ the commit message will be in the following format:
(difme-exec cmd))))
;;;; difme workers
-(define (build-stage-regex rules)
- "build stage regex based on RULES."
- (let ((regex "^"))
- (cond ((null? rules) (string-append regex "$"))
- ((member "." rules) ".")
- (else (string-append
- regex "[" (string-concatenate rules) "]")))))
+(define (difme-stage-commit? file-info rules)
+ "return non-nil if file must be staged and commited; #f otherwise."
+ (let ((file-mod-type (car file-info))
+ (file-path (cdr file-info)))
+ (define (mod-type? rule)
+ (member rule '("M" "D" "?" ".")))
+ (define (process rule)
+ (if (equal? rule ".")
+ rule
+ (string-append "^[" rule "]")))
+ (define (match rule)
+ (if (mod-type? rule)
+ (if (string-match (process rule) file-mod-type) #t #f)
+ (if (string-match rule file-path) #t #f)))
+ (member #t (map match rules))))
(define (difme repo-info)
"stage and commit relevant files in repo defined REPO-INFO.
@@ -140,7 +148,6 @@ the commit message will be in the following format:
also does `git push` to the repo' default upstream remote."
(let* ((repo-path (car repo-info))
(rules (cdr repo-info))
- (stage-regex (build-stage-regex rules))
(msg "git-difme autocommit"))
(define (commit-staged)
(let ((msg (string-append msg " already staged file(s).")))
@@ -148,8 +155,8 @@ also does `git push` to the repo' default upstream remote."
(define (process file-info)
(let* ((mod-type (car file-info))
(file-path (cdr file-info))
- (if (string-match stage-regex type)
(msg (string-append msg " [" mod-type "].")))
+ (if (difme-stage-commit? file-info rules)
(difme-stage-commit repo-path file-path msg))))
;; first commit already staged files.
(commit-staged)