threads / patch / 763

patchFix cg-log and cg-status for non-GNU sed/sort

Subject: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort

## tl;dr

6 messages between May 29, 2005 and May 31, 2005. Diffs are folded; open one to read it.

replies: 5people: 3as markdown or json

Mark Allen· May 29, 2005, 23:00 UTC · lore

Here're a couple of pretty simple patches against cg-log and cg-status (two cogito commands I use a lot) for the non-GNU (or at least older, forked GNU) tools on Darwin.

There's also a non-GNU sed problem in cg-commit, but I haven't quite figured a good way to tackle this issue yet. (The problem is in the regex stripping leading and trailing newlines from $LOGMSG at line 170. Darwin's sed does not like the embedded curly braces, but there's not a good simple way to rewrite this and retain the meaning of the "sedlet" that tracks whether its seen any text yet.)

Cheers,
--Mark

--- commit e43fc64b1f779b1ecf1bcc36e4f89a9f43ab2fb6 tree 95770616edbd49c71dff9ca6e51e7abf449d35e7 parent d36ed1fd011d349ea2adc00456750b5b3da3a9cd author Mark Allen <mrallen1@yahoo.com> 1117406652 -0500 committer Mark Allen <mallen@aeris.local> 1117406652 -0500

 cg-log    |   13 +++++--------
 cg-status |    2 +-
 2 files changed, 6 insertions(+), 9 deletions(-)
Show changes to diff +6 −9
Index: cg-log
===================================================================
--- 3a65f5fb53367c75f4f76aebed27a83d8679f068/cg-log  (mode:100755)
+++ 95770616edbd49c71dff9ca6e51e7abf449d35e7/cg-log  (mode:100755)
@@ -148,10 +148,10 @@
 				fi
 
 				date=(${rest#*> })
-				pdate="$(showdate $date)"
+				pdate="$(date -u -r $date)"
 				if [ "$pdate" ]; then
-					echo -n $color$key $rest | sed "s/>.*/> $pdate/"
-					echo $coldefault
+					echo -n $color$key $rest | sed "s/>.*/> $pdate/" 
+					echo -n $coldefault
 				else
 					echo $color$key $rest $coldefault
 				fi
@@ -168,11 +168,8 @@
 				if [ -n "$list_files" ]; then
 					list_commit_files "$tree1" "$tree2"
 				fi
-				echo; sed -re '
-					/ *Signed-off-by:.*/Is//'$colsignoff'&'$coldefault'/
-					/ *Acked-by:.*/Is//'$colsignoff'&'$coldefault'/
-					s/./    &/
-				'
+				echo; sed -e "/ *Signed-off-by:.*/s/ *Signed-off-by:.*/$colsignoff&$coldefault/" -e"/ *Acked-by:.*/s/ *Acked-by:.*/$colsignoff&$coldefault/" -e "s/./    &/"
+				
 				;;
 			*)
 				echo $colheader$key $rest $coldefault
Index: cg-status
===================================================================
--- 3a65f5fb53367c75f4f76aebed27a83d8679f068/cg-status  (mode:100755)
+++ 95770616edbd49c71dff9ca6e51e7abf449d35e7/cg-status  (mode:100755)
@@ -15,7 +15,7 @@
 
 {
 	git-ls-files -z -t --others --deleted --unmerged $EXCLUDE
-} | sort -z -k 2 | xargs -0 sh -c '
+} | sort -t '\0' -k 2 | xargs -0 sh -c '
 while [ "$1" ]; do
 	tag=${1% *};
 	filename=${1#* };
Petr Baudis· May 29, 2005, 23:16 UTC · re: Mark Allen · lore

Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort

Dear diary, on Mon, May 30, 2005 at 01:00:10AM CEST, I got a letter where Mark Allen <mrallen1@yahoo.com> told me that...

> Here're a couple of pretty simple patches against cg-log and cg-status (two cogito
> commands I use a lot) for the non-GNU (or at least older, forked GNU) tools on Darwin.
Show 6 quoted lines
> @@ -148,10 +148,10 @@
>                                 fi
> 
>                                 date=(${rest#*> })
> -                               pdate="$(showdate $date)"
> +                               pdate="$(date -u -r $date)"

Hmm, coudlnt' showdate be fixed instead then? And $date is not a file so -r $date makes no sense to me - what am I missing?

Show 5 quoted lines
>                                 if [ "$pdate" ]; then
> -                                       echo -n $color$key $rest | sed "s/>.*/> $pdate/"
> -                                       echo $coldefault
> +                                       echo -n $color$key $rest | sed "s/>.*/> $pdate/"
> +                                       echo -n $coldefault
I'm lost on this one too. Why do you introduce the -n?
Show 15 quoted lines
>                                 else
>                                         echo $color$key $rest $coldefault
>                                 fi
> @@ -168,11 +168,8 @@
>                                 if [ -n "$list_files" ]; then
>                                         list_commit_files "$tree1" "$tree2"
>                                 fi
> -                               echo; sed -re '
> -                                       / *Signed-off-by:.*/Is//'$colsignoff'&'$coldefault'/
> -                                       / *Acked-by:.*/Is//'$colsignoff'&'$coldefault'/
> -                                       s/./    &/
> -                               '
> +                               echo; sed -e "/ *Signed-off-by:.*/s/ *Signed-off-by:.*/$colsignoff&$coldefault/" -e"/
> +*Acked-by:.*/s/ *Acked-by:.*/$colsignoff&$coldefault/" -e "s/./    &/"
> +

Is it necessary to take away the newlines? What is the real problem, actually? Just the I flag?

Could you please sign the patch off, and send it as text/plain or inline the message body?

Thanks,
-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Mark Allen· May 29, 2005, 23:43 UTC · re: Petr Baudis · lore

Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort

--- Petr Baudis <pasky@ucw.cz> wrote:
Show 7 quoted lines
> Dear diary, on Mon, May 30, 2005 at 01:00:10AM CEST, I got a letter
> where Mark Allen <mrallen1@yahoo.com> told me that...
> > -                               pdate="$(showdate $date)"
> > +                               pdate="$(date -u -r $date)"
> 
> Hmm, coudlnt' showdate be fixed instead then? And $date is not a file so
> -r $date makes no sense to me - what am I missing?
There is no showdate(1) command on Darwin.  On Darwin, the date(1) command flags are

-u (show UTC) -r seconds

So `date -u -r $date` gives output like "Sun May 29 12:07:55 GMT 2005" instead of 1117336545

> I'm lost on this one too. Why do you introduce the -n?

Since I used date(1) above, I get an extra newline now when the date string is printed out. Using echo -n on the second echo stops that behavior. (This is perhaps a matter of taste; some people like lots of whitespace in headers, and some don't.)

Show 14 quoted lines
> > -                               echo; sed -re '
> > -                                       /
> *Signed-off-by:.*/Is//'$colsignoff'&'$coldefault'/
> > -                                       /
> *Acked-by:.*/Is//'$colsignoff'&'$coldefault'/
> > -                                       s/./    &/
> > -                               '
> > +                               echo; sed -e "/ *Signed-off-by:.*/s/
> *Signed-off-by:.*/$colsignoff&$coldefault/" -e"/
> > +*Acked-by:.*/s/ *Acked-by:.*/$colsignoff&$coldefault/" -e "s/./    &/"
> > +
> 
> Is it necessary to take away the newlines? What is the real problem,
> actually? Just the I flag?

Is it strictly necessary to take away the newlines? I don't know. To be honest, I didn't experiment too much with alternate implementations. But the I flag in the sed script, yes that is not understood by non-GNU sed. And the "-r" to sed itself is also problematic.

> Could you please sign the patch off, and send it as text/plain or inline the
> message body?
Modify cg-log and cg-status to work with non-GNU sed, sort and date
Signed-off-by: Mark Allen <mrallen1@yahoo.com>
---
commit 7e8fbf87acead0ee83afc4647228efdad0bbae2e
tree 50acf8ce23fee4ca6c9493b5f5959093e7579c74
parent d36ed1fd011d349ea2adc00456750b5b3da3a9cd
author Mark Allen <mallen@aeris.local> 1117409841 -0500
committer Mark Allen <mallen@aeris.local> 1117409841 -0500
 cg-log    |   15 +++++++--------
 cg-status |    2 +-
 2 files changed, 8 insertions(+), 9 deletions(-)
Show changes to diff +8 −9
Index: cg-log
===================================================================
--- 3a65f5fb53367c75f4f76aebed27a83d8679f068/cg-log  (mode:100755)
+++ 50acf8ce23fee4ca6c9493b5f5959093e7579c74/cg-log  (mode:100755)
@@ -148,10 +148,10 @@
                                fi
 
                                date=(${rest#*> })
-                               pdate="$(showdate $date)"
+                               pdate="$(date -u -r $date)"
                                if [ "$pdate" ]; then
-                                       echo -n $color$key $rest | sed "s/>.*/> $pdate/"
-                                       echo $coldefault
+                                       echo -n $color$key $rest | sed "s/>.*/> $pdate/" 
+                                       echo -n $coldefault
                                else
                                        echo $color$key $rest $coldefault
                                fi
@@ -168,11 +168,10 @@
                                if [ -n "$list_files" ]; then
                                        list_commit_files "$tree1" "$tree2"
                                fi
-                               echo; sed -re '
-                                       /
*Signed-off-by:.*/Is//'$colsignoff'&'$coldefault'/
-                                       / *Acked-by:.*/Is//'$colsignoff'&'$coldefault'/
-                                       s/./    &/
-                               '
+                               echo; sed -e "/ *Signed-off-by:.*/s/
*Signed-off-by:.*/$colsignoff&$coldefault/" 
+                               -e"/ *Acked-by:.*/s/
*Acked-by:.*/$colsignoff&$coldefault/" 
+                               -e "s/./    &/"
+
                                ;;
                        *)
                                echo $colheader$key $rest $coldefault
Index: cg-status
===================================================================
--- 3a65f5fb53367c75f4f76aebed27a83d8679f068/cg-status  (mode:100755)
+++ 50acf8ce23fee4ca6c9493b5f5959093e7579c74/cg-status  (mode:100755)
@@ -15,7 +15,7 @@
 
 {
        git-ls-files -z -t --others --deleted --unmerged $EXCLUDE
-} | sort -z -k 2 | xargs -0 sh -c '
+} | sort -t '\0' -k 2 | xargs -0 sh -c '
 while [ "$1" ]; do
        tag=${1% *};
        filename=${1#* };
Petr Baudis· May 29, 2005, 23:49 UTC · re: Mark Allen · lore

Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort

Dear diary, on Mon, May 30, 2005 at 01:43:26AM CEST, I got a letter where Mark Allen <mrallen1@yahoo.com> told me that...

Show 10 quoted lines
> --- Petr Baudis <pasky@ucw.cz> wrote:
> > Dear diary, on Mon, May 30, 2005 at 01:00:10AM CEST, I got a letter
> > where Mark Allen <mrallen1@yahoo.com> told me that...
> > > -                               pdate="$(showdate $date)"
> > > +                               pdate="$(date -u -r $date)"
> > 
> > Hmm, coudlnt' showdate be fixed instead then? And $date is not a file so
> > -r $date makes no sense to me - what am I missing?
> 
> There is no showdate(1) command on Darwin.  On Darwin, the date(1) command flags are

There's probably no showdate command at all. This is internal function defined in cg-Xlib. ;-)

Show 5 quoted lines
> -u (show UTC)
> -r seconds 
> 
> So `date -u -r $date` gives output like "Sun May 29 12:07:55 GMT 2005" instead of
> 1117336545
GNU date:
  -r, --reference=FILE      display the last modification time of FILE
Show 19 quoted lines
> > > -                               echo; sed -re '
> > > -                                       /
> > *Signed-off-by:.*/Is//'$colsignoff'&'$coldefault'/
> > > -                                       /
> > *Acked-by:.*/Is//'$colsignoff'&'$coldefault'/
> > > -                                       s/./    &/
> > > -                               '
> > > +                               echo; sed -e "/ *Signed-off-by:.*/s/
> > *Signed-off-by:.*/$colsignoff&$coldefault/" -e"/
> > > +*Acked-by:.*/s/ *Acked-by:.*/$colsignoff&$coldefault/" -e "s/./    &/"
> > > +
> > 
> > Is it necessary to take away the newlines? What is the real problem,
> > actually? Just the I flag?
> 
> Is it strictly necessary to take away the newlines? I don't know. To be honest, I didn't 
> experiment too much with alternate implementations. But the I flag in the sed script, 
> yes that is not understood by non-GNU sed. And the "-r" to sed itself is also
> problematic.

I think we don't really need -r anyway. Could you please try with the 'i' flag instead of 'I'? (The manpage is somewhat unclear on the difference and portability.) Also, could you try if it works with the newlines?

-- 
				Petr "Pasky" Baudis
Stuff: http://pasky.or.cz/
C++: an octopus made by nailing extra legs onto a dog. -- Steve Taylor
Alecs King· May 30, 2005, 17:00 UTC · re: Petr Baudis · lore

Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort

On Mon, May 30, 2005 at 01:49:11AM +0200, Petr Baudis wrote:
Show 30 quoted lines
> > > > -                               echo; sed -re '
> > > > -                                       /
> > > *Signed-off-by:.*/Is//'$colsignoff'&'$coldefault'/
> > > > -                                       /
> > > *Acked-by:.*/Is//'$colsignoff'&'$coldefault'/
> > > > -                                       s/./    &/
> > > > -                               '
> > > > +                               echo; sed -e "/
> > > > *Signed-off-by:.*/s/
> > > *Signed-off-by:.*/$colsignoff&$coldefault/" -e"/
> > > > +*Acked-by:.*/s/ *Acked-by:.*/$colsignoff&$coldefault/" -e "s/./
> > > > &/"
> > > > +
> > > 
> > > Is it necessary to take away the newlines? What is the real
> > > problem,
> > > actually? Just the I flag?
> > 
> > Is it strictly necessary to take away the newlines? I don't know. To
> > be honest, I didn't 
> > experiment too much with alternate implementations. But the I flag
> > in the sed script, 
> > yes that is not understood by non-GNU sed. And the "-r" to sed
> > itself is also
> > problematic.
> 
> I think we don't really need -r anyway. Could you please try with the
> 'i' flag instead of 'I'? (The manpage is somewhat unclear on the
> difference and portability.) Also, could you try if it works with the
> newlines?

-r here is for the 'I' (same as 'i') modifier, which means case insensitive. non-GNU sed might not have the '-r' option or the 'I' ('i') modifier.

I dunno about the strict rules of 'Signed-off-by' things but what i have seen are all _exactly_ of this form. I have never seen something like 'SIGNED-OFF-BY' or 'sIGneD-oFf-bY'.

If only the exact case sensitive form is allowed, then we can safely remove the '-r' and 'I'.

Also, to Mark, as a quick alternative to work around these sed issues, you can install the gsed port. IIRC, opendarwin has this port.

Speaking of other portability issues, i made up a patch to make cogito properly work under fbsd (without hurting others hopefully) weeks ago:

1) expr would regard a negative $dtz as an option (-xx).
2) coloring for both terminfo & termcap terminal.
Show changes to diff +9 −8
Index: cg-Xlib
===================================================================
--- de641904363cd3759f132ee7c0dfaf8a2ee58388/cg-Xlib  (mode:100755)
+++ 4e3c899dfa4a74effdb4ae23528785b8f688561d/cg-Xlib  (mode:100755)
@@ -43,7 +43,7 @@
 	date="$1"
 	sec=${date[0]}; tz=${date[1]}
 	dtz=${tz/+/}
-	lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec)
+	lsec=$(expr \( $dtz \) / 100 \* 3600 + \( $dtz \) % 100 \* 60 +
$sec)
 	pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)"
 
 	echo "${pdate/+0000/$tz}"
Index: cg-log
===================================================================
--- de641904363cd3759f132ee7c0dfaf8a2ee58388/cg-log  (mode:100755)
+++ 4e3c899dfa4a74effdb4ae23528785b8f688561d/cg-log  (mode:100755)
@@ -42,13 +42,14 @@
 	# TODO: Parse -r here too.
 	case "$1" in
 	-c)
-		# See terminfo(5), "Color Handling"
-		colheader="$(tput setaf 2)"    # Green
-		colauthor="$(tput setaf 6)"    # Cyan
-		colcommitter="$(tput setaf 5)" # Magenta
-		colfiles="$(tput setaf 4)"     # Blue
-		colsignoff="$(tput setaf 3)"   # Yellow
-		coldefault="$(tput op)"        # Restore default
+		# ANSI escape seq
+		esc=$(echo -e '\e')
+		colheader="${esc}[0;32m"    # Green
+		colauthor="${esc}[0;36m"    # Cyan
+		colcommitter="${esc}[0;35m" # Magenta
+		colfiles="${esc}[0;34m"     # Blue
+		colsignoff="${esc}[0;33m"   # Yellow
+		coldefault="${esc}[0m"      # Restore default
 		shift
 		;;
 	-f)
-- 
Alecs King
Mark Allen· May 31, 2005, 01:19 UTC · re: Petr Baudis · lore

Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort

--- Petr Baudis <pasky@ucw.cz> wrote:
> I think we don't really need -r anyway. Could you please try with the
> 'i' flag instead of 'I'? (The manpage is somewhat unclear on the
> difference and portability.) Also, could you try if it works with the
> newlines?

I tried with an i\ which is what the sed on Darwin wants, and it didn't work very well... so, I just removed the I and i\ and that worked pretty nicely. I shaved off the -r and made for a simpler patch.

I also added $has_gnudate to cg-Xlib and modified the logic in showdate to use the appropriate command depending on whether $has_gnudate is true or false.

Finally, I stripped the -z from sort because it seems to do the right thing anyway without it and it makes the sort on Darwin unhappy.

Anyway, here's another try, this against the tip of the most recent cogito tree.
---
Modify cg-log, cg-Xlib and cg-status for non-GNU sed, sort and date.
Signed-off-by: Mark Allen <mrallen1@yahoo.com>
Show changes to 3 files +13 −9

cg-Xlib, cg-log, cg-status

diff --git a/cg-Xlib b/cg-Xlib
--- a/cg-Xlib
+++ b/cg-Xlib
@@ -42,9 +42,13 @@ mktemp () {
 showdate () {
        date="$1"
        sec=${date[0]}; tz=${date[1]}
-       dtz=${tz/+/}
-       lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec)
-       pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)"
+       if [ ! "$has_gnudate" ]; then 
+               pdate="$(date -u -r ${date[0]} 2>/dev/null)"
+       else
+               dtz=${tz/+/}
+               lsec=$(expr $dtz / 100 \* 3600 + $dtz % 100 \* 60 + $sec)
+               pdate="$(date -Rud "1970-01-01 UTC + $lsec sec" 2>/dev/null)"
+       fi
 
        echo "${pdate/+0000/$tz}"
 }
@@ -137,3 +141,4 @@ fi
 
 export BROKEN_MKTEMP=1
 del=$($(which mktemp) -t 2>/dev/null) && { rm $del; export BROKEN_MKTEMP=; }
+has_gnudate=$(date -Rud "1970-01-01 UTC" 2>/dev/null)
diff --git a/cg-log b/cg-log
--- a/cg-log
+++ b/cg-log
@@ -190,8 +190,7 @@ $revls | $revsort | while read time comm
                                date=(${rest#*> })
                                pdate="$(showdate $date)"
                                if [ "$pdate" ]; then
-                                       echo -n $color$key $rest | sed "s/>.*/> 
$pdate/"
-                                       echo $coldefault
+                                       echo -n $color$key $rest | sed "s/>.*/> 
$pdate$coldefault/"
                                else
                                        echo $color$key $rest $coldefault
                                fi
@@ -208,9 +207,9 @@ $revls | $revsort | while read time comm
                                if [ -n "$list_files" ]; then
                                        list_commit_files "$tree1" "$tree2"
                                fi
-                               echo; sed -re '
-                                       / *Signed-off-by:.*/Is//'$colsignoff'&'$
coldefault'/
-                                       / *Acked-by:.*/Is//'$colsignoff'&'$colde
fault'/
+                               echo; sed -e '
+                                       / *Signed-off-by:.*/s//'$colsignoff'&'$c
oldefault'/
+                                       / *Acked-by:.*/s//'$colsignoff'&'$coldef
ault'/
                                        s/./    &/
                                '
                                ;;
diff --git a/cg-status b/cg-status
--- a/cg-status
+++ b/cg-status
@@ -41,7 +41,7 @@ fi
 
 {
        git-ls-files -z -t --others --deleted --unmerged $EXCLUDE
-} | sort -z -k 2 | xargs -0 sh -c '
+} | sort -k 2 | xargs -0 sh -c '
 while [ "$1" ]; do
        tag=${1% *};
        filename=${1#* };

← back to recent threads