File tree Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Expand file tree Collapse file tree 3 files changed +74
-0
lines changed Original file line number Diff line number Diff line change @@ -276,3 +276,10 @@ probably enable this hook.
276
276
Both standard output and standard error output are forwarded to
277
277
`git-send-pack` on the other end, so you can simply `echo` messages
278
278
for the user.
279
+
280
+ pre-auto-gc
281
+ -----------
282
+
283
+ This hook is invoked by `git-gc --auto`. It takes no parameter, and
284
+ exiting with non-zero status from this script causes the `git-gc --auto`
285
+ to abort.
Original file line number Diff line number Diff line change @@ -157,6 +157,34 @@ static int too_many_packs(void)
157
157
return gc_auto_pack_limit <= cnt ;
158
158
}
159
159
160
+ static int run_hook (void )
161
+ {
162
+ const char * argv [2 ];
163
+ struct child_process hook ;
164
+ int ret ;
165
+
166
+ argv [0 ] = git_path ("hooks/pre-auto-gc" );
167
+ argv [1 ] = NULL ;
168
+
169
+ if (access (argv [0 ], X_OK ) < 0 )
170
+ return 0 ;
171
+
172
+ memset (& hook , 0 , sizeof (hook ));
173
+ hook .argv = argv ;
174
+ hook .no_stdin = 1 ;
175
+ hook .stdout_to_stderr = 1 ;
176
+
177
+ ret = start_command (& hook );
178
+ if (ret ) {
179
+ warning ("Could not spawn %s" , argv [0 ]);
180
+ return ret ;
181
+ }
182
+ ret = finish_command (& hook );
183
+ if (ret == - ERR_RUN_COMMAND_WAITPID_SIGNAL )
184
+ warning ("%s exited due to uncaught signal" , argv [0 ]);
185
+ return ret ;
186
+ }
187
+
160
188
static int need_to_gc (void )
161
189
{
162
190
/*
@@ -176,6 +204,9 @@ static int need_to_gc(void)
176
204
append_option (argv_repack , "-A" , MAX_ADD );
177
205
else if (!too_many_loose_objects ())
178
206
return 0 ;
207
+
208
+ if (run_hook ())
209
+ return 0 ;
179
210
return 1 ;
180
211
}
181
212
Original file line number Diff line number Diff line change
1
+ #! /bin/sh
2
+ #
3
+ # An example hook script to verify if you are on battery, in case you
4
+ # are running Linux. Called by git-gc --auto with no arguments. The hook
5
+ # should exit with non-zero status after issuing an appropriate message
6
+ # if it wants to stop the auto repacking.
7
+ #
8
+ # This hook is stored in the contrib/hooks directory. Your distribution
9
+ # may have put this somewhere else. If you want to use this hook, you
10
+ # should make this script executable then link to it in the repository
11
+ # you would like to use it in.
12
+ #
13
+ # For example, if the hook is stored in
14
+ # /usr/share/git-core/contrib/hooks/pre-auto-gc-battery:
15
+ #
16
+ # chmod a+x pre-auto-gc-battery
17
+ # cd /path/to/your/repository.git
18
+ # ln -sf /usr/share/git-core/contrib/hooks/pre-auto-gc-battery \
19
+ # hooks/pre-auto-gc
20
+
21
+ if test -x /sbin/on_ac_power && /sbin/on_ac_power
22
+ then
23
+ exit 0
24
+ elif test " $( cat /sys/class/power_supply/AC/online 2> /dev/null) " = 1
25
+ then
26
+ exit 0
27
+ elif grep -q ' on-line' /proc/acpi/ac_adapter/AC/state 2> /dev/null
28
+ then
29
+ exit 0
30
+ elif grep -q ' 0x01$' /proc/apm 2> /dev/null
31
+ then
32
+ exit 0
33
+ fi
34
+
35
+ echo " Auto packing deferred; not on AC"
36
+ exit 1
You can’t perform that action at this time.
0 commit comments