git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Ping Yin <pkufranky@gmail.com>
Cc: git@vger.kernel.org, gitster@pobox.com
Subject: Re: [PATCH 2/5] git-submodule: New subcommand 'summary' (2) - hard work
Date: Sat, 12 Jan 2008 00:32:15 -0800	[thread overview]
Message-ID: <7vejcnv3zk.fsf@gitster.siamese.dyndns.org> (raw)
In-Reply-To: <62a73e734832ad67e89be706f1f8b3dbc30cfcf4.1200122041.git.pkufranky@gmail.com> (Ping Yin's message of "Sat, 12 Jan 2008 15:37:12 +0800")

Ping Yin <pkufranky@gmail.com> writes:

> +	git diff $cache_option --raw $head -- $modules |
> +	grep '^:160000\|:000000 160000' |
> +	cut -c2- |
> +	while read mod_src mod_dst sha1_src sha1_dst status name
> +	do
> +		sha1_dst=$(echo $sha1_dst | cut -c1-7)
> +		sha1_src=$(echo $sha1_src | cut -c1-7)

If you are willing to lose precision forever like this, I think
you can run "git diff" with --abbrev and lose this cut.

> +		check_dst=t
> +		check_src=t
> +		case $status in
> +		D)
> +			check_dst=
> +			;;
> +		A)
> +			check_src=
> +			;;

I'd loosen the above grep (see my comments to your 1/5) and also
add this:

		*)
			continue ;# punt
			;;

so that the rest of the code won't break when seeing a path that
was submodule in the HEAD but is a blob in the index.

> +		esac
> +
> +		(
> +			errmsg=
> +			unfound_src=
> +			unfound_dst=
> +
> +			test -z "$check_src" ||
> +			GIT_DIR="$name/.git" git-rev-parse $sha1_src >&/dev/null ||

And the precision of $sha1_src matter here.  Be it done with
"diff --abbrev" at the toplevel or your "cut", that may not be
unique enough in the submodule.

I think you would want to read full 40-char sha1_src and
sha1_dst with "while read", and keep that full 40-char in these
variables, and use them when calling rev-parse here.

If you are checking if that the object exists in the submodule,
use "rev-parse --verify", which was designed for exactly that
purpose.  If you also want to verify if the object is a commit,
which may be a good idea anyway, "rev-parse --verify $sha1_src^0".

To be portable, use traditional ">/dev/null 2>&1", not ">&/dev/null".

> +			case "$unfound_src,$unfound_dst" in
> +			t,)
> +				errmsg="  Warn: $name doesn't contain commit $sha1_src"
> +				;;
> +			,t)
> +				errmsg="  Warn: $name doesn't contain commit $sha1_dst"
> +				;;
> +			t,t)
> +				errmsg="  Warn: $name doesn't contain commits $sha1_src and $sha1_dst"
> +				;;

When reporting errors, you would want to give full 40-chars...

> +			*)
> +				left=
> +				right=
> +				test -n "$check_src" &&
> +				left=$(GIT_DIR="$name/.git" git log --pretty=format:"  <%s" \
> +				${check_dst:+$sha1_dst..}$sha1_src 2>/dev/null)
> +
> +				test -n "$check_dst" &&
> +				right=$(GIT_DIR="$name/.git" git log --reverse --pretty=format:"  >%s" \
> +				${check_src:+$sha1_src..}$sha1_dst 2>/dev/null)
> +				;;
> +			esac
> +
> +			echo "* $name $sha1_src...$sha1_dst:"

While reporting like this, you would want the shortened form,
perhaps produced your "cut -c1-7".

> +			if test -n "$errmsg"
> +			then
> +				echo "$errmsg"
> +			else
> +				test -n "$left" && echo "$left"
> +				test -n "$right" && echo "$right"
> +			fi
> +			echo
> +		) | sed 's/^/# /'
> +	done

I'd prefer to always have "-e" before the sed expression.

Any reason why you want separate invocation of sed inside the
while loop?  IOW, why isn't it like this?

	git diff --raw |
        while read ...
        do
        	...
	done | sed -e 's/^/# /'

> +
>  	cd "$cwd"

Hmmm.

  parent reply	other threads:[~2008-01-12  8:32 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-01-12  7:37 [PATCH 0/5] submodule summary support Ping Yin
2008-01-12  7:37 ` [PATCH 1/5] git-submodule: New subcommand 'summary' (1) - code framework Ping Yin
2008-01-12  7:37   ` [PATCH 2/5] git-submodule: New subcommand 'summary' (2) - hard work Ping Yin
2008-01-12  7:37     ` [PATCH 3/5] git-submodule: New subcommand 'summary' (3) - limit summary size Ping Yin
2008-01-12  7:37       ` [PATCH 4/5] git-status: submodule summary support Ping Yin
2008-01-12  7:37         ` [PATCH 5/5] git-status: configurable submodule summary size Ping Yin
2008-01-12  8:36       ` [PATCH 3/5] git-submodule: New subcommand 'summary' (3) - limit " Junio C Hamano
2008-01-12  9:51         ` Ping Yin
2008-01-12 19:17           ` Junio C Hamano
2008-01-13  6:38             ` Ping Yin
2008-01-12  8:32     ` Junio C Hamano [this message]
2008-01-12  9:48       ` [PATCH 2/5] git-submodule: New subcommand 'summary' (2) - hard work Ping Yin
2008-01-12 12:24         ` Ping Yin
2008-01-12 19:21           ` Junio C Hamano
2008-01-12 11:12     ` Ping Yin
2008-01-12 19:25       ` Junio C Hamano
2008-01-13  6:28         ` Ping Yin
2008-01-12  8:18   ` [PATCH 1/5] git-submodule: New subcommand 'summary' (1) - code framework Junio C Hamano
2008-01-12  9:09     ` Ping Yin

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=7vejcnv3zk.fsf@gitster.siamese.dyndns.org \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=pkufranky@gmail.com \
    /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 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).