1
0
Fork 0
mirror of https://github.com/git/git.git synced 2024-11-17 14:34:49 +01:00

Merge branch 'fixes'

This commit is contained in:
Junio C Hamano 2005-10-07 17:08:56 -07:00
commit 305a5c78bf
6 changed files with 228 additions and 41 deletions

View file

@ -7,6 +7,9 @@
# Show GIT link as: <command>(<section>); if section is defined, else just show # Show GIT link as: <command>(<section>); if section is defined, else just show
# the command. # the command.
[attributes]
caret=^
ifdef::backend-docbook[] ifdef::backend-docbook[]
[gitlink-inlinemacro] [gitlink-inlinemacro]
{0%{target}} {0%{target}}
@ -19,3 +22,5 @@ ifdef::backend-xhtml11[]
[gitlink-inlinemacro] [gitlink-inlinemacro]
<a href="{target}.html">{target}{0?({0})}</a> <a href="{target}.html">{target}{0?({0})}</a>
endif::backend-xhtml11[] endif::backend-xhtml11[]

View file

@ -50,7 +50,7 @@ OPTIONS
-k|--killed:: -k|--killed::
Show files on the filesystem that need to be removed due Show files on the filesystem that need to be removed due
to file/directory conflicts for checkout-cache to to file/directory conflicts for checkout-index to
succeed. succeed.
-z:: -z::

View file

@ -54,13 +54,13 @@ OPTIONS
`git-diff-\*`). `git-diff-\*`).
--not:: --not::
When showing object names, prefix them with '^' and When showing object names, prefix them with '{caret}' and
strip '^' prefix from the object names that already have strip '{caret}' prefix from the object names that already have
one. one.
--symbolic:: --symbolic::
Usually the object names are output in SHA1 form (with Usually the object names are output in SHA1 form (with
possible '^' prefix); this option makes them output in a possible '{caret}' prefix); this option makes them output in a
form as close to the original input as possible. form as close to the original input as possible.
@ -93,22 +93,23 @@ what is called an 'extended SHA1' syntax.
happen to have both heads/master and tags/master, you can happen to have both heads/master and tags/master, you can
explicitly say 'heads/master' to tell GIT which one you mean. explicitly say 'heads/master' to tell GIT which one you mean.
* A suffix '^' to a revision parameter means the first parent of * A suffix '{caret}' to a revision parameter means the first parent of
that commit object. '^<n>' means the <n>th parent (i.e. that commit object. '{caret}<n>' means the <n>th parent (i.e.
'rev^' 'rev{caret}'
is equivalent to 'rev^1'). As a special rule, is equivalent to 'rev{caret}1'). As a special rule,
'rev^0' means the commit itself and is used when 'rev' is the 'rev{caret}0' means the commit itself and is used when 'rev' is the
object name of a tag object that refers to a commit object. object name of a tag object that refers to a commit object.
* A suffix '~<n>' to a revision parameter means the commit * A suffix '~<n>' to a revision parameter means the commit
object that is the <n>th generation grand-parent of the named object that is the <n>th generation grand-parent of the named
commit object, following only the first parent. I.e. rev~3 is commit object, following only the first parent. I.e. rev~3 is
equivalent to rev^^^ which is equivalent to rev^1^1^1. equivalent to rev{caret}{caret}{caret} which is equivalent to\
rev{caret}1{caret}1{caret}1.
'git-rev-parse' also accepts a prefix '^' to revision parameter, 'git-rev-parse' also accepts a prefix '{caret}' to revision parameter,
which is passed to 'git-rev-list'. Two revision parameters which is passed to 'git-rev-list'. Two revision parameters
concatenated with '..' is a short-hand for writing a range concatenated with '..' is a short-hand for writing a range
between them. I.e. 'r1..r2' is equivalent to saying '^r1 r2' between them. I.e. 'r1..r2' is equivalent to saying '{caret}r1 r2'
Author Author

View file

@ -42,7 +42,15 @@ git-update-index -q --unmerged --refresh || exit
if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1 if GIT_DIR="$GIT_DIR" git-rev-parse --verify HEAD >/dev/null 2>&1
then then
git-diff-index -M --cached HEAD | git-diff-index -M --cached HEAD |
sed 's/^://' | sed -e '
s/^://
h
s/^[^\t]*//
s/ /\\ /g
x
s/\t.*$//
G
s/\n/ /' |
report "Updated but not checked in" "will commit" report "Updated but not checked in" "will commit"
committable="$?" committable="$?"
@ -51,14 +59,24 @@ else
# Initial commit # Initial commit
#' #'
git-ls-files | git-ls-files |
sed 's/^/o o o o A /' | sed -e '
s/ /\\ /g
s/^/o o o o A /' |
report "Updated but not checked in" "will commit" report "Updated but not checked in" "will commit"
committable="$?" committable="$?"
fi fi
git-diff-files | git-diff-files |
sed 's/^://' | sed -e '
s/^://
h
s/^[^\t]*//
s/ /\\ /g
x
s/\t.*$//
G
s/\n/ /' |
report "Changed but not updated" "use git-update-index to mark for commit" report "Changed but not updated" "use git-update-index to mark for commit"
if grep -v '^#' "$GIT_DIR/info/exclude" >/dev/null 2>&1 if grep -v '^#' "$GIT_DIR/info/exclude" >/dev/null 2>&1

View file

@ -54,11 +54,13 @@ static int prepare_children(struct tree_entry_list *elem)
return 0; return 0;
} }
static struct tree_entry_list *find_entry(const char *path) static struct tree_entry_list *find_entry(const char *path, char *pathbuf)
{ {
const char *next, *slash; const char *next, *slash;
int len; int len;
struct tree_entry_list *elem = &root_entry; struct tree_entry_list *elem = &root_entry, *oldelem = NULL;
*(pathbuf) = '\0';
/* Find tree element, descending from root, that /* Find tree element, descending from root, that
* corresponds to the named path, lazily expanding * corresponds to the named path, lazily expanding
@ -86,6 +88,10 @@ static struct tree_entry_list *find_entry(const char *path)
len = slash - path; len = slash - path;
} }
if (len) { if (len) {
if (oldelem) {
pathbuf += sprintf(pathbuf, "%s/", oldelem->name);
}
/* (len == 0) if the original path was "drivers/char/" /* (len == 0) if the original path was "drivers/char/"
* and we have run already two rounds, having elem * and we have run already two rounds, having elem
* pointing at the drivers/char directory. * pointing at the drivers/char directory.
@ -101,6 +107,8 @@ static struct tree_entry_list *find_entry(const char *path)
} }
if (!elem) if (!elem)
return NULL; return NULL;
oldelem = elem;
} }
path = next; path = next;
} }
@ -108,19 +116,6 @@ static struct tree_entry_list *find_entry(const char *path)
return elem; return elem;
} }
static void show_entry_name(struct tree_entry_list *e)
{
/* This is yucky. The root level is there for
* our convenience but we really want to do a
* forest.
*/
if (e->parent && e->parent != &root_entry) {
show_entry_name(e->parent);
putchar('/');
}
printf("%s", e->name);
}
static const char *entry_type(struct tree_entry_list *e) static const char *entry_type(struct tree_entry_list *e)
{ {
return (e->directory ? "tree" : "blob"); return (e->directory ? "tree" : "blob");
@ -134,28 +129,35 @@ static const char *entry_hex(struct tree_entry_list *e)
} }
/* forward declaration for mutually recursive routines */ /* forward declaration for mutually recursive routines */
static int show_entry(struct tree_entry_list *, int); static int show_entry(struct tree_entry_list *, int, char *pathbuf);
static int show_children(struct tree_entry_list *e, int level) static int show_children(struct tree_entry_list *e, int level, char *pathbuf)
{ {
int oldlen = strlen(pathbuf);
if (e != &root_entry)
sprintf(pathbuf + oldlen, "%s/", e->name);
if (prepare_children(e)) if (prepare_children(e))
die("internal error: ls-tree show_children called with non tree"); die("internal error: ls-tree show_children called with non tree");
e = e->item.tree->entries; e = e->item.tree->entries;
while (e) { while (e) {
show_entry(e, level); show_entry(e, level, pathbuf);
e = e->next; e = e->next;
} }
pathbuf[oldlen] = '\0';
return 0; return 0;
} }
static int show_entry(struct tree_entry_list *e, int level) static int show_entry(struct tree_entry_list *e, int level, char *pathbuf)
{ {
int err = 0; int err = 0;
if (e != &root_entry) { if (e != &root_entry) {
printf("%06o %s %s ", e->mode, entry_type(e), printf("%06o %s %s %s%s", e->mode, entry_type(e),
entry_hex(e)); entry_hex(e), pathbuf, e->name);
show_entry_name(e);
putchar(line_termination); putchar(line_termination);
} }
@ -176,10 +178,10 @@ static int show_entry(struct tree_entry_list *e, int level)
*/ */
if (level == 0 && !(ls_options & LS_TREE_ONLY)) if (level == 0 && !(ls_options & LS_TREE_ONLY))
/* case (1)-a and (1)-b */ /* case (1)-a and (1)-b */
err = err | show_children(e, level+1); err = err | show_children(e, level+1, pathbuf);
else if (level && ls_options & LS_RECURSIVE) else if (level && ls_options & LS_RECURSIVE)
/* case (2)-b */ /* case (2)-b */
err = err | show_children(e, level+1); err = err | show_children(e, level+1, pathbuf);
} }
return err; return err;
} }
@ -187,7 +189,8 @@ static int show_entry(struct tree_entry_list *e, int level)
static int list_one(const char *path) static int list_one(const char *path)
{ {
int err = 0; int err = 0;
struct tree_entry_list *e = find_entry(path); char pathbuf[MAXPATHLEN + 1];
struct tree_entry_list *e = find_entry(path, pathbuf);
if (!e) { if (!e) {
/* traditionally ls-tree does not complain about /* traditionally ls-tree does not complain about
* missing path. We may change this later to match * missing path. We may change this later to match
@ -195,7 +198,7 @@ static int list_one(const char *path)
*/ */
return err; return err;
} }
err = err | show_entry(e, 0); err = err | show_entry(e, 0, pathbuf);
return err; return err;
} }

160
t/t3101-ls-tree-dirname.sh Normal file
View file

@ -0,0 +1,160 @@
#!/bin/sh
#
# Copyright (c) 2005 Junio C Hamano
# Copyright (c) 2005 Robert Fitzsimons
#
test_description='git-ls-tree directory and filenames handling.
This test runs git-ls-tree with the following in a tree.
1.txt - a file
2.txt - a file
path0/a/b/c/1.txt - a file in a directory
path1/b/c/1.txt - a file in a directory
path2/1.txt - a file in a directory
path3/1.txt - a file in a directory
path3/2.txt - a file in a directory
Test the handling of mulitple directories which have matching file
entries. Also test odd filename and missing entries handling.
'
. ./test-lib.sh
test_expect_success \
'setup' \
'echo 111 >1.txt &&
echo 222 >2.txt &&
mkdir path0 path0/a path0/a/b path0/a/b/c &&
echo 111 >path0/a/b/c/1.txt &&
mkdir path1 path1/b path1/b/c &&
echo 111 >path1/b/c/1.txt &&
mkdir path2 &&
echo 111 >path2/1.txt &&
mkdir path3 &&
echo 111 >path3/1.txt &&
echo 222 >path3/2.txt &&
find *.txt path* \( -type f -o -type l \) -print |
xargs git-update-index --add &&
tree=`git-write-tree` &&
echo $tree'
_x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
_x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
test_output () {
sed -e "s/ $_x40 / X /" <current >check
diff -u expected check
}
test_expect_success \
'ls-tree plain' \
'git-ls-tree $tree >current &&
cat >expected <<\EOF &&
100644 blob X 1.txt
100644 blob X 2.txt
040000 tree X path0
040000 tree X path1
040000 tree X path2
040000 tree X path3
EOF
test_output'
test_expect_success \
'ls-tree recursive' \
'git-ls-tree -r $tree >current &&
cat >expected <<\EOF &&
100644 blob X 1.txt
100644 blob X 2.txt
040000 tree X path0
040000 tree X path0/a
040000 tree X path0/a/b
040000 tree X path0/a/b/c
100644 blob X path0/a/b/c/1.txt
040000 tree X path1
040000 tree X path1/b
040000 tree X path1/b/c
100644 blob X path1/b/c/1.txt
040000 tree X path2
100644 blob X path2/1.txt
040000 tree X path3
100644 blob X path3/1.txt
100644 blob X path3/2.txt
EOF
test_output'
test_expect_success \
'ls-tree filter 1.txt' \
'git-ls-tree $tree 1.txt >current &&
cat >expected <<\EOF &&
100644 blob X 1.txt
EOF
test_output'
test_expect_success \
'ls-tree filter path1/b/c/1.txt' \
'git-ls-tree $tree path1/b/c/1.txt >current &&
cat >expected <<\EOF &&
100644 blob X path1/b/c/1.txt
EOF
test_output'
test_expect_success \
'ls-tree filter all 1.txt files' \
'git-ls-tree $tree 1.txt path0/a/b/c/1.txt path1/b/c/1.txt path2/1.txt path3/1.txt >current &&
cat >expected <<\EOF &&
100644 blob X 1.txt
100644 blob X path0/a/b/c/1.txt
100644 blob X path1/b/c/1.txt
100644 blob X path2/1.txt
100644 blob X path3/1.txt
EOF
test_output'
test_expect_success \
'ls-tree filter directories' \
'git-ls-tree $tree path3 path2 path0/a/b/c path1/b/c path0/a >current &&
cat >expected <<\EOF &&
040000 tree X path3
100644 blob X path3/1.txt
100644 blob X path3/2.txt
040000 tree X path2
100644 blob X path2/1.txt
040000 tree X path0/a/b/c
100644 blob X path0/a/b/c/1.txt
040000 tree X path1/b/c
100644 blob X path1/b/c/1.txt
040000 tree X path0/a
040000 tree X path0/a/b
EOF
test_output'
test_expect_success \
'ls-tree filter odd names' \
'git-ls-tree $tree 1.txt /1.txt //1.txt path3/1.txt /path3/1.txt //path3//1.txt path3 /path3/ path3// >current &&
cat >expected <<\EOF &&
100644 blob X 1.txt
100644 blob X 1.txt
100644 blob X 1.txt
100644 blob X path3/1.txt
100644 blob X path3/1.txt
100644 blob X path3/1.txt
040000 tree X path3
100644 blob X path3/1.txt
100644 blob X path3/2.txt
040000 tree X path3
100644 blob X path3/1.txt
100644 blob X path3/2.txt
040000 tree X path3
100644 blob X path3/1.txt
100644 blob X path3/2.txt
EOF
test_output'
test_expect_success \
'ls-tree filter missing files and extra slashes' \
'git-ls-tree $tree 1.txt/ abc.txt path3//23.txt path3/2.txt/// >current &&
cat >expected <<\EOF &&
EOF
test_output'
test_done