diff --git a/guilt b/guilt index ec4fb04..fbc8478 100755 --- a/guilt +++ b/guilt @@ -167,7 +167,7 @@ verify_branch() get_top() { - tail -1 "$GUILT_DIR/$branch/status" + tail -n 1 "$GUILT_DIR/$branch/status" } get_prev() @@ -479,10 +479,13 @@ pop_many_patches() cd_to_toplevel # remove the patches refs - tail -$2 < "$applied" | remove_patch_refs + tail -n $2 < "$applied" | remove_patch_refs git reset --hard "$1" > /dev/null - head -n "-$2" < "$applied" > "$applied.tmp" + + n=`wc -l < "$applied"` + n=`expr $n - $2` + head -n "$n" < "$applied" > "$applied.tmp" mv "$applied.tmp" "$applied" ) } @@ -491,7 +494,7 @@ pop_many_patches() pop_all_patches() { pop_many_patches \ - `git rev-parse refs/patches/$branch/$(head -1 "$applied")^` \ + `git rev-parse refs/patches/$branch/$(head -n 1 "$applied")^` \ `wc -l < "$applied"` } @@ -536,7 +539,7 @@ commit() fi ct=`git log -1 --pretty=%ct` - if [ $ct -gt `stat -c %Y "$p"` ]; then + if [ $ct -gt `last_modified "$p"` ]; then ct=`expr $ct + 60` if [ $ct -gt `date +%s` ]; then touch "$p" @@ -545,12 +548,7 @@ commit() fi fi - # 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). - export GIT_AUTHOR_DATE="`stat -c %y "$p" | 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/'`" + export GIT_AUTHOR_DATE="`format_last_modified "$p"`" export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" # commit @@ -717,9 +715,11 @@ __refresh_patch() N=`expr "$3" - 1` # remove the patches refs - tail -$N < "$applied" | remove_patch_refs + tail -n $N < "$applied" | remove_patch_refs - head -n "-$N" < "$applied" > "$applied.tmp" + n=`wc -l < "$applied"` + n=`expr $n - $N` + head -n "$n" < "$applied" > "$applied.tmp" mv "$applied.tmp" "$applied" ) } @@ -779,6 +779,50 @@ guilt_hook() return $? } +# usage: last_modified +last_modified() +{ + case $UNAME_S in + Darwin) stat -f "%a" "$1" ;; + Linux) stat -c "%Y" "$1" ;; + *) echo "Unsupported operating system: $UNAME_S" ;; + esac +} + +# usage: last_modified +format_last_modified() +{ + case $UNAME_S in + Darwin) stat -f "%Sa" -t "%Y-%m-%d %H:%M:%S %z" "$1" ;; + Linux) + # 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/';; + *) echo "Unsupported operating system: $UNAME_S" ;; + esac +} + +# usage: head -n [count] +head() { + case $UNAME_S in + Darwin) if [ "$2" -gt 0 ]; then "$HEAD" -n "$2"; fi ;; + Linux) "$HEAD" -n "$2" ;; + *) echo "Unsupported operating system: $UNAME_S" ;; + esac +} + +# usage: sha1 [file] +sha1() { + case $UNAME_S in + Darwin) openssl dgst -sha1 "$1" ;; + Linux) sha1sum "$1" ;; + *) echo "Unsupported operating system: $UNAME_S" ;; + esac +} + # # Some constants # @@ -829,3 +873,6 @@ guards_file="$GUILT_DIR/$branch/guards" # determine a pager to use for anything interactive (fall back to more) pager="more" [ ! -z "$PAGER" ] && pager="$PAGER" + +UNAME_S=`uname -s` +HEAD=`which head` diff --git a/guilt-branch b/guilt-branch index 125bb1a..f81adb2 100755 --- a/guilt-branch +++ b/guilt-branch @@ -36,7 +36,13 @@ git checkout "$newbranch" mkdir -p "$GUILT_DIR/`dirname $newbranch`" # copy the patch dir -cp -a "$GUILT_DIR/$branch" "$GUILT_DIR/$newbranch" +case $UNAME_S in + # Darwin doesn't have the GNU equalient -d (--no-dereference --preserve=links), + # flags + Darwin) cp -p "$GUILT_DIR/$branch" "$GUILT_DIR/$newbranch" ;; + Linux) cp -a "$GUILT_DIR/$branch" "$GUILT_DIR/$newbranch" ;; + *) echo "Unsupported operating system: $UNAME_S" ;; +esac # copy the refs diff --git a/guilt-files b/guilt-files index ee129b9..e90a8e9 100755 --- a/guilt-files +++ b/guilt-files @@ -31,7 +31,7 @@ IFS=: if [ -n "$opt_all" ]; then cat $applied else - tail -1 $applied + tail -n 1 $applied fi | while read patch; do obj=`git rev-parse refs/patches/$branch/$patch` diff --git a/guilt-graph b/guilt-graph index 0fb4e79..9514186 100755 --- a/guilt-graph +++ b/guilt-graph @@ -12,7 +12,7 @@ fi patchname="$1" -bottom=`git rev-parse refs/patches/$branch/$(head -1 < "$applied")` +bottom=`git rev-parse refs/patches/$branch/$(head -n 1 < "$applied")` base=`git rev-parse $bottom^` if [ -z "$patchname" ]; then @@ -55,7 +55,7 @@ while [ "$current" != "$base" ]; do getfiles $current | while read f; do # hash the filename - fh=`echo "$f" | sha1sum | cut -d' ' -f1` + fh=`echo "$f" | sha1 | cut -d' ' -f1` if [ -e "$cache/$fh" ]; then # ok, something already touched this file before us cat "$cache/$fh" >> "$cache/dep" diff --git a/guilt-push b/guilt-push index 1fae40b..8c16628 100755 --- a/guilt-push +++ b/guilt-push @@ -102,7 +102,7 @@ if [ "$sidx" -gt "$eidx" ]; then if [ "$sidx" -le "`get_series | wc -l`" ]; then disp "Patch is already applied." else - disp "File series fully applied, ends at patch `get_series | tail -1`" + disp "File series fully applied, ends at patch `get_series | tail -n 1`" fi exit 0 fi diff --git a/guilt-rebase b/guilt-rebase index ebfe056..4da1a25 100755 --- a/guilt-rebase +++ b/guilt-rebase @@ -80,7 +80,7 @@ cat "$rebase_dir/status" | while read hash name; do while read patchid commitid ; do disp "Applying '$name'" if [ -f "$rebase_dir/$patchid" ]; then - realcommit=`head -1 "$rebase_dir/$patchid"` + realcommit=`head -n 1 "$rebase_dir/$patchid"` disp "Matches upstream commit $realcommit" series_rename_patch "$name" "###rebased###$name" disp "Patch removed from series." diff --git a/guilt-repair b/guilt-repair index 163ac18..17a25bc 100755 --- a/guilt-repair +++ b/guilt-repair @@ -82,7 +82,7 @@ repair_pushed() { if [ -s "$applied" ]; then # there were some patches applied - newrev=`git rev-parse refs/patches/$branch/$(head -1 < "$applied")^` + newrev=`git rev-parse refs/patches/$branch/$(head -n 1 < "$applied")^` else # no patches were applied, but let's do all the work anyway newrev="$oldrev" diff --git a/guilt-series b/guilt-series index 031ff04..e233391 100755 --- a/guilt-series +++ b/guilt-series @@ -25,8 +25,8 @@ if [ ! -z "$edit" ]; then git_editor "$series" elif [ ! -z "$gui" ]; then [ -z "`get_top`" ] && die "No patches applied." - bottom=`git rev-parse refs/patches/$branch/$(head -1 $applied)` - top=`git rev-parse refs/patches/$branch/$(tail -1 $applied)` + bottom=`git rev-parse refs/patches/$branch/$(head -n 1 $applied)` + top=`git rev-parse refs/patches/$branch/$(tail -n 1 $applied)` range="$bottom..$top" # FIXME, this doesn't quite work - it's perfectly fine with