Fossil SCM

Prelimiary hook documentation. Use popen2() to run after-receive hooks for compatibility on windows systems.

drh 2020-07-06 17:38 hooks
Commit 4729793ea19d56303d090577c6eec814ac01fe345cc12fad7d20367ce90215c5
2 files changed +8 -4 +126
+8 -4
--- src/hook.c
+++ src/hook.c
@@ -386,14 +386,18 @@
386386
fossil_print("%s\n", zCmd2);
387387
if( needOut ){
388388
fossil_print("%s", blob_str(&out));
389389
}
390390
}else if( needOut ){
391
- FILE *f = popen(zCmd2, "w");
392
- if( f ){
393
- fwrite(blob_buffer(&out),1,blob_size(&out),f);
394
- pclose(f);
391
+ int fdFromChild;
392
+ FILE *toChild;
393
+ int pidChild;
394
+ if( popen2(zCmd2, &fdFromChild, &toChild, &pidChild, 0)==0 ){
395
+ if( toChild ){
396
+ fwrite(blob_buffer(&out),1,blob_size(&out),toChild);
397
+ }
398
+ pclose2(fdFromChild, toChild, pidChild);
395399
}
396400
}else{
397401
fossil_system(zCmd2);
398402
}
399403
fossil_free(zCmd2);
400404
401405
ADDED www/hooks.md
--- src/hook.c
+++ src/hook.c
@@ -386,14 +386,18 @@
386 fossil_print("%s\n", zCmd2);
387 if( needOut ){
388 fossil_print("%s", blob_str(&out));
389 }
390 }else if( needOut ){
391 FILE *f = popen(zCmd2, "w");
392 if( f ){
393 fwrite(blob_buffer(&out),1,blob_size(&out),f);
394 pclose(f);
 
 
 
 
395 }
396 }else{
397 fossil_system(zCmd2);
398 }
399 fossil_free(zCmd2);
400
401 DDED www/hooks.md
--- src/hook.c
+++ src/hook.c
@@ -386,14 +386,18 @@
386 fossil_print("%s\n", zCmd2);
387 if( needOut ){
388 fossil_print("%s", blob_str(&out));
389 }
390 }else if( needOut ){
391 int fdFromChild;
392 FILE *toChild;
393 int pidChild;
394 if( popen2(zCmd2, &fdFromChild, &toChild, &pidChild, 0)==0 ){
395 if( toChild ){
396 fwrite(blob_buffer(&out),1,blob_size(&out),toChild);
397 }
398 pclose2(fdFromChild, toChild, pidChild);
399 }
400 }else{
401 fossil_system(zCmd2);
402 }
403 fossil_free(zCmd2);
404
405 DDED www/hooks.md
+126
--- a/www/hooks.md
+++ b/www/hooks.md
@@ -0,0 +1,126 @@
1
+# Hooks
2
+
3
+Hooks are short scripts that Fossil runs at defined points of processing.
4
+Administrators can use hooks to help enforce policy or connect Fossil to
5
+a continuous integration (CI) system.
6
+
7
+## Interim Documentation.
8
+
9
+ * This is a work-in-progress. The interface is in flux.
10
+ For the time being, the documentation as a list of
11
+ bullet points. We hope to transform this into a proper document
12
+ later, after things settle down.
13
+
14
+ * Contributions and suggestions to the hook system and/or the
15
+ documentation are welcomed.
16
+
17
+## General Notes.
18
+
19
+ * Each hooks has a "type", as "sequence", and a "command". The command
20
+ is a shell command that runs at the appropriate time. The type
21
+ is currently one of "after-or "disabled".
22
+ The sequence is an arbitrary integer.
23
+
24
+ * There can be multiple hooks of the same type. When that is the
25
+ case, the hooks are run in order of ascending sequence.
26
+
27
+ * Use the "fossil hook" command to create, edit, and delete hooks.
28
+
29
+ * Use the "fossil hook test" command to test new hooks.
30
+
31
+## Hook Scripts
32
+
33
+ * All scripts are expected to run relatively quickly. If a long-running
34
+ process is started by a hook, it should be run in the background so
35
+ that the original script can return.
36
+
37
+ * The "%F" sequence inside the script is translated into the
38
+ name of the fossil executable.
39
+
40
+ * The "%R" sequence in the script is translated into the name of
41
+ the repository.
42
+
43
+ * The "%As,
44
+ the meaning of which depends on the hook type. The auxiliary filename
45
+ might be an empty string. Take care to use appropriate quoting!
46
+
47
+## Disabled Hooks
48
+
49
+ * Hooks with type "disabled" nev* The "after-receive" hook is run by [the backoffice](./backoffice.md)
50
+ whenever new artifacts are received into the repository. The artifacts
51
+ have already been committed and so there is nothing that the
52
+ after-receive hook can do to block them.
53
+
54
+ * The after-receive hooks are intended to be run on a server# Hooks
55
+
56
+Hooks are short scripts that Fossil runs at defined points of processing.
57
+Administrators ce shorruns at the appropriate time. The type
58
+ is currently one of "after-or "disabled".
59
+ The sequence is an arbitrary integer.
60
+
61
+ * There can be multiple hooks of the same type. When that is the
62
+ case, the hooks are run in order of ascending sequence.
63
+
64
+ * Use the "fossil hook" command to create, edit, and delete hooks.
65
+
66
+ * Use the "fossil hook test" command to test new hooks.
67
+
68
+## Hook Scripts
69
+
70
+ * All scripts are expected to run relatively quickly. If a long-running
71
+ process is started by a hook, it should be run in the background so
72
+ that the original script can return.
73
+
74
+ * The "%F" sequence inside the script is translated into the
75
+ name of the fossil executable.
76
+
77
+ * The "%R" sequence in the script is translated into the name of
78
+ the repository.
79
+
80
+ * The "%As,
81
+ the meaning of which depends on the hook type. The auxiliary filename
82
+ might be an empty string. Take care to use appropriate quoting!
83
+
84
+## Disabled Hooks
85
+
86
+ * Hooks with type "disabled" nev* The "after-receive" hook is run by [the backoffice](./backoffice.md)
87
+ whenever new artifacts are received into the repository. The artifacts
88
+ have already been committed and so there is nothing that the
89
+ after-receive hook can do to block them.
90
+
91
+ * The after-receive hooks are intended to be run on a server to start
92
+ up a background testing or CI process. But they can also be run
93
+ on the client side. The key point is that after-receive hooks are
94
+ invoked by backoffice, so backoffice must be running in order to
95
+ fire after-receive hooks.
96
+
97
+ * The exit code from the after-receive script is ignored.
98
+
99
+ * The standard intput to 60 seconds, or untsil hook test" command to test new hooks.
100
+
101
+## Hook Scripts
102
+
103
+ * All scripts are expected to run relatively quickly. If a long-running
104
+ process is started by a hook, it should be run in the background so
105
+ that the original script can return.
106
+
107
+ * The "%F" sequence inside the script is translated into the
108
+ name of the fossil executable.
109
+
110
+ * The "%R" sequence in the script is translated into the name of
111
+ the repository.
112
+
113
+ * The "%As,
114
+ the meaning of which depends on the hook type. The auxiliary filename
115
+ might be an empty string. Take care to use appropriate quoting!
116
+
117
+## Disabled Hooks
118
+
119
+ * Hooks with type "disabled" never run. They are a place-holder for
120
+ scripts that might be converted to some other hook-type later.
121
+ For example, the command "fossil hook edit --type disabled ID"
122
+ can be used to temporarily disable the hook named ID, and then
123
+ "fossil hook edit --type after-receive ID" can be used to reenable
124
+ it later.
125
+
126
+## After-Receiv
--- a/www/hooks.md
+++ b/www/hooks.md
@@ -0,0 +1,126 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
--- a/www/hooks.md
+++ b/www/hooks.md
@@ -0,0 +1,126 @@
1 # Hooks
2
3 Hooks are short scripts that Fossil runs at defined points of processing.
4 Administrators can use hooks to help enforce policy or connect Fossil to
5 a continuous integration (CI) system.
6
7 ## Interim Documentation.
8
9 * This is a work-in-progress. The interface is in flux.
10 For the time being, the documentation as a list of
11 bullet points. We hope to transform this into a proper document
12 later, after things settle down.
13
14 * Contributions and suggestions to the hook system and/or the
15 documentation are welcomed.
16
17 ## General Notes.
18
19 * Each hooks has a "type", as "sequence", and a "command". The command
20 is a shell command that runs at the appropriate time. The type
21 is currently one of "after-or "disabled".
22 The sequence is an arbitrary integer.
23
24 * There can be multiple hooks of the same type. When that is the
25 case, the hooks are run in order of ascending sequence.
26
27 * Use the "fossil hook" command to create, edit, and delete hooks.
28
29 * Use the "fossil hook test" command to test new hooks.
30
31 ## Hook Scripts
32
33 * All scripts are expected to run relatively quickly. If a long-running
34 process is started by a hook, it should be run in the background so
35 that the original script can return.
36
37 * The "%F" sequence inside the script is translated into the
38 name of the fossil executable.
39
40 * The "%R" sequence in the script is translated into the name of
41 the repository.
42
43 * The "%As,
44 the meaning of which depends on the hook type. The auxiliary filename
45 might be an empty string. Take care to use appropriate quoting!
46
47 ## Disabled Hooks
48
49 * Hooks with type "disabled" nev* The "after-receive" hook is run by [the backoffice](./backoffice.md)
50 whenever new artifacts are received into the repository. The artifacts
51 have already been committed and so there is nothing that the
52 after-receive hook can do to block them.
53
54 * The after-receive hooks are intended to be run on a server# Hooks
55
56 Hooks are short scripts that Fossil runs at defined points of processing.
57 Administrators ce shorruns at the appropriate time. The type
58 is currently one of "after-or "disabled".
59 The sequence is an arbitrary integer.
60
61 * There can be multiple hooks of the same type. When that is the
62 case, the hooks are run in order of ascending sequence.
63
64 * Use the "fossil hook" command to create, edit, and delete hooks.
65
66 * Use the "fossil hook test" command to test new hooks.
67
68 ## Hook Scripts
69
70 * All scripts are expected to run relatively quickly. If a long-running
71 process is started by a hook, it should be run in the background so
72 that the original script can return.
73
74 * The "%F" sequence inside the script is translated into the
75 name of the fossil executable.
76
77 * The "%R" sequence in the script is translated into the name of
78 the repository.
79
80 * The "%As,
81 the meaning of which depends on the hook type. The auxiliary filename
82 might be an empty string. Take care to use appropriate quoting!
83
84 ## Disabled Hooks
85
86 * Hooks with type "disabled" nev* The "after-receive" hook is run by [the backoffice](./backoffice.md)
87 whenever new artifacts are received into the repository. The artifacts
88 have already been committed and so there is nothing that the
89 after-receive hook can do to block them.
90
91 * The after-receive hooks are intended to be run on a server to start
92 up a background testing or CI process. But they can also be run
93 on the client side. The key point is that after-receive hooks are
94 invoked by backoffice, so backoffice must be running in order to
95 fire after-receive hooks.
96
97 * The exit code from the after-receive script is ignored.
98
99 * The standard intput to 60 seconds, or untsil hook test" command to test new hooks.
100
101 ## Hook Scripts
102
103 * All scripts are expected to run relatively quickly. If a long-running
104 process is started by a hook, it should be run in the background so
105 that the original script can return.
106
107 * The "%F" sequence inside the script is translated into the
108 name of the fossil executable.
109
110 * The "%R" sequence in the script is translated into the name of
111 the repository.
112
113 * The "%As,
114 the meaning of which depends on the hook type. The auxiliary filename
115 might be an empty string. Take care to use appropriate quoting!
116
117 ## Disabled Hooks
118
119 * Hooks with type "disabled" never run. They are a place-holder for
120 scripts that might be converted to some other hook-type later.
121 For example, the command "fossil hook edit --type disabled ID"
122 can be used to temporarily disable the hook named ID, and then
123 "fossil hook edit --type after-receive ID" can be used to reenable
124 it later.
125
126 ## After-Receiv

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button