git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort
@ 2005-05-29 23:00 Mark Allen
  2005-05-29 23:16 ` Petr Baudis
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Allen @ 2005-05-29 23:00 UTC (permalink / raw)
  To: git

[-- Attachment #1: Type: text/plain, Size: 583 bytes --]

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

[-- Attachment #2: 14121161-cogito-non-gnu.patch --]
[-- Type: application/octet-stream, Size: 1880 bytes --]


---
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(-)

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#* };

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort
  2005-05-29 23:00 [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort Mark Allen
@ 2005-05-29 23:16 ` Petr Baudis
  2005-05-29 23:43   ` Mark Allen
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Baudis @ 2005-05-29 23:16 UTC (permalink / raw)
  To: Mark Allen; +Cc: git

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.

> @@ -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?

>                                 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?

>                                 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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort
  2005-05-29 23:16 ` Petr Baudis
@ 2005-05-29 23:43   ` Mark Allen
  2005-05-29 23:49     ` Petr Baudis
  0 siblings, 1 reply; 6+ messages in thread
From: Mark Allen @ 2005-05-29 23:43 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

--- 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

-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.)

> > -                               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(-)

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#* };

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort
  2005-05-29 23:43   ` Mark Allen
@ 2005-05-29 23:49     ` Petr Baudis
  2005-05-30 17:00       ` Alecs King
  2005-05-31  1:19       ` Mark Allen
  0 siblings, 2 replies; 6+ messages in thread
From: Petr Baudis @ 2005-05-29 23:49 UTC (permalink / raw)
  To: Mark Allen; +Cc: git

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...
> --- 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. ;-)

> -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

> > > -                               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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort
  2005-05-29 23:49     ` Petr Baudis
@ 2005-05-30 17:00       ` Alecs King
  2005-05-31  1:19       ` Mark Allen
  1 sibling, 0 replies; 6+ messages in thread
From: Alecs King @ 2005-05-30 17:00 UTC (permalink / raw)
  To: git

On Mon, May 30, 2005 at 01:49:11AM +0200, Petr Baudis wrote:
> > > > -                               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.

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort
  2005-05-29 23:49     ` Petr Baudis
  2005-05-30 17:00       ` Alecs King
@ 2005-05-31  1:19       ` Mark Allen
  1 sibling, 0 replies; 6+ messages in thread
From: Mark Allen @ 2005-05-31  1:19 UTC (permalink / raw)
  To: Petr Baudis; +Cc: git

--- 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>

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#* };

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-05-31  1:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-29 23:00 [COGITO PATCH] Fix cg-log and cg-status for non-GNU sed/sort Mark Allen
2005-05-29 23:16 ` Petr Baudis
2005-05-29 23:43   ` Mark Allen
2005-05-29 23:49     ` Petr Baudis
2005-05-30 17:00       ` Alecs King
2005-05-31  1:19       ` Mark Allen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).