# $Revision$ keyword replacement?

4 messages from 2005-11-22 to 2005-11-22. Participants: Santi Béjar, Junio C Hamano, Santi Bejar.
Thread: https://gitlist.dev/t/2653

## Santi Béjar, 2005-11-22 17:36

Subject: $Revision$ keyword replacement?
Message-ID: <871x18h9ee.fsf@ifae.es>
URL: https://gitlist.dev/e/871x18h9ee.fsf%40ifae.es

```
Hello:

        I'm looking for a $Revision$ replacement. I know, in git all that
        matters are the contents. So the equivalent in git could be:

        How similar this file is to the file $path in these commit(s)?

        What I use now is an ugly shell script (as you might known
        I'm not a C programer), see the attatchment.

        So I get:

311bf741d16ee5d0166639a4fafd9194e504aad3:R094   introduccio.tex sim.tex
b764ee049289f5157238596cccc7a4e15f23896c:R094   introduccio.tex sim.tex
f293e1ab1dfb7ff60cb269ed5b18f9222099a752:R098   introduccio.tex sim.tex
f14c4b2d6799354d376e2026a5b7a85ccce48284:R098   introduccio.tex sim.tex
183af55606310218ca0e9a735dad0827acea7910:R098   introduccio.tex sim.tex
73fd2531cce3db0ca804577fb29f87f413fc4563:R096   introduccio.tex sim.tex

        Do you know any other (or better :) way to do it?

        Thanks

        Santi



#!/bin/sh
##
## find-sim finds the similarity of one file with the files in the
##           selected commits
##
## The arguments are:
##      $1     - file to compare
##      $n n>2 - arguments for git-rev-list to select the commits
##
. git-sh-setup || die "Not a git archive."

[ ! -e $1 ] && exit 1
file=$1
shift

case $GIT_DIR in
    /*)
	GIT_DIR_ORIG=$GIT_DIR;;
    *)
	GIT_DIR_ORIG=$PWD/$GIT_DIR
esac

tmp=`mktemp -t -d git-find-sim.XXXXXXX`
GIT_DIR_TEMP=$tmp
mkdir -p $GIT_DIR_TEMP/objects/info
[ -e $GIT_DIR_ORIG/objects/info/alternates ] &&
cp $GIT_DIR_ORIG/objects/info/alternates $GIT_DIR_TEMP/objects/info/alternates
echo $GIT_DIR_ORIG/objects >> $GIT_DIR_TEMP/objects/info/alternates
export GIT_DIR=$GIT_DIR_TEMP

trap "rm -rf $tmp" 0 1 2 3 15

git update-index --add $file || exit 1
tree=`git-write-tree`

rev_arg=`GIT_DIR=$GIT_DIR_ORIG git-rev-parse --default HEAD --revs-only "$@"`
revs=`GIT_DIR=$GIT_DIR_ORIG git-rev-list $rev_arg`
for i in $revs; do
    git diff-tree --name-status $i -C $tree | grep $file |
    sed "s/^/$i:/"
done

```

## Junio C Hamano, 2005-11-22 22:42

Subject: finding similar blobs (was: Re: $Revision$ keyword replacement?
Message-ID: <7vy83gb8zk.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vy83gb8zk.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <871x18h9ee.fsf@ifae.es>

```
Santi Béjar <sbejar@gmail.com> writes:

>         How similar this file is to the file $path in these commit(s)?

Very cute.

> tmp=`mktemp -t -d git-find-sim.XXXXXXX`
> ...
> git update-index --add $file || exit 1
> tree=`git-write-tree`

Are you going through all this trouble just to avoid a blob and
a tree object left dangling after you are done?  Or is there
something else going on?

> rev_arg=`GIT_DIR=$GIT_DIR_ORIG git-rev-parse --default HEAD --revs-only "$@"`
> revs=`GIT_DIR=$GIT_DIR_ORIG git-rev-list $rev_arg`
> for i in $revs; do
>     git diff-tree --name-status $i -C $tree | grep $file |
>     sed "s/^/$i:/"
> done

Perhaps

        GIT_DIR=$GIT_DIR_ORIG git-rev-list $rev_arg |
        while read one
            git diff-tree --name-status -r $one -C $tree | grep $file |
            sed "s/^/$one:/"
        done

just in case the similar file you will discover is hidden in a
subdirectory?

```

## Santi Bejar, 2005-11-22 23:10

Subject: Re: finding similar blobs (was: Re: $Revision$ keyword replacement?
Message-ID: <8aa486160511221510v667dbfd5y@mail.gmail.com>
URL: https://gitlist.dev/e/8aa486160511221510v667dbfd5y%40mail.gmail.com
In-Reply-To: <7vy83gb8zk.fsf@assigned-by-dhcp.cox.net>

```
2005/11/22, Junio C Hamano <junkio@cox.net>:
> Santi Béjar <sbejar@gmail.com> writes:
>

>
> > tmp=`mktemp -t -d git-find-sim.XXXXXXX`
> > ...
> > git update-index --add $file || exit 1
> > tree=`git-write-tree`
>
> Are you going through all this trouble just to avoid a blob and
> a tree object left dangling after you are done?  Or is there
> something else going on?

No, there is nothing else. These are "easy" avoided, so why have these
dangling {blob,tree,...}s?

>
> > rev_arg=`GIT_DIR=$GIT_DIR_ORIG git-rev-parse --default HEAD --revs-only "$@"`
> > revs=`GIT_DIR=$GIT_DIR_ORIG git-rev-list $rev_arg`
> > for i in $revs; do
> >     git diff-tree --name-status $i -C $tree | grep $file |
> >     sed "s/^/$i:/"
> > done
>
> Perhaps
>
>         GIT_DIR=$GIT_DIR_ORIG git-rev-list $rev_arg |
>         while read one
>             git diff-tree --name-status -r $one -C $tree | grep $file |
>             sed "s/^/$one:/"
>         done
>
> just in case the similar file you will discover is hidden in a
> subdirectory?

Oops :)

Santi

```

## Junio C Hamano, 2005-11-22 23:40

Subject: Re: finding similar blobs (was: Re: $Revision$ keyword replacement?
Message-ID: <7vmzjwb6an.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vmzjwb6an.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <8aa486160511221510v667dbfd5y@mail.gmail.com>

```
Santi Bejar <sbejar@gmail.com> writes:

> No, there is nothing else. These are "easy" avoided, so why have these
> dangling {blob,tree,...}s?

Only because I am lazy ;-).

```
