]> Cypherpunks.ru repositories - goredo.git/commitdiff
redo-affects v1.6.0
authorSergey Matveev <stargrave@stargrave.org>
Tue, 22 Jun 2021 07:47:27 +0000 (10:47 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 22 Jun 2021 07:47:27 +0000 (10:47 +0300)
.gitignore
doc/cmds.texi
doc/news.texi
ifchange.go
main.go
targets.go
usage.go

index dcf061d6e243a338330068d5c3259356d7e945bd..60a3ad69dfee891e8aee132ab20635b2bfcbed0c 100644 (file)
@@ -1,5 +1,6 @@
 /goredo
 /redo
+/redo-affects
 /redo-always
 /redo-cleanup
 /redo-dot
index 578d182ce65f43015cf5d292cc522d965269a614..6e5fc2f0e4bab6d04dbb57daac56c44035bbf675 100644 (file)
@@ -19,6 +19,9 @@
     @command{redo-sources} shows all recursive source files given
     targets depend on.
 
+@item redo-affects
+    List all targets that will be affected by changing the specified ones.
+
 @item redo-stamp
     Record stamp dependency. Nothing more, dummy. Read about
     @ref{Stamping, stamping} in the FAQ.
index c2674ae4ffed7bb3b75d07e5e63c95a898e0db9b..d301bddba8d624452017a787b3db1e1cc1dc9cf0 100644 (file)
@@ -1,6 +1,14 @@
 @node News
 @unnumbered News
 
+@anchor{Release 1.6.0}
+@section Release 1.6.0
+@itemize
+@item
+    @command{redo-affects} command appeared, that shows all targets that
+    will be affected by changing the specified ones.
+@end itemize
+
 @anchor{Release 1.5.0}
 @section Release 1.5.0
 @itemize
index 1f2c38194934da44475e97e039fb73601536a5a0..0f430fdebd76741065215382cb76ee406690e3fe 100644 (file)
@@ -27,6 +27,7 @@ func collectDeps(
        cwd, tgtOrig string,
        level int,
        deps map[string]map[string]struct{},
+       includeSrc bool,
 ) []string {
        cwd, tgt := cwdAndTgt(path.Join(cwd, tgtOrig))
        depPath := path.Join(cwd, RedoDir, tgt+DepSuffix)
@@ -60,7 +61,10 @@ func collectDeps(
                if dep == "" {
                        return alwayses
                }
-               if dep == tgt || isSrc(cwd, dep) {
+               if dep == tgt {
+                       continue
+               }
+               if !includeSrc && isSrc(cwd, dep) {
                        continue
                }
                if !returnReady {
@@ -68,11 +72,14 @@ func collectDeps(
                        if m, ok := deps[depRel]; ok {
                                m[tgtRel] = struct{}{}
                        } else {
-                               m = make(map[string]struct{}, 0)
+                               m = map[string]struct{}{}
                                m[tgtRel] = struct{}{}
                                deps[depRel] = m
                        }
-                       alwayses = append(alwayses, collectDeps(cwd, dep, level+1, deps)...)
+                       alwayses = append(
+                               alwayses,
+                               collectDeps(cwd, dep, level+1, deps, includeSrc)...,
+                       )
                }
        }
        return alwayses
@@ -84,7 +91,7 @@ func buildDependants(tgts []string) map[string]struct{} {
        seen := map[string]struct{}{}
        deps := map[string]map[string]struct{}{}
        for _, tgtInitial := range tgts {
-               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps) {
+               for _, tgt := range collectDeps(Cwd, tgtInitial, 0, deps, false) {
                        if tgt != tgtInitial {
                                seen[tgt] = struct{}{}
                        }
diff --git a/main.go b/main.go
index 092d38957ce4cd50bbef6cacaa8db5d88c45c65b..8c9c16da1430a761779856688da8382b82a98e18 100644 (file)
--- a/main.go
+++ b/main.go
@@ -79,6 +79,7 @@ func main() {
                rc := 0
                for _, cmdName := range []string{
                        "redo",
+                       "redo-affects",
                        "redo-always",
                        "redo-cleanup",
                        "redo-dot",
@@ -197,7 +198,7 @@ func main() {
                        panic(err)
                }
                unix.Flock(int(fdLock.Fd()), unix.LOCK_UN)
-               OODTgts = make(map[string]struct{})
+               OODTgts = map[string]struct{}{}
                for _, tgtRaw := range bytes.Split(tgtsRaw, []byte{0}) {
                        t := string(tgtRaw)
                        if t == "" {
@@ -371,6 +372,31 @@ CmdSwitch:
                for _, tgt := range tgts {
                        fmt.Println(tgt)
                }
+       case "redo-affects":
+               if tgtsWasEmpty {
+                       log.Fatalln("no targets specified")
+               }
+               var tgtsKnown []string
+               tgtsKnown, err = targetsWalker([]string{Cwd})
+               if err != nil {
+                       break
+               }
+               deps := map[string]map[string]struct{}{}
+               for _, tgt := range tgtsKnown {
+                       collectDeps(Cwd, tgt, 0, deps, true)
+               }
+               seen := map[string]struct{}{}
+               for _, tgt := range tgts {
+                       collectWholeDeps(deps[tgt], deps, seen)
+               }
+               tgts := make([]string, 0, len(seen))
+               for dep := range seen {
+                       tgts = append(tgts, dep)
+               }
+               sort.Strings(tgts)
+               for _, dep := range tgts {
+                       fmt.Println(dep)
+               }
        case "redo-ood":
                if tgtsWasEmpty {
                        tgts, err = targetsWalker([]string{Cwd})
index bc8edfd6d0b00669f1d48a8491034ddef151bda0..0545483752bda04c4ac1347cb16421ee46215c98 100644 (file)
@@ -76,7 +76,7 @@ func targetsCollect(root string, tgts map[string]struct{}) error {
 }
 
 func targetsWalker(tgts []string) ([]string, error) {
-       tgtsMap := make(map[string]struct{}, 0)
+       tgtsMap := map[string]struct{}{}
        for _, tgt := range tgts {
                if err := targetsCollect(tgt, tgtsMap); err != nil {
                        return nil, err
@@ -88,3 +88,14 @@ func targetsWalker(tgts []string) ([]string, error) {
        }
        return tgts, nil
 }
+
+func collectWholeDeps(
+       tgts map[string]struct{},
+       deps map[string]map[string]struct{},
+       seen map[string]struct{},
+) {
+       for tgt := range tgts {
+               seen[tgt] = struct{}{}
+               collectWholeDeps(deps[tgt], deps, seen)
+       }
+}
index 670da2abdecfe7dd5b7f9d7a7bc811d2cc09f252..b18c93b4d00a685df7a12b3f03710cbe0b4016d0 100644 (file)
--- a/usage.go
+++ b/usage.go
@@ -24,7 +24,7 @@ import (
 )
 
 const (
-       Version  = "1.5.0"
+       Version  = "1.6.0"
        Warranty = `Copyright (C) 2020-2021 Sergey Matveev
 
 This program is free software: you can redistribute it and/or modify
@@ -99,13 +99,17 @@ List all currently known source files.`
                d = `Usage: redo-ood [target ...]
 
 List all currently known out-of-date targets.`
+       case "redo-affects":
+               d = `Usage: redo-affects target [...]
+
+List all targets that will be affected by changing the specified ones.`
        default:
                d = `Usage: goredo -symlinks
 
 goredo expects to be called through the symbolic link to it.
-Available commands: redo, redo-always, redo-cleanup, redo-dot,
-redo-ifchange, redo-ifcreate, redo-log, redo-ood, redo-sources,
-redo-stamp, redo-targets, redo-whichdo.`
+Available commands: redo, redo-affects, redo-always, redo-cleanup,
+redo-dot, redo-ifchange, redo-ifcreate, redo-log, redo-ood,
+redo-sources, redo-stamp, redo-targets, redo-whichdo.`
        }
        fmt.Fprintf(os.Stderr, "%s\n\nCommon options:\n", d)
        flag.PrintDefaults()