* Adapting scripts to work in current (not top) directory
@ 2005-05-12 13:58 Alexey Nezhdanov
2005-05-12 19:15 ` H. Peter Anvin
2005-05-12 20:12 ` Petr Baudis
0 siblings, 2 replies; 5+ messages in thread
From: Alexey Nezhdanov @ 2005-05-12 13:58 UTC (permalink / raw)
To: GIT Mailing List
All git and cogito scripts wants .git subdirectory. If I'm in a subdirectory
that have no .git direcory in it I'm out of luck.
I have wrote an example script that determines the lowest possible .git
directory position and changes to it to satisfy user request.
Problems with script:
1) May be I misunderstood the git ideology and it needs not this at all.
if point (1) is false then there are couple of other problems:
2) Script is extremelly ugly. I'm a week bash programmer so please criticize.
3) This logic shold be somehow embedded to all git- and cg- scripts. I can not
figure how to do it non-intruisively.
4) files and patch with spaces not supported. Probably fixable but first I
want to resolve points (1), (2) and (3)
===========================
#!/bin/bash
#
# Add new file to a GIT repository.
# Copyright (c) Petr Baudis, 2005
#
# Takes a list of file names at the command line, and schedules them
# for addition to the GIT repository at the next commit.
. ${COGITO_LIB:-/home/snake/lib/cogito/}cg-Xlib
[ "$1" ] || die "usage: cg-add FILE..."
gitpath=
subpath=
curpath=`pwd`
for ((i=2;i<9999;i=i+1)) ; do {
path1=`echo $curpath | cut -d / -f 0-$i`
path2=`echo $curpath | cut -d / -f $((i+1))-`
[ -d "$path1"/.git ] && gitpath=$path1 && subpath=$path2
[ "$path1" == "$curpath" ] && break
}; done
for file in "$@"; do
if [ -f "$file" ]; then
echo "Adding file $file"
else
die "$file does not exist"
fi
done
cd "$gitpath"
files=
for file in "$@"; do
files="$files $subpath/$file"
done
git-update-cache --add -- $files
===========================
--
Respectfully
Alexey Nezhdanov
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adapting scripts to work in current (not top) directory
2005-05-12 13:58 Adapting scripts to work in current (not top) directory Alexey Nezhdanov
@ 2005-05-12 19:15 ` H. Peter Anvin
2005-05-12 20:12 ` Petr Baudis
1 sibling, 0 replies; 5+ messages in thread
From: H. Peter Anvin @ 2005-05-12 19:15 UTC (permalink / raw)
To: Alexey Nezhdanov; +Cc: GIT Mailing List
Alexey Nezhdanov wrote:
> All git and cogito scripts wants .git subdirectory. If I'm in a subdirectory
> that have no .git direcory in it I'm out of luck.
> I have wrote an example script that determines the lowest possible .git
> directory position and changes to it to satisfy user request.
>
> Problems with script:
> 1) May be I misunderstood the git ideology and it needs not this at all.
>
Linus has explicitly said he doesn't want that.
-hpa
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adapting scripts to work in current (not top) directory
2005-05-12 13:58 Adapting scripts to work in current (not top) directory Alexey Nezhdanov
2005-05-12 19:15 ` H. Peter Anvin
@ 2005-05-12 20:12 ` Petr Baudis
2005-05-13 10:59 ` Alexey Nezhdanov
1 sibling, 1 reply; 5+ messages in thread
From: Petr Baudis @ 2005-05-12 20:12 UTC (permalink / raw)
To: Alexey Nezhdanov; +Cc: GIT Mailing List
Dear diary, on Thu, May 12, 2005 at 03:58:10PM CEST, I got a letter
where Alexey Nezhdanov <snake@penza-gsm.ru> told me that...
> All git and cogito scripts wants .git subdirectory. If I'm in a subdirectory
> that have no .git direcory in it I'm out of luck.
This is fine for Cogito, but Git itself shouldn't care - unless you mean
the bundled mini-plumbing scripts. I don't know if anyone (and who) uses
them except Linus, but I'm not likely to make much effort to maintain
them, or even to actually accept any non-trivial changes to them.
> I have wrote an example script that determines the lowest possible .git
> directory position and changes to it to satisfy user request.
>
> Problems with script:
> 1) May be I misunderstood the git ideology and it needs not this at all.
Cogito really needs it.
> if point (1) is false then there are couple of other problems:
> 2) Script is extremelly ugly. I'm a week bash programmer so please criticize.
> 3) This logic shold be somehow embedded to all git- and cg- scripts. I can not
> figure how to do it non-intruisively.
Add it to cg-Xlib. You can just update $_git appropriately. (Except when
you were explicitly passed GIT_DIR.)
> gitpath=
> subpath=
> curpath=`pwd`
> for ((i=2;i<9999;i=i+1)) ; do {
> path1=`echo $curpath | cut -d / -f 0-$i`
> path2=`echo $curpath | cut -d / -f $((i+1))-`
> [ -d "$path1"/.git ] && gitpath=$path1 && subpath=$path2
> [ "$path1" == "$curpath" ] && break
> }; done
I would gradually trim the $curpath by $(dirname) until I hit
$curpath/.git or the root directory.
--
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] 5+ messages in thread
* Re: Adapting scripts to work in current (not top) directory
2005-05-12 20:12 ` Petr Baudis
@ 2005-05-13 10:59 ` Alexey Nezhdanov
2005-05-13 13:53 ` Petr Baudis
0 siblings, 1 reply; 5+ messages in thread
From: Alexey Nezhdanov @ 2005-05-13 10:59 UTC (permalink / raw)
To: git
On Friday, 13 May 2005 00:12 Petr Baudis wrote:
> Dear diary, on Thu, May 12, 2005 at 03:58:10PM CEST, I got a letter
> where Alexey Nezhdanov <snake@penza-gsm.ru> told me that...
>
> > All git and cogito scripts wants .git subdirectory. If I'm in a
> > subdirectory that have no .git direcory in it I'm out of luck.
>
> This is fine for Cogito, but Git itself shouldn't care - unless you mean
> the bundled mini-plumbing scripts. I don't know if anyone (and who) uses
> them except Linus, but I'm not likely to make much effort to maintain
> them, or even to actually accept any non-trivial changes to them.
>
> > I have wrote an example script that determines the lowest possible .git
> > directory position and changes to it to satisfy user request.
> >
> > Problems with script:
> > 1) May be I misunderstood the git ideology and it needs not this at all.
>
> Cogito really needs it.
Ok, so sticking with cogito.
> > if point (1) is false then there are couple of other problems:
> > 2) Script is extremelly ugly. I'm a week bash programmer so please
> > criticize.
> > 3) This logic shold be somehow embedded to all git- and cg-
> > scripts. I can not figure how to do it non-intruisively.
>
> Add it to cg-Xlib. You can just update $_git appropriately. (Except when
> you were explicitly passed GIT_DIR.)
ok, that's easy.
>
> > gitpath=
> > subpath=
> > curpath=`pwd`
> > for ((i=2;i<9999;i=i+1)) ; do {
> > path1=`echo $curpath | cut -d / -f 0-$i`
> > path2=`echo $curpath | cut -d / -f $((i+1))-`
> > [ -d "$path1"/.git ] && gitpath=$path1 && subpath=$path2
> > [ "$path1" == "$curpath" ] && break
> > }; done
>
> I would gradually trim the $curpath by $(dirname) until I hit
> $curpath/.git or the root directory.
I have opted for current directory and not root. Explanation is later this
mail. New variant:
=========================
--- /home/snake/scm/cogito/cg-Xlib 2005-05-12 08:47:29.000000000 +0400
+++ cg-Xlib 2005-05-13 13:40:58.000000000 +0400
@@ -8,7 +8,17 @@
_cg_cmd=${0##*/}
-_git=${GIT_DIR:-.git}
+repopath=`pwd`
+while ((1)) ; do {
+ [ -d "$repopath/.git" ] && break
+ [ "$repopath" == "/" ] && {
+ repopath=`pwd`;
+ break;
+ };
+ repopath=`dirname $repopath`
+}; done
+
+_git=${GIT_DIR:-$repopath/.git}
_git_objects=${GIT_OBJECT_DIRECTORY:-$_git/objects}
=========================
Here is a problem:
Because of git backend only some of the commands should be enabled to work
from current directory. F.e. cg-init should not scan upper directories for
".git" but should instead stick to current directory. In the script above
this workarounded as choosing current directory instead of root but this will
broke if we trying to initialise repo in a subdirectory of another repo.
So I have analysed list of cogito commands to find out which ones should be
adopted to use "find repo" behaivoir:
"+" means "definitely yes"
"-" means "definitely no"
"?" means "not sure"
"." means "not matter"
+ cg-add
? cg-admin-lsobj
- cg-admin-uncommit
? cg-branch-add
? cg-branch-ls
- cg-cancel
- cg-clone
- cg-commit
+ cg-diff
- cg-export
. cg-help
- cg-init
+ cg-log
+ cg-ls
- cg-merge
+ cg-mkpatch
? cg-patch
- cg-pull
- cg-restore
+ cg-rm
- cg-seek
+ cg-status
- cg-tag
? cg-tag-ls
- cg-update
. cg-version
Any opinions?
--
Respectfully
Alexey Nezhdanov
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Adapting scripts to work in current (not top) directory
2005-05-13 10:59 ` Alexey Nezhdanov
@ 2005-05-13 13:53 ` Petr Baudis
0 siblings, 0 replies; 5+ messages in thread
From: Petr Baudis @ 2005-05-13 13:53 UTC (permalink / raw)
To: Alexey Nezhdanov; +Cc: git
Dear diary, on Fri, May 13, 2005 at 12:59:08PM CEST, I got a letter
> I have opted for current directory and not root. Explanation is later this
> mail. New variant:
Yes, that's fine.
> =========================
> --- /home/snake/scm/cogito/cg-Xlib 2005-05-12 08:47:29.000000000 +0400
> +++ cg-Xlib 2005-05-13 13:40:58.000000000 +0400
> @@ -8,7 +8,17 @@
>
> _cg_cmd=${0##*/}
>
> -_git=${GIT_DIR:-.git}
> +repopath=`pwd`
> +while ((1)) ; do {
> + [ -d "$repopath/.git" ] && break
> + [ "$repopath" == "/" ] && {
> + repopath=`pwd`;
> + break;
> + };
> + repopath=`dirname $repopath`
> +}; done
> +
> +_git=${GIT_DIR:-$repopath/.git}
> _git_objects=${GIT_OBJECT_DIRECTORY:-$_git/objects}
Looks basically fine.
> =========================
> Here is a problem:
> Because of git backend only some of the commands should be enabled to work
> from current directory. F.e. cg-init should not scan upper directories for
> ".git" but should instead stick to current directory. In the script above
> this workarounded as choosing current directory instead of root but this will
> broke if we trying to initialise repo in a subdirectory of another repo.
I'd set some flag like $reposubdir if .git was found in some of the
parent directories. Then test that in the relevant commands.
> So I have analysed list of cogito commands to find out which ones should be
> adopted to use "find repo" behaivoir:
>
> "+" means "definitely yes"
> "-" means "definitely no"
> "?" means "not sure"
> "." means "not matter"
>
> + cg-add
> ? cg-admin-lsobj
Sure.
> - cg-admin-uncommit
> ? cg-branch-add
> ? cg-branch-ls
Sure (both).
> - cg-cancel
> - cg-clone
> - cg-commit
This one should, committing only the subdirectory content.
> + cg-diff
> - cg-export
Perhaps it could export just the subdirectory?
> . cg-help
> - cg-init
> + cg-log
> + cg-ls
(Listing the appropriate subdir.)
> - cg-merge
> + cg-mkpatch
> ? cg-patch
This one should, using the appropriate -p level.
> - cg-pull
> - cg-restore
This one should, restoring only the subdirectory.
> + cg-rm
> - cg-seek
> + cg-status
> - cg-tag
> ? cg-tag-ls
Why not...
> - cg-update
> . cg-version
--
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] 5+ messages in thread
end of thread, other threads:[~2005-05-13 13:46 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-12 13:58 Adapting scripts to work in current (not top) directory Alexey Nezhdanov
2005-05-12 19:15 ` H. Peter Anvin
2005-05-12 20:12 ` Petr Baudis
2005-05-13 10:59 ` Alexey Nezhdanov
2005-05-13 13:53 ` Petr Baudis
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).