# [PATCH] Add OS X support to the pre-auto-gc example hook

5 messages from 2008-09-23 to 2008-09-30. Participants: Jonathan del Strother, Miklos Vajna.
Thread: https://gitlist.dev/t/15644

## Jonathan del Strother, 2008-09-23 22:43

Subject: [PATCH] Add OS X support to the pre-auto-gc example hook
Message-ID: <1222209803-4401-1-git-send-email-jon.delStrother@bestbefore.tv>
URL: https://gitlist.dev/e/1222209803-4401-1-git-send-email-jon.delStrother%40bestbefore.tv

```
Signed-off-by: Jonathan del Strother <jon.delStrother@bestbefore.tv>
---

Darwin / OS X has a pmset tool for getting power management information.  How about adding OS X support to the auto-gc hook?
Shell scripting isn't my fortÃ©, suggestions for improvements would be welcome.

 contrib/hooks/pre-auto-gc-battery |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/contrib/hooks/pre-auto-gc-battery b/contrib/hooks/pre-auto-gc-battery
index 0096f57..0b7bcde 100644
--- a/contrib/hooks/pre-auto-gc-battery
+++ b/contrib/hooks/pre-auto-gc-battery
@@ -1,9 +1,9 @@
 #!/bin/sh
 #
 # An example hook script to verify if you are on battery, in case you
-# are running Linux. Called by git-gc --auto with no arguments. The hook
-# should exit with non-zero status after issuing an appropriate message
-# if it wants to stop the auto repacking.
+# are running Linux or OS X. Called by git-gc --auto with no arguments.
+# The hook should exit with non-zero status after issuing an appropriate
+# message if it wants to stop the auto repacking.
 #
 # This hook is stored in the contrib/hooks directory. Your distribution
 # may have put this somewhere else. If you want to use this hook, you
@@ -30,6 +30,9 @@ then
 elif grep -q '0x01$' /proc/apm 2>/dev/null
 then
 	exit 0
+elif test -x /usr/bin/pmset && (! /usr/bin/pmset -g batt | grep -q 'Battery Power' )
+then
+	exit 0
 fi
 
 echo "Auto packing deferred; not on AC"
-- 
1.6.0.2.308.gd442a.dirty

```

## Miklos Vajna, 2008-09-25 23:20

Subject: Re: [PATCH] Add OS X support to the pre-auto-gc example hook
Message-ID: <20080925232008.GO23137@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080925232008.GO23137%40genesis.frugalware.org
In-Reply-To: <1222209803-4401-1-git-send-email-jon.delStrother@bestbefore.tv>

```
On Tue, Sep 23, 2008 at 11:43:23PM +0100, Jonathan del Strother <jon.delStrother@bestbefore.tv> wrote:
> Shell scripting isn't my fortĂŠ, suggestions for improvements would be
> welcome.
> 
> +elif test -x /usr/bin/pmset && (! /usr/bin/pmset -g batt | grep -q 'Battery Power' )

What about

+elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt | grep -q 'AC Power'

?

```

## Jonathan del Strother, 2008-09-27 09:53

Subject: Re: [PATCH] Add OS X support to the pre-auto-gc example hook
Message-ID: <57518fd10809270253s4c07318bjd54c7d86460ce7d7@mail.gmail.com>
URL: https://gitlist.dev/e/57518fd10809270253s4c07318bjd54c7d86460ce7d7%40mail.gmail.com
In-Reply-To: <20080925232008.GO23137@genesis.frugalware.org>

```
On Fri, Sep 26, 2008 at 12:20 AM, Miklos Vajna <vmiklos@frugalware.org> wrote:
> On Tue, Sep 23, 2008 at 11:43:23PM +0100, Jonathan del Strother <jon.delStrother@bestbefore.tv> wrote:
>> Shell scripting isn't my fortĂŠ, suggestions for improvements would be
>> welcome.
>>
>> +elif test -x /usr/bin/pmset && (! /usr/bin/pmset -g batt | grep -q 'Battery Power' )
>
> What about
>
> +elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt | grep -q 'AC Power'
>
> ?
I was trying to handle pmset reporting anything other than Battery
Power (currently it reports either Battery, UPS, or AC), but thinking
about it, if you're on UPS, you probably don't want git gc eating into
your remaining power...
I'll post an updated version on Monday.

```

## Jonathan del Strother, 2008-09-29 23:36

Subject: [PATCH v2] Add OS X support to the pre-auto-gc example hook
Message-ID: <1222731388-833-1-git-send-email-jon.delStrother@bestbefore.tv>
URL: https://gitlist.dev/e/1222731388-833-1-git-send-email-jon.delStrother%40bestbefore.tv
In-Reply-To: <57518fd10809270253s4c07318bjd54c7d86460ce7d7@mail.gmail.com>

```
Signed-off-by: Jonathan del Strother <jon.delStrother@bestbefore.tv>
---
Second attempt - this simplifies the test while making it more specific (it will only pack when on AC power, rather than, say, UPS).

 contrib/hooks/pre-auto-gc-battery |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/hooks/pre-auto-gc-battery b/contrib/hooks/pre-auto-gc-battery
index 0096f57..b0a8caa 100644
--- a/contrib/hooks/pre-auto-gc-battery
+++ b/contrib/hooks/pre-auto-gc-battery
@@ -1,9 +1,9 @@
 #!/bin/sh
 #
 # An example hook script to verify if you are on battery, in case you
-# are running Linux. Called by git-gc --auto with no arguments. The hook
-# should exit with non-zero status after issuing an appropriate message
-# if it wants to stop the auto repacking.
+# are running Linux or OS X. Called by git-gc --auto with no arguments.
+# The hook should exit with non-zero status after issuing an appropriate
+# message if it wants to stop the auto repacking.
 #
 # This hook is stored in the contrib/hooks directory. Your distribution
 # may have put this somewhere else. If you want to use this hook, you
@@ -30,6 +30,10 @@ then
 elif grep -q '0x01$' /proc/apm 2>/dev/null
 then
 	exit 0
+elif test -x /usr/bin/pmset && /usr/bin/pmset -g batt |
+	grep -q "Currently drawing from 'AC Power'"
+then
+	exit 0
 fi
 
 echo "Auto packing deferred; not on AC"
-- 
1.6.0.2.308.gd442a.dirty

```

## Miklos Vajna, 2008-09-30 15:00

Subject: Re: [PATCH v2] Add OS X support to the pre-auto-gc example hook
Message-ID: <20080930150036.GB23137@genesis.frugalware.org>
URL: https://gitlist.dev/e/20080930150036.GB23137%40genesis.frugalware.org
In-Reply-To: <1222731388-833-1-git-send-email-jon.delStrother@bestbefore.tv>

```
On Tue, Sep 30, 2008 at 12:36:28AM +0100, Jonathan del Strother <jon.delStrother@bestbefore.tv> wrote:
> Second attempt - this simplifies the test while making it more
> specific (it will only pack when on AC power, rather than, say, UPS).

Acked-by: Miklos Vajna <vmiklos@frugalware.org>

Thanks.

```
