Sparse checkout
v2 cover Sparse checkout
Another RFC, which is more usable than the last series I sent out. Compared to the last one, a few more patches have gone the way of Dodo; 'git shape-workdir' has become a hook and should be easier to write too. All you need is a few
"git update-index --[no-]assume-unchanged" in .git/hooks/sparse.
Nguyễn Thái Ng�c Duy (4):
Prevent diff machinery from examining assume-unchanged entries on
worktree
gitignore: read from index if .gitignore is assume-unchanged unpack_trees(): add support for sparse checkout
read-tree: add --no-sparse to turn off sparse hook
Documentation/technical/api-directory-listing.txt | 3 + builtin-clean.c | 5 +- builtin-ls-files.c | 4 +- builtin-read-tree.c | 4 +- cache.h | 3 + diff-lib.c | 5 +- dir.c | 70 +++++++--- t/t1009-read-tree-sparse.sh | 48 +++++++ t/t3001-ls-files-others-exclude.sh | 20 +++ t/t4039-diff-assume-unchanged.sh | 31 ++++ t/t7300-clean.sh | 19 +++ unpack-trees.c | 154 ++++++++++++++++++++- unpack-trees.h | 3 + 13 files changed, 335 insertions(+), 34 deletions(-) create mode 100755 t/t1009-read-tree-sparse.sh create mode 100755 t/t4039-diff-assume-unchanged.sh
RFC PATCH v2 1/4 Prevent diff machinery from examining assume-unchanged entries on worktree
--- diff-lib.c | 5 +++-- t/t4039-diff-assume-unchanged.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) create mode 100755 t/t4039-diff-assume-unchanged.sh
diff-lib.c +3 -2
@@ -159,7 +159,7 @@ int run_diff_files(struct rev_info *revs, unsigned int option)continue ; } -if (ce_uptodate (ce)) +if (ce_uptodate (ce) || (ce->ce_flags &CE_VALID ))continue ; changed =check_removed (ce, &st);
@@ -337,6 +337,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,struct rev_info *revs = o->unpack_data;int match_missing, cached; +/* if the entry is not checked out, don't examine work tree */ + cached = o->index_only || (idx && (idx->ce_flags &CE_VALID ));/* * Backward compatibility wart - "diff-index -m" does * not mean "do not ignore merges", but "match_missing".
@@ -344,7 +346,6 @@ static void do_oneway_diff(struct unpack_trees_options *o,* But with the revision flag parsing, that's found in * "!revs->ignore_merges". */ - cached = o->index_only; match_missing = !revs->ignore_merges;if (cached && idx &&ce_stage (idx)) {
t/t4039-diff-assume-unchanged.sh new file +31 -0
@@ -0,0 +1,31 @@ +#!/bin/sh + +test_description='diff with assume-unchanged entries' + +. ./test-lib.sh + +# external diff has been tested in t4020-diff-external.sh + +test_expect_success 'setup' ' + echo zero > zero && + git add zero && + git commit -m zero && + echo one > one && + echo two > two && + git add one two && + git commit -m onetwo && + git update-index --assume-unchanged one && + echo borked >> one && + test "$(git ls-files -v one)" = "h one" +' + +test_expect_success 'diff-index does not examine assume-unchanged entries' ' + git diff-index HEAD^ -- one | grep -q 5626abf0f72e58d7a153368ba57db4c673c0e171 +' + +# TODO ced_uptodate() +test_expect_success 'diff-files does not examine assume-unchanged entries' ' + /usr/bin/git diff-files -- one +' + +test_done
Signature · 1 line
1.6.3.GIT
RFC PATCH v2 2/4 gitignore: read from index if .gitignore is assume-unchanged
In sparse checkout mode (aka CE_VALID or assume-unchanged) some files may be missing from working directory. If some of those files are .gitignore, it will affect how git excludes files.
Because those files are by definition "assume unchanged" we can instead read them from index. This adds index as a prerequisite for directory listing. At the moment directory listing is used by "git clean", "git add", "git ls-files" and "git status"/"git commit" and unpack_trees()-related commands. These commands have been checked/modified to populate index before doing directory listing.
--- Documentation/technical/api-directory-listing.txt | 3 + builtin-clean.c | 5 +- builtin-ls-files.c | 4 +- dir.c | 70 ++++++++++++++------- t/t3001-ls-files-others-exclude.sh | 20 ++++++ t/t7300-clean.sh | 19 ++++++ 6 files changed, 96 insertions(+), 25 deletions(-)
Documentation/technical/api-directory-listing.txt +3 -0
@@ -58,6 +58,9 @@ The result of the enumeration is left in these fields:: Calling sequence ---------------- +* Ensure the_index is populated as it may have CE_VALID entries that + affect directory listing. + * Prepare `struct dir_struct dir` and clear it with `memset(&dir, 0, sizeof(dir))`.
builtin-clean.c +4 -1
@@ -71,8 +71,11 @@ int cmd_clean(int argc, const char **argv, const char *prefix) dir.flags |=DIR_SHOW_OTHER_DIRECTORIES ; -if (!ignored) +if (!ignored) { +if (read_cache () <0 ) +die ("index file corrupt" );setup_standard_excludes (&dir); + } pathspec =get_pathspec (prefix, argv);read_cache ();
builtin-ls-files.c +3 -1
@@ -481,6 +481,9 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) prefix_offset =strlen (prefix);git_config (git_default_config,NULL ); +if (read_cache () <0 ) +die ("index file corrupt" ); + argc =parse_options (argc, argv, prefix, builtin_ls_files_options, ls_files_usage,0 );if (show_tag || show_valid_bit) {
@@ -508,7 +511,6 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) pathspec =get_pathspec (prefix, argv);/* be nice with submodule paths ending in a slash */ -read_cache ();if (pathspec)strip_trailing_slash_from_submodules ();
dir.c +47 -23
109 lines not on this page · raw message
t/t3001-ls-files-others-exclude.sh +20 -0
@@ -85,6 +85,26 @@ test_expect_success \ >output && test_cmp expect output' +test_expect_success 'setup sparse gitignore' ' + git add .gitignore one/.gitignore one/two/.gitignore && + git update-index --assume-unchanged .gitignore one/.gitignore one/two/.gitignore && + rm .gitignore one/.gitignore one/two/.gitignore +' + +test_expect_success \ + 'git ls-files --others with various exclude options.' \ + 'git ls-files --others \ + --exclude=\*.6 \ + --exclude-per-directory=.gitignore \ + --exclude-from=.git/ignore \ + >output && + test_cmp expect output' + +test_expect_success 'restore gitignore' ' + git checkout .gitignore one/.gitignore one/two/.gitignore && + rm .git/index +' + cat > excludes-file <<\EOF *.[1-8] e*
t/t7300-clean.sh +19 -0
@@ -22,6 +22,25 @@ test_expect_success 'setup' ' ' +test_expect_success 'git clean with assume-unchanged .gitignore' ' + git update-index --assume-unchanged .gitignore && + rm .gitignore && + mkdir -p build docs && + touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && + git clean && + test -f Makefile && + test -f README && + test -f src/part1.c && + test -f src/part2.c && + test ! -f a.out && + test ! -f src/part3.c && + test -f docs/manual.txt && + test -f obj.o && + test -f build/lib.so && + git update-index --no-assume-unchanged .gitignore && + git checkout .gitignore +' + test_expect_success 'git clean' ' mkdir -p build docs &&
Signature · 1 line
1.6.3.GIT
RFC PATCH v2 3/4 unpack_trees(): add support for sparse checkout
This patch teaches unpack_trees() to checkout/remove entries on working directories appropriately when sparse checkout area is changed. Hook "sparse" is needed to help determine which entry will be checked out, which will not be.
When the hook is run, it is prepared with a pseudo index. The hook then can use "git update-index --[no-]assume-unchanged" to manipulate the index. It should not do anything else on the index. Assume unchanged information from the index will be used to shape working directory.
--- cache.h | 3 + t/t1009-read-tree-sparse.sh | 42 ++++++++++++ unpack-trees.c | 152 +++++++++++++++++++++++++++++++++++++++++-- unpack-trees.h | 2 + 4 files changed, 193 insertions(+), 6 deletions(-) create mode 100755 t/t1009-read-tree-sparse.sh
cache.h +3 -0
@@ -177,6 +177,9 @@ struct cache_entry {#define CE_HASHED (0x100000)#define CE_UNHASHED (0x200000) +/* Only remove in work directory, not index */ +#define CE_WT_REMOVE (0x400000) +/* * Extended on-disk flags */
t/t1009-read-tree-sparse.sh new file +42 -0
42 lines not on this page · raw message
unpack-trees.c +146 -6
212 lines not on this page · raw message
unpack-trees.h +2 -0
@@ -14,6 +14,8 @@ struct unpack_trees_error_msgs {const char *not_uptodate_dir;const char *would_lose_untracked;const char *bind_overlap; +const char *sparse_not_uptodate_file; +const char *would_lose_orphaned; };struct unpack_trees_options {
Signature · 1 line
1.6.3.GIT
RFC PATCH v2 4/4 read-tree: add --no-sparse to turn off sparse hook
--- builtin-read-tree.c | 4 +++- t/t1009-read-tree-sparse.sh | 6 ++++++ unpack-trees.c | 6 ++++-- unpack-trees.h | 1 + 4 files changed, 14 insertions(+), 3 deletions(-)
builtin-read-tree.c +3 -1
@@ -31,7 +31,7 @@ static int list_tree(unsigned char *sha1) }static const char *const read_tree_usage[] = { -"git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u [--exclude-per-directory=<gitignore>] | -i]] [--index-output=<file>] <tree-ish1> [<tree-ish2> [<tree-ish3>]]" , +"git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u [--exclude-per-directory=<gitignore>] | -i]] [--no-sparse] [--index-output=<file>] <tree-ish1> [<tree-ish2> [<tree-ish3>]]" ,NULL };
@@ -98,6 +98,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix) PARSE_OPT_NONEG, exclude_per_directory_cb }, OPT_SET_INT('i', NULL, &opts.index_only, "don't check the working tree after merging", 1), + OPT_SET_INT(0, "no-sparse", &opts.no_sparse_hook, + "do not run sparse hook", 1),OPT_END () };
t/t1009-read-tree-sparse.sh +6 -0
@@ -39,4 +39,10 @@ test_expect_success 're-add one' ' test -f one ' +test_expect_success 'read-tree --no-sparse' ' + make_hook "git update-index --assume-unchanged one" + git read-tree -u -m --no-sparse HEAD && + test -f one +' + test_done
unpack-trees.c +4 -2
@@ -530,8 +530,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_optionsif (o->trivial_merges_only && o->nontrivial_merge)return unpack_failed (o,"Merge requires file-level merging" ); -if (run_sparse_hook (o)) -return unpack_failed (o,NULL ); +if (!o->no_sparse_hook) { +if (run_sparse_hook (o)) +return unpack_failed (o,NULL ); + } o->src_index =NULL ; ret =check_updates (o) ? (-2 ) :0 ;
unpack-trees.h +1 -0
@@ -30,6 +30,7 @@ struct unpack_trees_options { skip_unmerged, initial_checkout, diff_index_cached, + no_sparse_hook, gently;const char *prefix;int pos;
Signature · 1 line
1.6.3.GIT
Re: [RFC PATCH v2 4/4] read-tree: add --no-sparse to turn off sparse hook
Hi,
Quoted 5 lines · Nguyễn Thái Ngọc Duy
unpack-trees.c +0
-0
unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 537
Quoted 10 lines
unpack-trees.c +4
-2@@ -530,8 +530,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_optionsif (o->trivial_merges_only && o->nontrivial_merge)return unpack_failed (o,"Merge requires file-level merging" ); -if (run_sparse_hook (o)) -return unpack_failed (o,NULL ); +if (!o->no_sparse_hook) { +if (run_sparse_hook (o)) +return unpack_failed (o,NULL ); + }
IMHO this would read nicelier as
if (!o->no_sparse_hook && run_sparse_hook(o)) return unpack_failed(o, NULL);
unpack-trees.h struct unpack_trees_options { · line 34
Quoted 10 lines
unpack-trees.h +1
-0@@ -30,6 +30,7 @@ struct unpack_trees_options { skip_unmerged, initial_checkout, diff_index_cached, + no_sparse_hook, gently;
Hmm. I understand that the assumption is that memset(&opts, 0, sizeof(opts)); should give you a sensible default, but I cannot avoid noticing that "no_sparse_hook = 0" is a double negation, something to be avoided...
Thanks,
Dscho
Re: [RFC PATCH v2 4/4] read-tree: add --no-sparse to turn off sparse hook
2009/8/10 Johannes Schindelin <[email protected]>:
Quoted 22 lines
Hi,
Quoted 5 lines · Nguyễn Thái Ngọc Duy
unpack-trees.c +0
-0unpack-trees.c int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options · line 537
Quoted 10 lines
unpack-trees.c +4
-2@@ -530,8 +530,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options if (o->trivial_merges_only && o->nontrivial_merge) return unpack_failed(o, "Merge requires file-level merging"); - if (run_sparse_hook(o)) - return unpack_failed(o, NULL); + if (!o->no_sparse_hook) { + if (run_sparse_hook(o)) + return unpack_failed(o, NULL); + }IMHO this would read nicelier as
Quoted 2 lines
if (!o->no_sparse_hook &&
run_sparse_hook(o)) returnunpack_failed(o, NULL);
Right.
Quoted 7 lines
Quoted 7 lines
unpack-trees.h +0
-0@@ -30,6 +30,7 @@ struct unpack_trees_options { skip_unmerged, initial_checkout,
Quoted 8 lines
unpack-trees.h struct unpack_trees_options { · line 34
Quoted 3 lines
unpack-trees.h +1
-0diff_index_cached, + no_sparse_hook, gently;Hmm. I understand that the assumption is that
memset(&opts, 0, sizeof(opts)); should give you a sensible default, but I cannot avoid noticing that "no_sparse_hook= 0" is a double negation, something to be avoided...
skip_sparse_hook then? :-)
Signature · 1 line
Duy
Re: [RFC PATCH v2 4/4] read-tree: add --no-sparse to turn off sparse hook
Quoted 6 lines · Nguyen Thai Ngoc Duy
Quoted 4 lines
Hmm. I understand that the assumption is that
memset(&opts, 0, sizeof(opts)); should give you a sensible default, but I cannot avoid noticing that "no_sparse_hook= 0" is a double negation, something to be avoided...
skip_sparse_hookthen? :-)
Why not making the hook to be skipped by default, and pass an explicit option to trigger the hook?
I like Dscho's other suggestion to use patterns like .gitignore instead of using hook scripts that needs to be ported across platforms, by the way.
Re: [RFC PATCH v2 4/4] read-tree: add --no-sparse to turn off sparse hook
Hi,
Quoted 8 lines · Junio C Hamano
Quoted 6 lines · Nguyen Thai Ngoc Duy
Quoted 4 lines
Hmm. I understand that the assumption is that
memset(&opts, 0, sizeof(opts)); should give you a sensible default, but I cannot avoid noticing that "no_sparse_hook= 0" is a double negation, something to be avoided...
skip_sparse_hookthen? :-)
It nicely avoids the double negation, indeed.
Quoted 6 lines
Why not making the hook to be skipped by default, and pass an explicit option to trigger the hook?
I like Dscho's other suggestion to use patterns like .gitignore instead of using hook scripts that needs to be ported across platforms, by the way.
I forgot to mention that I checked dir.c to verify that add_excludes_from_file_1() (which is static, so you'll either need to use it in the same file, or even better, export it renaming it to something like add_excludes_from_file_to_list()) and excluded_1() (same here) already do a large part of what you need.
Ciao,
Dscho
Re: [RFC PATCH v2 4/4] read-tree: add --no-sparse to turn off sparse hook
Quoted 7 lines · Johannes Schindelin
Quoted 6 lines
Why not making the hook to be skipped by default, and pass an explicit option to trigger the hook?
I like Dscho's other suggestion to use patterns like .gitignore instead of using hook scripts that needs to be ported across platforms, by the way.
Quoted 5 lines
I forgot to mention that I checked
dir.cto verify thatadd_excludes_from_file_1()(which is static, so you'll either need to use it in the same file, or even better, export it renaming it to something likeadd_excludes_from_file_to_list()) andexcluded_1()(same here) already do a large part of what you need.
Indeed (and I have that code too). I still like the hook though because you have more freedom in defining your worktree (and yes, less portable). I wanted to make something generic enough that you can build higher "strategies" on top, like .gitignore-based patterns. Anyway I'll send out another patch for .gitignore patterns tonight and see how it goes.
Signature · 1 line
Duy
Re: [RFC PATCH v2 3/4] unpack_trees(): add support for sparse checkout
In reply to Nguyễn Thái Ngọc DuyHi,
Quoted 9 lines · Nguyễn Thái Ngọc Duy
This patch teaches
unpack_trees()to checkout/remove entries on working directories appropriately when sparse checkout area is changed. Hook "sparse" is needed to help determine which entry will be checked out, which will not be.When the hook is run, it is prepared with a pseudo index. The hook then can use "git update-index --[no-]assume-unchanged" to manipulate the index. It should not do anything else on the index. Assume unchanged information from the index will be used to shape working directory.
If I understand correctly, the purpose of the hook is to allow the user to mark something as unwanted preemptively, right?
If that is the sole reason for the hook, would it not be better to add support for a file .git/info/sparse which has the same syntax as .git/info/exclude, and which is used to determine if an added/modified/deleted file is supposed to be in the "sparse" area or not?
Something like
* !/Documentation/
comes to mind.
Thanks,
Dscho
Re: [RFC PATCH v2 3/4] unpack_trees(): add support for sparse checkout
2009/8/10 Johannes Schindelin <[email protected]>:
Quoted 22 lines
Hi,
Quoted 9 lines · Nguyễn Thái Ngọc Duy
This patch teaches
unpack_trees()to checkout/remove entries on working directories appropriately when sparse checkout area is changed. Hook "sparse" is needed to help determine which entry will be checked out, which will not be.When the hook is run, it is prepared with a pseudo index. The hook then can use "git update-index --[no-]assume-unchanged" to manipulate the index. It should not do anything else on the index. Assume unchanged information from the index will be used to shape working directory.
If I understand correctly, the purpose of the hook is to allow the user to mark something as unwanted preemptively, right?
If that is the sole reason for the hook, would it not be better to add support for a file .git/info/sparse which has the same syntax as .git/info/exclude, and which is used to determine if an added/modified/deleted file is supposed to be in the "sparse" area or not?
Quoted 6 lines
Something like
*
!/Documentation/comes to mind.
That was what the original series was about (although I used git config instead of .git/info/sparse). The hook has two advantages:
- flexibility: you can set things differently based on branch, for
example, or filter files based on certain file content.
- less code bloat (and less intrusive too), compare ~1000 lines of
change of the original series with this series.
Signature · 1 line
Duy
Re: [RFC PATCH v2 3/4] unpack_trees(): add support for sparse checkout
Hi,
Quoted 29 lines · Nguyen Thai Ngoc Duy
2009/8/10 Johannes Schindelin <[email protected]>:
Quoted 27 lines · Nguyễn Thái Ngọc Duy
Quoted 11 lines
This patch teaches
unpack_trees()to checkout/remove entries on working directories appropriately when sparse checkout area is changed. Hook "sparse" is needed to help determine which entry will be checked out, which will not be.When the hook is run, it is prepared with a pseudo index. The hook then can use "git update-index --[no-]assume-unchanged" to manipulate the index. It should not do anything else on the index. Assume unchanged information from the index will be used to shape working directory.
If I understand correctly, the purpose of the hook is to allow the user to mark something as unwanted preemptively, right?
If that is the sole reason for the hook, would it not be better to add support for a file .git/info/sparse which has the same syntax as .git/info/exclude, and which is used to determine if an added/modified/deleted file is supposed to be in the "sparse" area or not?
Something like
*
!/Documentation/
Quoted 7 lines
Quoted 1 line
comes to mind.
That was what the original series was about (although I used git config instead of .git/info/sparse). The hook has two advantages:
- flexibility: you can set things differently based on branch, for example, or filter files based on certain file content.
True, it is flexible. The question is: is it not too flexible for its own good?
Having to introduce a hook means that every user either must trust another person and install the unmodified hook, or write the hook herself for every narrow work tree.
The branch use case you mentioned is maybe a good example what I mean by "too flexible":
- it is easy to get confused which parts are narrow or not if the hook can change that depending on, say, the phase of the moon (okay, okay, depending on the branch, but it is still confusing),
- the whole purpose of narrow checkout is to avoid having to check out stuff that does not affect you. Chances are that 99.99% of all "narrow" users do not need to modify which slice of the files they want to see, and those who do are probably better off with two work trees, methinks.
Quoted 2 lines
- less code bloat (and less intrusive too), compare ~1000 lines of change of the original series with this series.
Heh, see my other mail. I'm sorry I forgot to mention that the similarity to .gitignore spares you a lot of code...
Ciao,
Dscho
Re: [RFC PATCH v2 2/4] gitignore: read from index if .gitignore is assume-unchanged
In reply to Nguyễn Thái Ngọc DuyHi,
dir.c void add_exclude(const char *string, const char *base, · line 203
Quoted 9 lines · Nguyễn Thái Ngọc Duy
dir.c +1
-0@@ -200,11 +200,36 @@ void add_exclude(const char *string, const char *base, which->excludes[which->nr++] = x; } +static void *read_index_data (const char *path,size_t *size)
How about calling it "read_assume_unchanged_from_index()" instead? I suggest this because it does not read the index from the data if the path is not marked assume unchanged...
Quoted 5 lines
dir.c +0
-0@@ -212,27 +237,31 @@ static int add_excludes_from_file_1(const char *fname,if (buf_p)
dir.c static int add_excludes_from_file_1(const char *fname, · line 267
Quoted 10 lines
dir.c +2
-3*buf_p = buf; - buf[size++] ='\n' ; entry = buf; -for (i =0 ; i < size; i++) { -if (buf[i] =='\n' ) { +for (i =0 ; i <= size; i++) { +if (i == size || buf[i] =='\n' ) {if (entry != buf + i && entry[0 ] !='#' ) { buf[i - (i && buf[i-1 ] =='\r' )] =0 ;add_exclude (entry, base, baselen, which);
Should this change not rather be a separate one?
Quoted 6 lines
dir.c +0
-2@@ -241,17 +270,12 @@ static int add_excludes_from_file_1(const char *fname, } }return 0 ; - - err:
dir.c static int add_excludes_from_file_1(const char *fname, · line 278
Quoted 10 lines
dir.c +1
-4-if (0 <= fd) -close (fd); -return -1 ; }void add_excludes_from_file (struct dir_struct *dir,const char *fname) {if (add_excludes_from_file_1 (fname,"" ,0 ,NULL , - &dir->exclude_list[EXC_FILE ]) <0 ) + &dir->exclude_list[EXC_FILE ],0 ) <0 )
Could you mention in the commit message why this function does not want to check the index (I _guess_ it is because this code path only tries to read .git/info/exclude, but it would be better to be sure).
Quoted 17 lines
dir.c +1
-1die ("cannot use %s as an exclude file" , fname); }@@ -302,7 +326,7 @@ static void prep_exclude(struct dir_struct *dir, const char *base, int baselen)strcpy (dir->basebuf + stk->baselen, dir->exclude_per_dir);add_excludes_from_file_1 (dir->basebuf, dir->basebuf, stk->baselen, - &stk->filebuf, el); + &stk->filebuf, el,1 ); dir->exclude_stack = stk; current = stk->baselen; }t/t3001-ls-files-others-exclude.sh +0
-0
t/t3001-ls-files-others-exclude.sh test_expect_success \ · line 92
Quoted 8 lines
t/t3001-ls-files-others-exclude.sh +5
-0@@ -85,6 +85,26 @@ test_expect_success \ >output && test_cmp expect output' +test_expect_success 'setup sparse gitignore' ' + git add .gitignore one/.gitignore one/two/.gitignore && + git update-index --assume-unchanged .gitignore one/.gitignore one/two/.gitignore && + rm .gitignore one/.gitignore one/two/.gitignore +'
You're probably less sloppy than me; I'd have defined a variable like this:
ignores=".gitignore one/.gitignore one/two/.gitignore"
and used it for the three calls, just to make sure that I do not fsck anything up there due to fat fingers.
Thanks,
Dscho
Re: [RFC PATCH v2 2/4] gitignore: read from index if .gitignore is assume-unchanged
2009/8/10 Johannes Schindelin <[email protected]>:
Quoted 12 lines
Hi,
Quoted 8 lines · Nguyễn Thái Ngọc Duy
dir.c +0
-0@@ -200,11 +200,36 @@ void add_exclude(const char *string, const char *base, which->excludes[which->nr++] = x; }
Quoted 5 lines
dir.c void add_exclude(const char *string, const char *base, · line 203
Quoted 1 line
dir.c +1
-0+static void *read_index_data (const char *path,size_t *size)How about calling it "
read_assume_unchanged_from_index()" instead? I suggest this because it does not read the index from the data if the path is not marked assume unchanged...
Agree.
Quoted 4 lines
Quoted 4 lines
dir.c +0
-0@@ -212,27 +237,31 @@ static int add_excludes_from_file_1(const char *fname,
Quoted 13 lines
Quoted 11 lines
if (
buf_p)
*buf_p= buf;
- buf[size++] = '\n';
entry = buf;
- for (i = 0; i < size; i++) {
- if (buf[i] == '\n') {
+ for (i = 0; i <= size; i++) {
+ if (i == size || buf[i] == '\n') {
if (entry != buf + i && entry[0] != '#') { buf[i - (i && buf[i-1] == '\r')] = 0;add_exclude(entry, base, baselen, which);Should this change not rather be a separate one?
You meant a separate patch? It is tied to this patch, because if bus is read from read_index_data, it does not have extra space for '\n' at the end.
Quoted 11 lines
Quoted 11 lines
dir.c +0
-5@@ -241,17 +270,12 @@ static int add_excludes_from_file_1(const char *fname, } } return 0; - - err: - if (0 <= fd) - close(fd); - return -1; }
Quoted 9 lines
dir.c static int add_excludes_from_file_1(const char *fname, · line 278
Quoted 5 lines
dir.c +1
-1void add_excludes_from_file(struct dir_struct *dir, const char *fname) { if (add_excludes_from_file_1(fname, "", 0, NULL, - &dir->exclude_list[EXC_FILE]) < 0) + &dir->exclude_list[EXC_FILE], 0) < 0)Could you mention in the commit message why this function does not want to check the index (I _guess_ it is because this code path only tries to read .git/info/exclude, but it would be better to be sure).
To retain old behaviour. But I have to check its callers. Maybe we want to check the index too.
Quoted 13 lines
Quoted 9 lines
dir.c +0
-0@@ -85,6 +85,26 @@ test_expect_success \>output &&
test_cmpexpect output'+test_expect_success 'setup sparse gitignore' '
+ git add .gitignore one/.gitignore one/two/.gitignore &&
+ git update-index --assume-unchanged .gitignore one/.gitignore one/two/.gitignore &&
+ rm .gitignore one/.gitignore one/two/.gitignore
+'You're probably less sloppy than me; I'd have defined a variable like this:
Quoted 4 lines
ignores=".gitignore one/.gitignore one/two/.gitignore"
and used it for the three calls, just to make sure that I do not fsck anything up there due to fat fingers.
I have slim ones :-) But "git add $ignores && git update-index $ignores && rm $ignores" is easier to read.
Signature · 1 line
Duy
Re: [RFC PATCH v2 2/4] gitignore: read from index if .gitignore is assume-unchanged
Hi,
Quoted 22 lines · Nguyen Thai Ngoc Duy
2009/8/10 Johannes Schindelin <[email protected]>:
Quoted 6 lines · Nguyễn Thái Ngọc Duy
Quoted 5 lines
(quoted diff) +0
-0@@ -212,27 +237,31 @@ static int add_excludes_from_file_1(const char *fname,Quoted 13 lines
Quoted 11 lines
if (
buf_p)
*buf_p= buf;
- buf[size++] = '\n';
entry = buf;
- for (i = 0; i < size; i++) {
- if (buf[i] == '\n') {
+ for (i = 0; i <= size; i++) {
+ if (i == size || buf[i] == '\n') {
if (entry != buf + i && entry[0] != '#') { buf[i - (i && buf[i-1] == '\r')] = 0;add_exclude(entry, base, baselen, which);Should this change not rather be a separate one?
Quoted 1 line
You meant a separate patch?
Yes, sorry, I meant exactly that.
Quoted 2 lines
It is tied to this patch, because if bus is read from
read_index_data, it does not have extra space for '\n' at the end.
But you could separate it out as a patch that just avoids writing to buf. IMHO this would make following the patch series easier.
Quoted 21 lines
Quoted 11 lines
Quoted 11 lines
dir.c +0
-5@@ -241,17 +270,12 @@ static int add_excludes_from_file_1(const char *fname, } } return 0; - - err: - if (0 <= fd) - close(fd); - return -1; }Quoted 9 lines
dir.c static int add_excludes_from_file_1(const char *fname, · line 278
Quoted 5 lines
dir.c +1
-1void add_excludes_from_file(struct dir_struct *dir, const char *fname) { if (add_excludes_from_file_1(fname, "", 0, NULL, - &dir->exclude_list[EXC_FILE]) < 0) + &dir->exclude_list[EXC_FILE], 0) < 0)Could you mention in the commit message why this function does not want to check the index (I _guess_ it is because this code path only tries to read .git/info/exclude, but it would be better to be sure).
Quoted 2 lines
To retain old behaviour. But I have to check its callers. Maybe we want to check the index too.
Yes, it would be good to illustrate in the commit message which code paths want to check the index, and why.
Quoted 13 lines
Quoted 13 lines
Quoted 9 lines
(quoted diff) +0
-0@@ -85,6 +85,26 @@ test_expect_success \>output &&
test_cmpexpect output'+test_expect_success 'setup sparse gitignore' '
+ git add .gitignore one/.gitignore one/two/.gitignore &&
+ git update-index --assume-unchanged .gitignore one/.gitignore one/two/.gitignore &&
+ rm .gitignore one/.gitignore one/two/.gitignore
+'You're probably less sloppy than me; I'd have defined a variable like this:
Quoted 6 lines
Quoted 4 lines
ignores=".gitignore one/.gitignore one/two/.gitignore"
and used it for the three calls, just to make sure that I do not fsck anything up there due to fat fingers.
I have slim ones :-)
Oh, don't get me wrong: my fingers are slim enough to play piano, and even to write pretty fast on my EeePC 701.
But darn, there are days when they feel as if they were thick like a brick.
Ciao,
Dscho
Re: [RFC PATCH v2 1/4] Prevent diff machinery from examining assume-unchanged entries on worktree
In reply to Nguyễn Thái Ngọc DuyHi,
Quoted 14 lines · Nguyễn Thái Ngọc Duy
diff-lib.c +2
-0@@ -337,6 +337,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,struct rev_info *revs = o->unpack_data;int match_missing, cached; +/* if the entry is not checked out, don't examine work tree */ + cached = o->index_only || (idx && (idx->ce_flags &CE_VALID ));/* * Backward compatibility wart - "diff-index -m" does * not mean "do not ignore merges", but "match_missing".
diff-lib.c static void do_oneway_diff(struct unpack_trees_options *o, · line 351
Quoted 7 lines
diff-lib.c +0
-1@@ -344,7 +346,6 @@ static void do_oneway_diff(struct unpack_trees_options *o,* But with the revision flag parsing, that's found in * "!revs->ignore_merges". */ - cached = o->index_only; match_missing = !revs->ignore_merges;if (cached && idx &&ce_stage (idx)) {
Out of curiosity: why did that line have to move up?
Ciao,
Dscho
Quoted 16 lines
t/t4039-diff-assume-unchanged.sh new file +10
-0@@ -0,0 +1,31 @@ +#!/bin/sh + +test_description='diff with assume-unchanged entries' + +. ./test-lib.sh + +# external diff has been tested in t4020-diff-external.sh + +test_expect_success 'setup' ' + echo zero > zero &&
t/t4039-diff-assume-unchanged.sh line 20
Quoted 10 lines
t/t4039-diff-assume-unchanged.sh new file +10
-0+ git add zero && + git commit -m zero && + echo one > one && + echo two > two && + git add one two && + git commit -m onetwo && + git update-index --assume-unchanged one && + echo borked >> one && + test "$(git ls-files -v one)" = "h one" +'
Maybe use test_commit, to make it more readable?
t/t4039-diff-assume-unchanged.sh line 26
Quoted 6 lines
t/t4039-diff-assume-unchanged.sh new file +6
-0+ +test_expect_success 'diff-index does not examine assume-unchanged entries' ' + git diff-index HEAD^ -- one | grep -q 5626abf0f72e58d7a153368ba57db4c673c0e171 +' + +# TODO ced_uptodate()
What is this about?
t/t4039-diff-assume-unchanged.sh line 31
Quoted 5 lines
t/t4039-diff-assume-unchanged.sh new file +5
-0+test_expect_success 'diff-files does not examine assume-unchanged entries' ' + /usr/bin/git diff-files -- one +' + +test_done
Thanks,
Dscho
Re: [RFC PATCH v2 1/4] Prevent diff machinery from examining assume-unchanged entries on worktree
2009/8/10 Johannes Schindelin <[email protected]>:
Quoted 13 lines
Quoted 4 lines
+test_expect_success 'setup' '
+ echo zero > zero &&
+ git add zero &&
+ git commit -m zero &&Quoted 8 lines
+ echo one > one &&
+ echo two > two &&
+ git add one two &&
+ git commit -m onetwo &&
+ git update-index --assume-unchanged one &&
+ echo borked >> one &&
+ test "$(git ls-files -v one)" = "h one"
+'
Quoted 1 line
Maybe use
test_commit, to make it more readable?
Thanks. I did not know that (or forgot already). Will use it.
Quoted 9 lines
t/t4039-diff-assume-unchanged.sh line 26
Quoted 7 lines
t/t4039-diff-assume-unchanged.sh new file +6
-0+ +test_expect_success 'diff-index does not examine assume-unchanged entries' ' + git diff-index HEAD^ -- one | grep -q 5626abf0f72e58d7a153368ba57db4c673c0e171 +' + +# TODO ced_uptodate()What is this about?
It tests "if (ce_uptodate(ce) || (ce->ce_flags & CE_VALID))" and I was pretty sure it hit ce_uptodate() first, so the second expression was not tested.
Signature · 1 line
Duy
Re: [RFC PATCH v2 1/4] Prevent diff machinery from examining assume-unchanged entries on worktree
Hi,
Quoted 11 lines · Nguyen Thai Ngoc Duy
Quoted 7 lines
t/t4039-diff-assume-unchanged.sh line 26
Quoted 5 lines
t/t4039-diff-assume-unchanged.sh new file +5
-0+test_expect_success 'diff-index does not examine assume-unchanged entries' ' + git diff-index HEAD^ -- one | grep -q 5626abf0f72e58d7a153368ba57db4c673c0e171 +' + +# TODO ced_uptodate()What is this about?
It tests "if (
ce_uptodate(ce)|| (ce->ce_flags&CE_VALID))" and I was pretty sure it hitce_uptodate()first, so the second expression was not tested.
Ah. I was distracted by the "d" before the underscore.
ce_uptodate(ce) checks the time stamp amongst other things, right? How about using test-chmtime to force an mtime mismatch?
Ciao,
Dscho