3 # topgit_deps_prepare - TopGit awk utility script used by tg--awksome
4 # Copyright (C) 2017 Kyle J. McKay <mackyle@gmail.com>
10 # variable arguments (-v):
12 # brfile if non-empty, the named file gets a list of TopGit branches
13 # anfile if non-empty, annihilated branch names are written here
14 # noann if true, omit annihilated branches from brfile
15 # missing if non-empty output its value for the .topdeps blob instead
16 # of skipping, but still skip annihilated if noann is true
17 # misscmd if missing is used and not seen in a "check" line run this once
19 # note that the "noann" variable only affects brfile, if true unless missing
20 # is non-empty (in which case it suppresses the annihilated missing output), as
21 # annihilated branches normally do not contribute to the output of this script
23 # input must be result of awk_ref_prepare after feeding through the correct
24 # git --batch-check command and must be generated with the "depsblob" variable
25 # set to a TRUE value when awk_ref_prepare was run (the "msgblob" setting can
26 # be any value as the extra .topmsg blob line, if present, will always be
29 # if missing is non-empty there are two different possible choices:
31 # 1. the hash of the empty blob, this is the recommended value and will
32 # cause all annihilated (unless noann is true) and non-annihilaed branches
33 # without a .topdeps file to produce an output line which can sometimes be
36 # 2. an invalid ref value, do NOT use "missing" as there could be such a ref
37 # name in the repository ("?" or "?missing" are good choices) and it must
38 # not contain any whitespace either; in this case this will trigger the
39 # subsequent git cat-file --batch to generate a "xxx missing" line which
40 # will also remove the item and ultimately have the same effect as leaving
41 # missing unset in the first place
43 # 3. it says "two" above, so don't do this, but if the blob hash of
44 # a different .topdeps file is given its contents will be used as though
45 # it had been the branch's .topdeps file in the first place (only for
46 # annihilated and branches without one though)
48 # If missing is non-empty AND it gets used AND misscmd is non-empty AND no
49 # "blob check ?" line was seen for missing then misscmd will be run the FIRST
50 # time missing is about to be output (it always runs BEFORE the line is output).
52 # output is 1 line per non-annihilated TopGit branch with a .topdeps file where
53 # each output line has this format:
55 # <blob_hash_of_.topdeps_file> <TopGit_branch_name>
57 # which should then be fed to:
59 # git cat-file --batch='%(objecttype) %(objectsize) %(rest)' | tr '\0' '\27'
61 # note that brfile and anfile are both fully written and closed before the
62 # first line of stdout is written and will be truncated to empty even if there
63 # are no lines directed to them
66 BEGIN { exitcode =
"" }
67 function exitnow
(e
) { exitcode=e
; exit e
}
68 END { if (exitcode
!= "") exit exitcode
}
83 if (missing
!= "" && missing !~
/:/) missing = missing
"^{blob}"
86 NF ==
4 && $
4 ==
"?" && $
3 ==
"check" && $
2 ==
"blob" && $
1 != "" {
91 function domissing
() {
92 if (misscmd ==
"" || missblob in check
) return
97 NF ==
4 && $
4 ==
":" && $
3 != "" && $
2 != "missing" && $
1 != "" {
98 if ((getline bc
+ getline hc
+ \
99 getline bct
+ getline hct
+ getline hcd
) != 5) exitnow
(2)
105 if (abc
[2] != "commit" || ahc
[2] != "commit" ||
106 abct
[2] != "tree" || ahct
[2] != "tree") next
107 if (abct
[1] == ahct
[1]) {
108 if (anfile
) print $
3 >anfile
109 if (noann
|| missing ==
"") {
110 if (!noann
&& brfile
) print $
3 >brfile
118 if (brfile
) print $
3 >brfile
119 if (missing
!= "" && ahcd
[2] != "blob") {
124 if (ahcd
[2] ==
"blob") {
126 items
[++cnt
] = ahcd
[1] " " $
3
133 if (anfile
) close(anfile
)
134 if (brfile
) close(brfile
)
135 for (i =
1; i
<= cnt
; ++i
) print items
[i
]