[PATCH] Catch more exceptions in compat_log_entry()

2013-10-22 Thread Pavel Roskin
Catch exceptions in default_repo().  Catch git.RepositoryException.
This suppresses stack trace in stg pull on detached head and outside
the repository.

Signed-off-by: Pavel Roskin pro...@gnu.org
---
 stgit/lib/log.py |4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/stgit/lib/log.py b/stgit/lib/log.py
index dfadd51..d876ff6 100644
--- a/stgit/lib/log.py
+++ b/stgit/lib/log.py
@@ -359,10 +359,10 @@ class Fakestack(object):
 def compat_log_entry(msg):
 Write a new log entry. (Convenience function intended for use by
 code not yet converted to the new infrastructure.)
-repo = default_repo()
 try:
+repo = default_repo()
 stack = repo.get_stack(repo.current_branch_name)
-except libstack.StackException, e:
+except (libstack.StackException, git.RepositoryException), e:
 out.warn(str(e), 'Could not write to stack log')
 else:
 if repo.default_index.conflicts() and stack.patchorder.applied:
--
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Improve can_hardlink diagnostics, remove suggest_hardlink

2005-08-23 Thread Pavel Roskin
Hello!

suggest_hardlink is write-only in cg-pull - remove it.  can_hardlink
should not be shown to the user as is (it's either l or empty) - we
should output something meaningful instead.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/cg-pull b/cg-pull
--- a/cg-pull
+++ b/cg-pull
@@ -207,7 +207,6 @@ fetch_local()
cp_flags_l=-vdpR
if [ $1 = -u ]; then
cp_flags_l=$cp_flags_l -fu$can_hardlink
-   suggest_hardlink=
shift
fi
 
@@ -293,12 +292,16 @@ else
symlinked=
is_same_repo $_git_objects $uri/objects  symlinked=1
 
-   # See if we can hardlink and drop l if not.
+   # See if we can hardlink and add -l to cp flags.
can_hardlink=
sample_file=$(find $uri -type f -print | head -n 1)
rm -f $_git/.,,lntest
-   ln $sample_file $_git/.,,lntest 2/dev/null  can_hardlink=l
-   echo $can_hardlink
+   if cp -fl $sample_file $_git/.,,lntest 2/dev/null; then
+   can_hardlink=l
+   echo Using hard links
+   else
+   echo Hard links don't work - using copy
+   fi
rm -f $_git/.,,lntest
 fi
 


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cg-pull to stop treating master specially, fix fetch_local for .git/HEAD

2005-08-23 Thread Pavel Roskin
Hello!

This patch changes cg-pull so that if the branch is not specified, it
takes origin's .git/HEAD without first trying .git/refs/heads/master.
This removes preferential treatment of the master branch, allowing the
upstream to use another name for the default branch.  To get the master
branch, users would have to append #master to the URL.

Local URL handling needs to be fixed to handle .git/HEAD properly, since
it's a symlink in the upstream directory.  A new flag -b for fetch_*
functions is introduced, meaning dereference (like in GNU cp).

To do: the code needs refactoring with better option handling.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/cg-pull b/cg-pull
--- a/cg-pull
+++ b/cg-pull
@@ -67,6 +67,8 @@ pull_progress()
 
 fetch_rsync()
 {
+   [ $1 = -b ]  shift
+
redir=
if [ $1 = -i ]; then # ignore-errors
redir=2/dev/null
@@ -108,6 +110,7 @@ pull_rsync()
 
 fetch_http()
 {
+   [ $1 = -b ]  shift
[ $1 = -i ]  shift
[ $1 = -s ]  shift
 
@@ -158,6 +161,7 @@ pull_http()
 
 fetch_ssh()
 {
+   [ $1 = -b ]  shift
[ $1 = -i ]  shift
[ $1 = -s ]  shift
 
@@ -205,6 +209,11 @@ fetch_local()
[ $1 = -s ]  shift
 
cp_flags_l=-vdpR
+   if [ $1 = -b ]; then
+   cp_flags_l=-vb # Dereference symlinks
+   shift
+   fi
+
if [ $1 = -u ]; then
cp_flags_l=$cp_flags_l -fu$can_hardlink
suggest_hardlink=
@@ -255,7 +264,7 @@ name=${ARGS[0]}
 [ $name ] || die where to pull from?
 uri=$(cat $_git/branches/$name 2/dev/null) || die unknown branch: $name
 
-rembranch=master
+rembranch=
 if echo $uri | grep -q '#'; then
rembranch=$(echo $uri | cut -d '#' -f 2)
uri=$(echo $uri | cut -d '#' -f 1)
@@ -308,13 +317,13 @@ orig_head=
 
 
 mkdir -p $_git/refs/heads
-rsyncerr=
-$fetch -i $uri/refs/heads/$rembranch $_git/refs/heads/.$name-pulling || 
rsyncerr=1
-if [ $rsyncerr ]  [ $rembranch = master ]; then
-   rsyncerr=
-   $fetch -s $uri/HEAD $_git/refs/heads/.$name-pulling || rsyncerr=1
+if [ $rembranch ]; then
+   $fetch -i $uri/refs/heads/$rembranch 
$_git/refs/heads/.$name-pulling ||
+   die unable to get the head pointer of branch $rembranch
+else
+   $fetch -b -s $uri/HEAD $_git/refs/heads/.$name-pulling ||
+   die unable to get the HEAD branch
 fi
-[ $rsyncerr ]  die unable to get the head pointer of branch $rembranch
 
 new_head=$(cat $_git/refs/heads/.$name-pulling)
 if ! [ $symlinked ]; then


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] cg-admin-cat ignoring -r

2005-08-16 Thread Pavel Roskin
Hello!

cg-admin-cat ignores the argument for the -r option because it uses
optparse incorrectly.  For OPTARG to be set, -r= should be used
instead of -r.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/cg-admin-cat b/cg-admin-cat
--- a/cg-admin-cat
+++ b/cg-admin-cat
@@ -27,7 +27,7 @@ USAGE=cg-admin-cat [-r TREE_ID] FILE...
 
 rev=HEAD
 while optparse; do
-   if optparse -r; then
+   if optparse -r=; then
rev=$OPTARG
else
optfail


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] commit-id, tree-id fail on tags

2005-08-16 Thread Pavel Roskin
Hello!

Tag names don't work with current cogito because commit-id and tree-id
don't parse the cg-Xnormid output properly.

Namely, if $type is empty (which is the case for tags), $normid is used
before the trailing space is stripped from it.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/commit-id b/commit-id
--- a/commit-id
+++ b/commit-id
@@ -9,8 +9,9 @@
 
 id=$1
 normid=$(. ${COGITO_LIB}cg-Xnormid $id) || exit 1
-type=${normid#* }; [ $type ] || type=$(git-cat-file -t $normid)
+type=${normid#* }
 normid=${normid% *}
+[ $type ] || type=$(git-cat-file -t $normid)
 
 if [ $type != commit ]; then
echo Invalid commit id: $normid 2
diff --git a/tree-id b/tree-id
--- a/tree-id
+++ b/tree-id
@@ -7,8 +7,9 @@
 
 id=$1
 normid=$(. ${COGITO_LIB}cg-Xnormid $id) || exit 1
-type=${normid#* }; [ $type ] || type=$(git-cat-file -t $normid)
+type=${normid#* }
 normid=${normid% *}
+[ $type ] || type=$(git-cat-file -t $normid)
 
 if [ $type = commit ]; then
normid=$(git-cat-file commit $normid | sed -e 's/tree //;q')


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] Trapping exit in tests, using return for errors

2005-08-11 Thread Pavel Roskin
Hi, Junio!

On Wed, 2005-08-10 at 23:31 -0700, Junio C Hamano wrote:
 Junio C Hamano [EMAIL PROTECTED] writes:
 
  Sorry, sent it out without finishing.  The worst is return.
 
 Ah, my mistake.  You have the eval that can eval return in a
 function and let that return return from that function.
 Cleverly done.

I'm glad you appreciate it.  One more fix on top of the last patch is
needed.

return from a test would leave the exit trap set, which could cause a
spurious error message if it's the last test in the script or
--immediate is used.

The easiest solution would be to have a global trap that is set when
test-lib.sh is sourced and unset either by test_done(), error() or by
test_failure_() with --immediate.  This patch also depends on the patch
that adds test_done() the the scripts that don't have it.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/t/test-lib.sh b/t/test-lib.sh
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -36,6 +36,7 @@ unset SHA1_FILE_DIRECTORY
 
 error () {
echo * error: $*
+   trap - exit
exit 1
 }
 
@@ -74,6 +75,8 @@ fi
 test_failure=0
 test_count=0
 
+trap 'echo 5 FATAL: Unexpected exit with code $?; exit 1' exit
+
 
 # You are not expected to call test_ok_ and test_failure_ directly, use
 # the text_expect_* functions instead.
@@ -89,7 +92,7 @@ test_failure_ () {
say FAIL $test_count: $1
shift
echo $@ | sed -e 's/^//'
-   test $immediate ==  || exit 1
+   test $immediate ==  || { trap - exit; exit 1; }
 }
 
 
@@ -98,10 +101,8 @@ test_debug () {
 }
 
 test_run_ () {
-   trap 'echo 5 FATAL: Unexpected exit with code $?; exit 1' exit
eval 3 24 $1
eval_ret=$?
-   trap - exit
return 0
 }
 
@@ -132,6 +133,7 @@ test_expect_success () {
 }
 
 test_done () {
+   trap - exit
case $test_failure in
0)  
# We could:


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: New script: cg-clean

2005-08-11 Thread Pavel Roskin
Hi, Petr!

Unfortunately, my latest revision of cg-clean has committed suicide
just when I was about to post it.  Anyway, I would prefer to wait until
you apply my patch to cg-status to ignore all ignores.  That would allow
me to reuse cg-status.

On Fri, 2005-08-12 at 01:29 +0200, Petr Baudis wrote:
  Here's the simplified cg-clean script.  Note that the -d option is not
  working with the current version of git of a bug in git-ls-files.  I can
  work it around by scanning all directories in bash, but I think it's
  easier to fix git (remove continue before DT_REG in ls-files.c).
 
 Is that fixed already?

It turn out it's quite tricky.  git-ls-files doesn't distinguish between
known and unknown directories.  One way to do it would be to check all
cached files and find all directories they are in.  Another approach
would involve git-ls-tree -r, but I don't think it would be right
because we work with cache and current files, not with committed data
(but my knowledge is limited to make a call - I still need to read the
documentation about git).

What I did was following:

git-ls-files --cached is run, directories are extracted, sorted but
sort -u and put to a temporary file dirlist1.  find -type d is run,
.git is filtered out, the list is merged with dirlist1, sorted by
sort -u, and put to dirlist2.  dirlist1 and dirlist2 are compared by
diff, the entries in dirlist2 are unknown directories.  (That's the kind
of task where Perl hashes would be great).  A technical detail - both
lists are limited to $_git_relpath if it's defined.

  Processing of .gitignore was taken from cg-status, and I don't really
  understand it.  But I think it's important to keep that code in sync.
  It could later go to cg-Xlib.
 
 It became much simpler a short while later, thankfully. Judging from
 your another patch, I suppose you are going to update this script
 accordingly?

Yes, I'm going to use cg-status -w for files.

  # -d::
  #   Also clean directories.
 
 Perhaps add and their contents to prevent bad surprises.

Too late :-)

  filelist=$(mktemp -t gitlsfiles.XX)
  git-ls-files --others $EXCLUDE $filelist
  save_IFS=$IFS
  IFS=$'\n'
  for file in $(cat $filelist); do
 
 Why can't you use git-ls-files | IFS=$'\n' while ?

Good idea.

  IFS=$save_IFS
  if [ -d $file ]; then
  if [ $cleandir ]; then
  # Try really hard by changing permissions
  chmod -R 700 $file
  rm -rf $file
  fi
 
 An error message would be in order otherwise, I guess.

You mean, list directories if -d is not specified?  Good idea.  Also,
the latest revision included the -v option for verbose - it would
show everything that gets deleted.

  return
 
 I suppose you mean continue? I'm not really sure what does return do
 here, if it jumps out of the do block or what, and continue is nicely
 explicit. :-)

My error, it was fixed soon after I posted the script.

-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Need to set PAGER in tests

2005-08-10 Thread Pavel Roskin
Hello!

t5400-send-pack.sh --verbose stops waiting for user input.  It happens
because git log uses less for output now.  To prevent this, PAGER
should be set to cat.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/t/test-lib.sh b/t/test-lib.sh
--- a/t/test-lib.sh
+++ b/t/test-lib.sh
@@ -5,8 +5,9 @@
 
 # For repeatability, reset the environment to known value.
 LANG=C
+PAGER=cat
 TZ=UTC
-export LANG TZ
+export LANG PAGER TZ
 unset AUTHOR_DATE
 unset AUTHOR_EMAIL
 unset AUTHOR_NAME

-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Trapping exit in tests, using return for errors

2005-08-10 Thread Pavel Roskin
Hello!

I have noticed that make test fails without any explanations when the
merge utility is missing.  I don't think tests should be silent in
case of failure.

It turned out that the particular test was using exit to interrupt the
test in case of an error.  This caused the whole test script to exit.
No further tests would be run even if --immediate wasn't specified.
No error message was printed.

This patch does following:

All instances of exit, exit 1 and (exit 1) in tests have been
replaced with return 1.  In fact, (exit 1) had no effect.

File descriptor 5 is duplicated from file descriptor 1.  This is needed
to print important error messages from tests.

New function test_run_() has been introduced.  Any return in the test
would merely cause that function to return without skipping calls to
test_failure_() and test_ok_().  The new function also traps exit and
treats it like a fatal error (in case somebody reintroduces exit in
the tests).

test_expect_failure() and test_expect_success() check both the result of
eval and the return value of test_run_().  If the later is not 0, it's
always a failure because it indicates the the test didn't complete.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh
--- a/t/t1001-read-tree-m-2way.sh
+++ b/t/t1001-read-tree-m-2way.sh
@@ -100,7 +100,7 @@ test_expect_success \
  git-checkout-cache -u -f -q -a 
  git-update-cache --add yomin 
  read_tree_twoway $treeH $treeM 
- git-ls-files --stage 4.out || exit
+ git-ls-files --stage 4.out || return 1
  diff -u M.out 4.out 4diff.out
  compare_change 4diff.out expected 
  check_cache_at yomin clean'
@@ -114,7 +114,7 @@ test_expect_success \
  git-update-cache --add yomin 
  echo yomin yomin yomin 
  read_tree_twoway $treeH $treeM 
- git-ls-files --stage 5.out || exit
+ git-ls-files --stage 5.out || return 1
  diff -u M.out 5.out 5diff.out
  compare_change 5diff.out expected 
  check_cache_at yomin dirty'
@@ -215,7 +215,7 @@ test_expect_success \
  echo nitfol nitfol nitfol 
  git-update-cache --add nitfol 
  read_tree_twoway $treeH $treeM 
- git-ls-files --stage 14.out || exit
+ git-ls-files --stage 14.out || return 1
  diff -u M.out 14.out 14diff.out
  compare_change 14diff.out expected 
  check_cache_at nitfol clean'
@@ -229,7 +229,7 @@ test_expect_success \
  git-update-cache --add nitfol 
  echo nitfol nitfol nitfol nitfol 
  read_tree_twoway $treeH $treeM 
- git-ls-files --stage 15.out || exit
+ git-ls-files --stage 15.out || return 1
  diff -u M.out 15.out 15diff.out
  compare_change 15diff.out expected 
  check_cache_at nitfol dirty'
diff --git a/t/t1002-read-tree-m-u-2way.sh b/t/t1002-read-tree-m-u-2way.sh
--- a/t/t1002-read-tree-m-u-2way.sh
+++ b/t/t1002-read-tree-m-u-2way.sh
@@ -73,7 +73,7 @@ test_expect_success \
 'rm -f .git/index 
  git-update-cache --add yomin 
  git-read-tree -m -u $treeH $treeM 
- git-ls-files --stage 4.out || exit
+ git-ls-files --stage 4.out || return 1
  diff --unified=0 M.out 4.out 4diff.out
  compare_change 4diff.out expected 
  check_cache_at yomin clean 
@@ -90,7 +90,7 @@ test_expect_success \
  git-update-cache --add yomin 
  echo yomin yomin yomin 
  git-read-tree -m -u $treeH $treeM 
- git-ls-files --stage 5.out || exit
+ git-ls-files --stage 5.out || return 1
  diff --unified=0 M.out 5.out 5diff.out
  compare_change 5diff.out expected 
  check_cache_at yomin dirty 
@@ -192,7 +192,7 @@ test_expect_success \
  echo nitfol nitfol nitfol 
  git-update-cache --add nitfol 
  git-read-tree -m -u $treeH $treeM 
- git-ls-files --stage 14.out || exit
+ git-ls-files --stage 14.out || return 1
  diff --unified=0 M.out 14.out 14diff.out
  compare_change 14diff.out expected 
  sum bozbar frotz actual14.sum 
@@ -212,7 +212,7 @@ test_expect_success \
  git-update-cache --add nitfol 
  echo nitfol nitfol nitfol nitfol 
  git-read-tree -m -u $treeH $treeM 
- git-ls-files --stage 15.out || exit
+ git-ls-files --stage 15.out || return 1
  diff --unified=0 M.out 15.out 15diff.out
  compare_change 15diff.out expected 
  check_cache_at nitfol dirty 
diff --git a/t/t1005-read-tree-m-2way-emu23.sh 
b/t/t1005-read-tree-m-2way-emu23.sh
--- a/t/t1005-read-tree-m-2way-emu23.sh
+++ b/t/t1005-read-tree-m-2way-emu23.sh
@@ -120,7 +120,7 @@ test_expect_success \
  git-checkout-cache -u -f -q -a 
  git-update-cache --add yomin 
  read_tree_twoway $treeH $treeM 
- git-ls-files --stage 4.out || exit
+ git-ls-files --stage 4.out || return 1
  diff -u M.out 4.out 4diff.out
  compare_change 4diff.out expected 
  check_cache_at yomin clean'
@@ -136,7 +136,7 @@ test_expect_success \
  git-update-cache --add yomin 
  echo yomin yomin yomin 
  read_tree_twoway

[PATCH] Warning fix for gcc 4

2005-08-09 Thread Pavel Roskin
Hello!

This patch fixes the only warning reported by gcc 4.0.1 on Fedora Core 4
for x86_64:

sha1_file.c:1391: warning: pointer targets in assignment differ in
signedness

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/sha1_file.c b/sha1_file.c
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1388,7 +1388,7 @@ int write_sha1_from_fd(const unsigned ch
ssize_t size;
if (*bufposn) {
stream.avail_in = *bufposn;
-   stream.next_in = buffer;
+   stream.next_in = (unsigned char *) buffer;
do {
stream.next_out = discard;
stream.avail_out = sizeof(discard);


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: New script: cg-clean

2005-08-06 Thread Pavel Roskin
Hello, Petr!

Sorry for delay.

On Sun, 2005-07-10 at 17:46 +0200, Petr Baudis wrote:
 Dear diary, on Sat, Jul 09, 2005 at 12:34:44AM CEST, I got a letter
 where Pavel Roskin [EMAIL PROTECTED] told me that...
  Hello, Petr!
 
 Hello,
 
  Please consider this script for Cogito.
  
  Signed-off-by: Pavel Roskin [EMAIL PROTECTED]
 
 the script is definitively interesting, but I have couple of notes
 about it first:
 
 (i) -i sounds wrong for anything but being interactive here ;-) What
 about -A?

I agree that -i could be confusing, but -A would seem to imply All, so
let it be -x from exclude.

 (ii) I'm confused - if -a is all of the above, how do I clean _only_
 regular files, and only those not ignored by cg-status?

cg-clean without options.  I'm changing the description to avoid
confusion.

 (iii) Makes it any sense to remove only special files?

I thought it would make sense to have an option to remove them in
addition to regular files, but now I think it's not worth the trouble to
distinguish between them.

 (iv) -r implies being recursive, but it has nothing to do with that
 here.

Renamed to -d.  Other confusing options have been removed.  -a is
retired because it's not hard to type -dx.  Explicit arguments are not
accepted - one can easily use rm instead.  That should make cg-clean
much simpler.

 (v) Semantically, I think it's quite close to cg-reset. What about
 making it part of cg-reset instead of a separate command? I tend to be
 careful about command inflation. (That's part of being careful about the
 usability in general.) That's just an idea and possibly a bad one, what
 do you think?

I understand your concern, but cg-reset does other things.  cg-reset
changes the branch.  cg-clean allows to start the build from scratch
without changing the branch.

It's not uncommon for me to revert patches one-by-one looking for the
patch that breaks something.  I could make minor changes e.g for
debugging or to fix breakage in certain revisions.  I would revert such
by cg-clean before going to another revision.  cg-reset would be an
overkill - it would move me to the latest release.

I can imagine that cg-reset would call cg-clean (optionally) to allow
fresh start on the main branch.  The opposite would be wrong.

Here's the simplified cg-clean script.  Note that the -d option is not
working with the current version of git of a bug in git-ls-files.  I can
work it around by scanning all directories in bash, but I think it's
easier to fix git (remove continue before DT_REG in ls-files.c).

Processing of .gitignore was taken from cg-status, and I don't really
understand it.  But I think it's important to keep that code in sync.
It could later go to cg-Xlib.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

#!/usr/bin/env bash
#
# Clean unknown files from the working tree.
# Copyright (c) Pavel Roskin, 2005
#
# Cleans file and directories that are not under version control.
# When run without arguments, files ignored by cg-status and directories
# are not removed.
#
# OPTIONS
# ---
# -d::
#   Also clean directories.
#
# -x::
#   Also clean files ignored by cg-status, such as object files.

USAGE=cg-clean [-d] [-x]

. ${COGITO_LIB}cg-Xlib

cleanexclude=
cleandir=
while optparse; do
if optparse -d; then
cleandir=1
elif optparse -x; then
cleanexclude=1
else
optfail
fi
done

# Good candidate for cg-Xlib
# Put exclude options for git-ls-files to EXCLUDE
set_exclude() {
EXCLUDE=

stdignores=('*.[ao]' '.*' tags '*~' '#*' ',,merge*')
for ign in [EMAIL PROTECTED]; do
EXCLUDE=$EXCLUDE --exclude=$ign
done

EXCLUDEFILE=$_git/exclude
if [ -f $EXCLUDEFILE ]; then
EXCLUDE=$EXCLUDE --exclude-from=$EXCLUDEFILE
fi

{
path=$_git_relpath
dir=
[ -r .gitignore ]  EXCLUDE=$EXCLUDE 
--exclude-from=.gitignore
while [[ $path == */* ]]; do
dir=${dir:-.}/${path%%/*}
path=${path#*/}
[ -r $dir/.gitignore ]  EXCLUDE=$EXCLUDE 
--exclude-from=$dir/.gitignore
done
}
}

if [ -z $cleanexclude ]; then
set_exclude
else
EXCLUDE=
fi  

git-update-cache --refresh  /dev/null

# Need to use temporary file so that changing IFS doesn't affect $EXCLUDE
# expansion.
filelist=$(mktemp -t gitlsfiles.XX)
git-ls-files --others $EXCLUDE $filelist
save_IFS=$IFS
IFS=$'\n'
for file in $(cat $filelist); do
IFS=$save_IFS
if [ -d $file ]; then
if [ $cleandir ]; then
# Try really hard by changing permissions
chmod -R 700 $file
rm -rf $file
fi
return
fi
rm -f $file
done

rm -f $filelist


-- 
Regards,
Pavel Roskin
-
To unsubscribe from this list: send

[PATCH] Making CFLAGS compilant with GNU Coding Standards

2005-08-05 Thread Pavel Roskin
Hello!

Quoting GNU Coding Standards (info standards):

If there are C compiler options that _must_ be used for proper
compilation of certain files, do not include them in `CFLAGS'.  Users
expect to be able to specify `CFLAGS' freely themselves.

This patch renames COPTS to CFLAGS, because it's COPTS that was user
overridable.  Also, -Wall is moved there because it's optional.  What
was CFLAGS is now ALL_CFLAGS, which users should not override.

Defines are added to DEFINES.  Since ALL_CFLAGS is recursively expanded,
it uses the final value of DEFINES.

Implicit rules are made explicit since the implicit rules use CFLAGS
rather than ALL_CFLAGS.  I believe that serious projects should not rely
on implicit rules anyway.  Percent rules are used because they are used
already and because they don't need the .SUFFIXES target.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/Makefile b/Makefile
--- a/Makefile
+++ b/Makefile
@@ -34,8 +34,8 @@
 
 GIT_VERSION=0.99.3
 
-COPTS?=-g -O2
-CFLAGS+=$(COPTS) -Wall $(DEFINES)
+CFLAGS ?= -g -O2 -Wall
+ALL_CFLAGS = $(CFLAGS) $(DEFINES)
 
 prefix=$(HOME)
 bindir=$(prefix)/bin
@@ -125,7 +125,7 @@ ifndef NO_OPENSSL
LIB_OBJS += epoch.o
OPENSSL_LIBSSL=-lssl
 else
-   CFLAGS += '-DNO_OPENSSL'
+   DEFINES += '-DNO_OPENSSL'
MOZILLA_SHA1=1
OPENSSL_LIBSSL=
 endif
@@ -146,8 +146,8 @@ endif
 endif
 endif
 
-CFLAGS += '-DSHA1_HEADER=$(SHA1_HEADER)'
-CFLAGS += '-DDEFAULT_GIT_TEMPLATE_ENVIRONMENT=$(etcgitdir)/templates'
+DEFINES += '-DSHA1_HEADER=$(SHA1_HEADER)'
+DEFINES += '-DDEFAULT_GIT_TEMPLATE_ENVIRONMENT=$(etcgitdir)/templates'
 
 
 
@@ -156,9 +156,15 @@ CFLAGS += '-DDEFAULT_GIT_TEMPLATE_ENVIRO
 all: $(PROG)
 
 
+%.o: %.c
+   $(CC) -c $(ALL_CFLAGS) $
+
+%.o: %.S
+   $(CC) -c $(ALL_CFLAGS) $
+
 .PRECIOUS: %.o
 git-%: %.o $(LIB_FILE)
-   $(CC) $(CFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
+   $(CC) $(ALL_CFLAGS) -o $@ $(filter %.o,$^) $(LIBS)
 
 git-http-pull: pull.o
 git-local-pull: pull.o
@@ -185,13 +191,13 @@ test: all
$(MAKE) -C t/ all
 
 test-date: test-date.c date.o
-   $(CC) $(CFLAGS) -o $@ test-date.c date.o
+   $(CC) $(ALL_CFLAGS) -o $@ test-date.c date.o
 
 test-delta: test-delta.c diff-delta.o patch-delta.o
-   $(CC) $(CFLAGS) -o $@ $^
+   $(CC) $(ALL_CFLAGS) -o $@ $^
 
 check:
-   for i in *.c; do sparse $(CFLAGS) $(SPARSE_FLAGS) $$i; done
+   for i in *.c; do sparse $(ALL_CFLAGS) $(SPARSE_FLAGS) $$i; done
 
 
 

-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] mmap error handling

2005-07-29 Thread Pavel Roskin
Hi, Linus!

On Thu, 2005-07-28 at 17:30 -0700, Linus Torvalds wrote:
 _always_ save the value of errno before doing any other calls. Even 
 successful calls are perfectly allowed to change errno.

OK.  Fixed patch below.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

diff --git a/diff.c b/diff.c
--- a/diff.c
+++ b/diff.c
@@ -377,8 +377,10 @@ int diff_populate_filespec(struct diff_f
if (fd  0)
goto err_empty;
s-data = mmap(NULL, s-size, PROT_READ, MAP_PRIVATE, fd, 0);
-   s-should_munmap = 1;
close(fd);
+   if (s-data == MAP_FAILED)
+   goto err_empty;
+   s-should_munmap = 1;
}
else {
char type[20];
diff --git a/diffcore-order.c b/diffcore-order.c
--- a/diffcore-order.c
+++ b/diffcore-order.c
@@ -28,7 +28,7 @@ static void prepare_order(const char *or
}
map = mmap(NULL, st.st_size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0);
close(fd);
-   if (-1 == (int)(long)map)
+   if (map == MAP_FAILED)
return;
endp = map + st.st_size;
for (pass = 0; pass  2; pass++) {
diff --git a/local-pull.c b/local-pull.c
--- a/local-pull.c
+++ b/local-pull.c
@@ -54,7 +54,7 @@ int fetch(unsigned char *sha1)
}
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, ifd, 0);
close(ifd);
-   if (-1 == (int)(long)map) {
+   if (map == MAP_FAILED) {
fprintf(stderr, cannot mmap %s\n, filename);
return -1;
}
diff --git a/read-cache.c b/read-cache.c
--- a/read-cache.c
+++ b/read-cache.c
@@ -392,7 +392,7 @@ int read_cache(void)
return (errno == ENOENT) ? 0 : error(open failed);
 
size = 0; // avoid gcc warning
-   map = (void *)-1;
+   map = MAP_FAILED;
if (!fstat(fd, st)) {
size = st.st_size;
errno = EINVAL;
@@ -400,7 +400,7 @@ int read_cache(void)
map = mmap(NULL, size, PROT_READ | PROT_WRITE, 
MAP_PRIVATE, fd, 0);
}
close(fd);
-   if (-1 == (int)(long)map)
+   if (map == MAP_FAILED)
return error(mmap failed);
 
hdr = map;
diff --git a/rev-cache.c b/rev-cache.c
--- a/rev-cache.c
+++ b/rev-cache.c
@@ -212,11 +212,9 @@ int read_rev_cache(const char *path, FIL
return -1;
}
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
-   if (map == MAP_FAILED) {
-   close(fd);
-   return -1;
-   }
close(fd);
+   if (map == MAP_FAILED)
+   return -1;
 
memset(last_sha1, 0, 20);
ofs = 0;
diff --git a/sha1_file.c b/sha1_file.c
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -518,7 +518,7 @@ static void *map_sha1_file_internal(cons
}
map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
-   if (-1 == (int)(long)map)
+   if (map == MAP_FAILED)
return NULL;
*size = st.st_size;
return map;
@@ -1363,7 +1363,7 @@ int index_fd(unsigned char *sha1, int fd
if (size)
buf = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
close(fd);
-   if ((int)(long)buf == -1)
+   if (buf == MAP_FAILED)
return -1;
 
if (!type)
diff --git a/test-delta.c b/test-delta.c
--- a/test-delta.c
+++ b/test-delta.c
@@ -41,6 +41,7 @@ int main(int argc, char *argv[])
from_buf = mmap(NULL, from_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (from_buf == MAP_FAILED) {
perror(argv[2]);
+   close(fd);
return 1;
}
close(fd);
@@ -54,6 +55,7 @@ int main(int argc, char *argv[])
data_buf = mmap(NULL, data_size, PROT_READ, MAP_PRIVATE, fd, 0);
if (data_buf == MAP_FAILED) {
perror(argv[3]);
+   close(fd);
return 1;
}
close(fd);
diff --git a/tools/mailsplit.c b/tools/mailsplit.c
--- a/tools/mailsplit.c
+++ b/tools/mailsplit.c
@@ -116,8 +116,9 @@ int main(int argc, char **argv)
}
size = st.st_size;
map = mmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);
-   if (-1 == (int)(long)map) {
+   if (map == MAP_FAILED) {
perror(mmap);
+   close(fd);
exit(1);
}
close(fd);


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Colored log on any ANSI capable terminal

2005-04-21 Thread Pavel Roskin
Hello!

setterm only works on Linux terminal.  It should be safe to use raw ANSI
sequences -they work on most terminals, including xterm.  Nobody forces
you to use the -c option to git log on those stone-age terminals
that neither support nor ignore ANSI color codes.

I'm aware of $'...' but it may not work in bash 1.x.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

--- a/gitlog.sh
+++ b/gitlog.sh
@@ -12,11 +12,11 @@
 
 if [ $1 = -c ]; then
shift
-   colheader=$(setterm -foreground green)
-   colauthor=$(setterm -foreground cyan)
-   colcommitter=$(setterm -foreground magenta)
-   colsignoff=$(setterm -foreground yellow)
-   coldefault=$(setterm -foreground default)
+   colheader=$(echo -ne '\e[32m')
+   colauthor=$(echo -ne '\e[36m')
+   colcommitter=$(echo -ne '\e[35m')
+   colsignoff=$(echo -ne '\e[33m')
+   coldefault=$(echo -ne '\e[39m')
 else
colheader=
colauthor=


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] gittrack.sh accepts invalid branch names

2005-04-20 Thread Pavel Roskin
Hello, Petr and everybody!

gittrack.sh allows abbreviated branch names, e.g. it's possible to run
git track lin when there is a branch called linus.

I believe it's a bug, not a feature.  Please look at this line from
gittrack.sh:

grep -q $(echo -e ^$name\t | sed 's/\./\\./g') .git/remotes

The result of command expansion is subjected to word splitting, which
means the trailing tab is removed as a space.  So grep doesn't see the
tab.

The way to avoid word splitting would be to quote $(), but it would
make the shell code too hairy.  I'm not even sure all shells would
interpret $($name) correctly.

So I decided to use tab directly in the sed expression.  I cannot think
of any portable way to avoid grep completely (q is a GNU sed
extension, and we want to support BSD, I think), so it's still there,
looking for any output from sed.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

--- a/gittrack.sh
+++ b/gittrack.sh
@@ -35,7 +35,7 @@ die () {
 mkdir -p .git/heads
 
 if [ $name ]; then
-   grep -q $(echo -e ^$name\t | sed 's/\./\\./g') .git/remotes || \
+   sed -ne /^$name\t/p .git/remotes | grep -q . || \
[ -s .git/heads/$name ] || \
die unknown branch \$name\
 

-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] gittrack.sh accepts invalid branch names

2005-04-20 Thread Pavel Roskin
Hi, Petr!

On Thu, 2005-04-21 at 01:21 +0200, Petr Baudis wrote:
 Dear diary, on Wed, Apr 20, 2005 at 09:48:30PM CEST, I got a letter
 where Pavel Roskin [EMAIL PROTECTED] told me that...
  --- a/gittrack.sh
  +++ b/gittrack.sh
  @@ -35,7 +35,7 @@ die () {
   mkdir -p .git/heads
   
   if [ $name ]; then
  -   grep -q $(echo -e ^$name\t | sed 's/\./\\./g') .git/remotes || \
  +   sed -ne /^$name\t/p .git/remotes | grep -q . || \
  [ -s .git/heads/$name ] || \
  die unknown branch \$name\
 
 This fixes the acceptance, but not the choice.
 
 What does the grep -q . exactly do? Just sets error code based on
 whether the sed output is non-empty?

Yes.

  What about [] instead?

You'll need another pair of quotes for that:

[ $(sed -ne /^$name\t/p .git/remotes) ]; echo $?

If I remember correctly from my Autoconf hacking experience, not all
shells like mixing quotes and command substitution, and even bash
treated this differently in different versions.  I can do more research,
but it seems just too fragile to me.

Another thing I remember is that case would not need quotes.  For some
historic reasons, the expression between case and in is subjected to
command substitution, but not word expansion.

So the patch becomes:

--- a/gittrack.sh
+++ b/gittrack.sh
@@ -35,9 +35,11 @@ die () {
 mkdir -p .git/heads
 
 if [ $name ]; then
-   grep -q $(echo -e ^$name\t | sed 's/\./\\./g') .git/remotes || \
+   case x$(sed -ne /^$name\t/p .git/remotes) in
+   x)
[ -s .git/heads/$name ] || \
-   die unknown branch \$name\
+   die unknown branch \$name\ ;;
+   esac
 
echo $name .git/tracking
 
Looks rather ugly for my taste, but just in case:
Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

By the way, please check all references to .git/remotes - this bug is
not specific to gittrack.sh.


-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Switching between branches

2005-04-20 Thread Pavel Roskin
Hello!

Perhaps it's a naive question, but how do I switch between branches?  I
mean an equivalent of svn switch or cvs update -r branch that would
reuse the existing working directory.

I tried to switch a git-pasky working directory to the linus branch.

Here's what I tried:

git track linus
git cancel
git pull
git cancel
git merge linus
git cancel

After all that I found that README is still from the pasky branch.

Then I tried git merge -b pasky linus - this actually changed the
files to the linus branch, but it didn't remove files specific to
git-pasky.  Also, I'm surprised that I had to specify -b pasky, as if
the currently checked out branch is unknown.

I'm using git-pasky 0.6.2.

-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] Better option parsing for gitdiff.sh

2005-04-19 Thread Pavel Roskin
Hello!

This patch improves option handling for gitdiff.sh.  Now -p doesn't
need to precede -r, although all options still have to be placed
before the file names.  Also, the patch introduces a minimal usage info
for the script.

The patch is against current git-pasky.

Signed-off-by: Pavel Roskin [EMAIL PROTECTED]

--- a/gitdiff.sh
+++ b/gitdiff.sh
@@ -27,6 +27,13 @@ die () {
exit 1
 }
 
+usage () {
+   echo Usage: 2
+   echo   gitdiff.sh -r rev1:rev2 [FILES...] 2
+   echo   gitdiff.sh -r rev1 -r rev2 [FILES...] 2
+   exit 1
+}
+
 diffqfile () {
dir=$1; shift
file=$1; shift
@@ -59,26 +66,44 @@ diffqueue () {
return $ret
 }
 
-
-# FIXME: The commandline parsing is awful.
-
-if [ $1 = -p ]; then
-   shift
-   parent=1
-fi
-
-if [ $1 = -r ]; then
-   shift
-   id1=$(echo $1: | cut -d : -f 1)
-   [ $id1 != $1 ]  id2=$(echo $1: | cut -d : -f 2)
-   shift
-fi
-
-if [ $1 = -r ]; then
-   shift
-   id2=$1
-   shift
-fi
+# Parsing the command line
+id1_set=
+id2_set=
+while true; do
+   case $1 in
+   -p)
+   parent=1
+   shift
+   ;;
+   -r)
+   if test $id2_set; then
+   echo Too many revision numbers 21
+   usage
+   elif test $id1_set; then
+   shift
+   id2=$1
+   id2_set=1
+   shift
+   else
+   shift
+   id1=$(echo $1: | cut -d : -f 1)
+   id1_set=1
+   if test $id1 != $1; then
+   id2=$(echo $1: | cut -d : -f 2)
+   id2_set=1
+   fi
+   shift
+   fi
+   ;;
+   -*)
+   echo Unknown option $1 21
+   usage
+   ;;
+   *)
+   break
+   ;;
+   esac
+done
 
 if [ $parent ]; then
id2=$id1



-- 
Regards,
Pavel Roskin

-
To unsubscribe from this list: send the line unsubscribe git in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html