From: Zheng Liu <gnehzuil.liu@gmail.com>
To: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: [GUILT] add FreeBSD support
Date: Tue, 20 Aug 2013 15:44:16 +0800 [thread overview]
Message-ID: <20130820074415.GA27247@gmail.com> (raw)
In-Reply-To: <20130809152046.GL22686@poseidon.cudanet.local>
Hi Josef,
On Fri, Aug 09, 2013 at 11:20:46AM -0400, Josef 'Jeff' Sipek wrote:
> On Fri, Aug 09, 2013 at 11:04:45PM +0800, gnehzuil.liu wrote:
> > ?? 2013-8-9??????10:46??Josef 'Jeff' Sipek <jeffpc@josefsipek.net> д????
> >
> > > On Fri, Aug 09, 2013 at 08:32:28PM +0800, Zheng Liu wrote:
> > >> From: Zheng Liu <gnehzuil.liu@gmail.com>
> > >>
> > >> Currently guilt doesn't support FreeBSD platform. This commit tries to
> > >> add this support. The file called 'os.FreeBSD' is copied from os.Darwin
> > >> due to these two platforms have almost the same command tools.
> > >
> > > Out of curiosity, is it identical? I eyeballed it, and they do look
> > > identical. There's probably a better way to do this whole os-specific
> > > thing, but this will work well enough for now.
> >
> > Yes, it is identical. Sorry, I am a newbie for guilt, but I am happy to
> > improve this os-specific thing. Any idea?
>
> So, I'm a bit torn between some "build-time" checking that generates
> something like an "os" file based on what it detects and something that
> happens at runtime. I like that currently there's nothing to do - you just
> clone the repo and you're set. At the same time, the more code can be
> avoided executing the faster (in theory) guilt gets.
Sorry for the late reply. I did a simple experiment that tries to fold
all os.* files into one file and uses a if statement to export functions
according to different platforms. But frankly I don't like this because
it is not very clearly. So IMHO we'd better add a 'os.FreeBSD' file to
support FreeBSD platform.
I attach the patch in this mail. It is not very mature. If you think
it is worthwhile improving this patch. Please review it. All feedbacks
are always welcome.
Regards,
- Zheng
---
Makefile | 2 +-
guilt | 8 ++--
os | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++
os.Darwin | 70 ---------------------------
os.Linux | 57 ----------------------
os.SunOS | 57 ----------------------
regression/scaffold | 4 +-
7 files changed, 141 insertions(+), 191 deletions(-)
create mode 100644 os
delete mode 100644 os.Darwin
delete mode 100644 os.Linux
delete mode 100644 os.SunOS
diff --git a/Makefile b/Makefile
index b38c1e4..395abc1 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ PREFIX?=/usr/local
DESTDIR?=
INSTALL?=install
-OSFILES = $(filter-out $(wildcard *~),$(wildcard os.*))
+OSFILES = os
SCRIPTS = $(filter-out $(wildcard *~),$(wildcard guilt-*))
.PHONY: all
diff --git a/guilt b/guilt
index e9b2aab..718bed0 100755
--- a/guilt
+++ b/guilt
@@ -906,10 +906,10 @@ pager="more"
UNAME_S=`uname -s`
-if [ -r "$GUILT_PATH/os.$UNAME_S" ]; then
- . "$GUILT_PATH/os.$UNAME_S"
-elif [ -r "$GUILT_PATH/../lib/guilt/os.$UNAME_S" ]; then
- . "$GUILT_PATH/../lib/guilt/os.$UNAME_S"
+if [ -r "$GUILT_PATH/os" ]; then
+ . "$GUILT_PATH/os"
+elif [ -r "$GUILT_PATH/../lib/guilt/os" ]; then
+ . "$GUILT_PATH/../lib/guilt/os"
else
die "Unsupported operating system: $UNAME_S"
fi
diff --git a/os b/os
new file mode 100644
index 0000000..6d1bc01
--- /dev/null
+++ b/os
@@ -0,0 +1,134 @@
+UNAME_S=`uname -s`
+
+if [ $UNAME_S == 'FreeBSD' ] || [ $UNAME_S == 'Darwin' ]; then
+ # usage: touch_date <unix ts> <file>
+ touch_date()
+ {
+ touch -t `date -r $1 +%Y%m%d%H%M.%S` "$2"
+ }
+
+ # usage: last_modified <file>
+ last_modified()
+ {
+ stat -f "%m" "$1"
+ }
+
+ # usage: format_last_modified <file>
+ format_last_modified()
+ {
+ stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S %z" "$1"
+ }
+
+ # usage: head_n [count]
+ head_n()
+ {
+ if [ "$1" -gt 0 ]; then
+ head -n "$1"
+ fi
+ }
+
+ # usage: sha1 [file]
+ sha1()
+ {
+ if [ $# = 1 ]
+ then
+ openssl dgst -sha1 "$1" | sed "s,SHA1.\(.*\).= \(.*\),\2 \1,"
+ else
+ openssl dgst -sha1 | sed 's,\(.*= \)*\(.*\),\2 -,'
+ fi
+ }
+
+ # usage: cp_a <src> <dst>
+ cp_a()
+ {
+ cp -pR "$1" "$2"
+ }
+
+ # usage: _tac
+ _tac()
+ {
+ sed -e '1!G;h;$!d'
+ }
+
+ _seq()
+ {
+ (
+ if [ $# -eq 1 ]
+ then
+ /usr/bin/jot $1
+ elif [ $# -eq 2 ]
+ then
+ n1=$((${2} - ${1} + 1))
+ n2=$1
+ /usr/bin/jot $n1 $n2
+ elif [ $# -eq 3 ]
+ then
+ num1=$1
+ incr=$2
+ num2=$3
+ /usr/bin/awk -v n1=$num1 -v n2=$num2 -v add=$incr 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed -E '/e/s/^.+e.+$/0/'
+ fi
+ )
+ return 0
+ }
+elif [ $UNAME_S == 'Linux' ] || [ $UNAME_S == 'SunOS' ]; then
+ # usage: touch_date <unix ts> <file>
+ touch_date()
+ {
+ touch -d @$1 "$2"
+ }
+
+ # usage: last_modified <file>
+ last_modified()
+ {
+ stat -c "%Y" "$1"
+ }
+
+ # usage: format_last_modified <file>
+ format_last_modified()
+ {
+ # must strip nano-second part otherwise git gets very
+ # confused, and makes up strange timestamps from the past
+ # (chances are it decides to interpret it as a unix
+ # timestamp).
+ stat -c "%y" "$1" | sed -e '
+ s/^\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\) \([0-9]\{2\}\):\([0-9]\{2\}\):\([0-9]\{2\}\)\.[0-9]* \(.*\)$/\1-\2-\3 \4:\5:\6 \7/'
+ }
+
+ # usage: head_n [count]
+ head_n()
+ {
+ head -n "$1"
+ }
+
+ # usage: sha1 [file]
+ sha1()
+ {
+ if [ $# = 1 ]
+ then
+ sha1sum "$1"
+ else
+ sha1sum
+ fi
+ }
+
+ # usage: cp_a <src> <dst>
+ cp_a()
+ {
+ cp -a "$1" "$2"
+ }
+
+ # usage: _tac
+ _tac()
+ {
+ tac
+ }
+
+ _seq()
+ {
+ seq "$@"
+ return $?
+ }
+else
+ die "Unsupported operating system: $UNAME_S"
+fi
diff --git a/os.Darwin b/os.Darwin
deleted file mode 100644
index 3f23121..0000000
--- a/os.Darwin
+++ /dev/null
@@ -1,70 +0,0 @@
-# usage: touch_date <unix ts> <file>
-touch_date()
-{
- touch -t `date -r $1 +%Y%m%d%H%M.%S` "$2"
-}
-
-# usage: last_modified <file>
-last_modified()
-{
- stat -f "%m" "$1"
-}
-
-# usage: format_last_modified <file>
-format_last_modified()
-{
- stat -f "%Sm" -t "%Y-%m-%d %H:%M:%S %z" "$1"
-}
-
-# usage: head_n [count]
-head_n()
-{
- if [ "$1" -gt 0 ]; then
- head -n "$1"
- fi
-}
-
-# usage: sha1 [file]
-sha1()
-{
- if [ $# = 1 ]
- then
- openssl dgst -sha1 "$1" | sed "s,SHA1.\(.*\).= \(.*\),\2 \1,"
- else
- openssl dgst -sha1 | sed 's,\(.*= \)*\(.*\),\2 -,'
- fi
-}
-
-# usage: cp_a <src> <dst>
-cp_a()
-{
- cp -pR "$1" "$2"
-}
-
-# usage: _tac
-_tac()
-{
- sed -e '1!G;h;$!d'
-}
-
-_seq()
-{
- (
- if [ $# -eq 1 ]
- then
- /usr/bin/jot $1
- elif [ $# -eq 2 ]
- then
- n1=$((${2} - ${1} + 1))
- n2=$1
- /usr/bin/jot $n1 $n2
- elif [ $# -eq 3 ]
- then
- num1=$1
- incr=$2
- num2=$3
- /usr/bin/awk -v n1=$num1 -v n2=$num2 -v add=$incr 'BEGIN{ for(i=n1; i<=n2; i+=add) print i;}' | /usr/bin/sed -E '/e/s/^.+e.+$/0/'
- fi
- )
- return 0
-}
diff --git a/os.Linux b/os.Linux
deleted file mode 100644
index aaebf88..0000000
--- a/os.Linux
+++ /dev/null
@@ -1,57 +0,0 @@
-# usage: touch_date <unix ts> <file>
-touch_date()
-{
- touch -d @$1 "$2"
-}
-
-# usage: last_modified <file>
-last_modified()
-{
- stat -c "%Y" "$1"
-}
-
-# usage: format_last_modified <file>
-format_last_modified()
-{
- # must strip nano-second part otherwise git gets very
- # confused, and makes up strange timestamps from the past
- # (chances are it decides to interpret it as a unix
- # timestamp).
- stat -c "%y" "$1" | sed -e '
-s/^\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\) \([0-9]\{2\}\):\([0-9]\{2\}\):\([0-9]\{2\}\)\.[0-9]* \(.*\)$/\1-\2-\3 \4:\5:\6 \7/'
-}
-
-# usage: head_n [count]
-head_n()
-{
- head -n "$1"
-}
-
-# usage: sha1 [file]
-sha1()
-{
- if [ $# = 1 ]
- then
- sha1sum "$1"
- else
- sha1sum
- fi
-}
-
-# usage: cp_a <src> <dst>
-cp_a()
-{
- cp -a "$1" "$2"
-}
-
-# usage: _tac
-_tac()
-{
- tac
-}
-
-_seq()
-{
- seq "$@"
- return $?
-}
diff --git a/os.SunOS b/os.SunOS
deleted file mode 100644
index aaebf88..0000000
--- a/os.SunOS
+++ /dev/null
@@ -1,57 +0,0 @@
-# usage: touch_date <unix ts> <file>
-touch_date()
-{
- touch -d @$1 "$2"
-}
-
-# usage: last_modified <file>
-last_modified()
-{
- stat -c "%Y" "$1"
-}
-
-# usage: format_last_modified <file>
-format_last_modified()
-{
- # must strip nano-second part otherwise git gets very
- # confused, and makes up strange timestamps from the past
- # (chances are it decides to interpret it as a unix
- # timestamp).
- stat -c "%y" "$1" | sed -e '
-s/^\([0-9]\{4\}\)-\([0-9]\{2\}\)-\([0-9]\{2\}\) \([0-9]\{2\}\):\([0-9]\{2\}\):\([0-9]\{2\}\)\.[0-9]* \(.*\)$/\1-\2-\3 \4:\5:\6 \7/'
-}
-
-# usage: head_n [count]
-head_n()
-{
- head -n "$1"
-}
-
-# usage: sha1 [file]
-sha1()
-{
- if [ $# = 1 ]
- then
- sha1sum "$1"
- else
- sha1sum
- fi
-}
-
-# usage: cp_a <src> <dst>
-cp_a()
-{
- cp -a "$1" "$2"
-}
-
-# usage: _tac
-_tac()
-{
- tac
-}
-
-_seq()
-{
- seq "$@"
- return $?
-}
diff --git a/regression/scaffold b/regression/scaffold
index 546d8c6..4d4613b 100644
--- a/regression/scaffold
+++ b/regression/scaffold
@@ -25,8 +25,8 @@ function die
UNAME_S=`uname -s`
-if [ -r "$REG_DIR/../os.$UNAME_S" ]; then
- . "$REG_DIR/../os.$UNAME_S"
+if [ -r "$REG_DIR/../os" ]; then
+ . "$REG_DIR/../os"
else
die "Unsupported operating system: $UNAME_S"
fi
--
1.8.3.4
next prev parent reply other threads:[~2013-08-20 7:43 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-09 12:32 [GUILT] add FreeBSD support Zheng Liu
2013-08-09 14:46 ` Josef 'Jeff' Sipek
2013-08-09 15:04 ` gnehzuil.liu
2013-08-09 15:20 ` Josef 'Jeff' Sipek
2013-08-20 7:44 ` Zheng Liu [this message]
2013-08-20 15:25 ` Josef 'Jeff' Sipek
2013-08-21 2:04 ` Zheng Liu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20130820074415.GA27247@gmail.com \
--to=gnehzuil.liu@gmail.com \
--cc=git@vger.kernel.org \
--cc=jeffpc@josefsipek.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.