3 # topgit_branches - TopGit awk utility script used by tg--awksome
4 # Copyright (C) 2017,2019 Kyle J. McKay <mackyle@gmail.com>
10 # variable arguments (-v):
12 # brfile if non-empty, the named file gets a copy of the output stream
13 # anfile if non-empty, annihilated branch names are written here
14 # noann if true, omit annihilated branches from output (and brfile)
15 # exclbr whitespace separated list of names to exclude (only from stdout)
16 # inclbr whitespace separated list of names to include (only for stdout)
18 # note that the "noann" variable affects both stdout and, if given, brfile
21 # if inclbr is non-empty a branch name must be listed to appear on stdout
22 # (but brfile, if given, is not affected)
24 # if a branch name appears in exclbr it is omitted from stdout trumping inclbr
25 # (but brfile, if given, is not affected)
27 # input must be output from awk_ref_prepare (depsblob and msgblob may have any
28 # setting) after feeding through the correct git --batch-check command
30 # output is one TopGit branch name per line omitting annihilated ones if noann
32 # note that brfile and anfile are both fully written and closed before the
33 # first line of stdout is written and will be truncated to empty even if there
34 # are no lines directed to them
37 BEGIN { exitcode =
"" }
38 function exitnow
(e
) { exitcode=e
; exit e
}
39 END { if (exitcode
!= "") exit exitcode
}
52 cnt =
split(inclbr
, scratch
, " ")
55 for (i =
1; i
<= cnt
; ++i
) incnames
[scratch
[i
]] =
1
57 cnt =
split(exclbr
, scratch
, " ")
58 for (i =
1; i
<= cnt
; ++i
) excnames
[scratch
[i
]] =
1
63 NF ==
4 && $
4 ==
":" && $
3 != "" && $
2 != "missing" && $
1 != "" {
64 if ((getline bc
+ getline hc
+ \
65 getline bct
+ getline hct
) != 4) exitnow
(2)
70 if (abc
[2] != "commit" || ahc
[2] != "commit" ||
71 abct
[2] != "tree" || ahct
[2] != "tree") next
72 if (abct
[1] == ahct
[1]) {
73 if (anfile
) print $
3 >anfile
76 if (brfile
) print $
3 >brfile
77 if ((!inconly
|| ($
3 in incnames
)) && !
($
3 in excnames
)) {
86 if (anfile
) close(anfile
)
87 if (brfile
) close(brfile
)
88 for (i =
1; i
<= cnt
; ++i
) print items
[i
]