Sparse checkout, the last half of the series
cover Sparse checkout, the last half of the series
This series is almost identical to my last sent series with bug fixes. Documentation is hopefully detail enough so I don't have to say more here.
Nguyễn Thái Ng�c Duy (8):
generate-cmdlist.sh: avoid selecting synopsis at wrong place Introduce "sparse patterns"
unpack_trees(): keep track of unmerged entries unpack_trees(): add support for sparse checkout
clone: support sparse checkout with --sparse-checkout option
checkout: add new options to support sparse checkout Introduce default sparse patterns (core.defaultsparse)
wt-status: show sparse checkout info
Documentation/config.txt | 10 + Documentation/git-checkout.txt | 133 ++++++++++++++- Documentation/git-clone.txt | 11 +- Documentation/git-ls-files.txt | 8 +- builtin-checkout.c | 93 ++++++++++ builtin-clone.c | 16 ++ builtin-ls-files.c | 23 ++- builtin-read-tree.c | 3 +- cache.h | 5 + config.c | 5 + environment.c | 1 + generate-cmdlist.sh | 2 +- t/t2011-checkout-sparse.sh | 147 ++++++++++++++++ t/t3003-ls-files-narrow-match.sh | 41 +++++ t/t3003/1 | 4 + t/t3003/12 | 8 + t/t3003/clone-escape | 5 + t/t3003/cur-12 | 2 + t/t3003/prefix-sub2 | 3 + t/t3003/root-sub-1 | 1 + t/t3003/slash-1 | 1 + t/t3003/sub-1 | 2 + t/t3003/sub-only | 3 + t/t3003/subsub-slash | 3 + t/t5703-clone-narrow.sh | 42 +++++ unpack-trees.c | 360 +++++++++++++++++++++++++++++++++++++- unpack-trees.h | 29 +++ wt-status.c | 44 +++++ wt-status.h | 1 + 29 files changed, 988 insertions(+), 18 deletions(-) create mode 100755 t/t2011-checkout-sparse.sh create mode 100755 t/t3003-ls-files-narrow-match.sh create mode 100644 t/t3003/1 create mode 100644 t/t3003/12 create mode 100644 t/t3003/clone-escape create mode 100644 t/t3003/cur-12 create mode 100644 t/t3003/prefix-sub2 create mode 100644 t/t3003/root-sub-1 create mode 100644 t/t3003/slash-1 create mode 100644 t/t3003/sub create mode 100644 t/t3003/sub-1 create mode 100644 t/t3003/sub-only create mode 100644 t/t3003/subsub-slash create mode 100755 t/t5703-clone-narrow.sh
PATCH 1/8 generate-cmdlist.sh: avoid selecting synopsis at wrong place
In "common" man pages there is luckily no "NAME" anywhere except at beginning of documents. If there is another "NAME", sed could mis-select it and lead to common-cmds.h corruption. So better nail it at beginning of line, which would reduce corruption chance.
--- generate-cmdlist.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
generate-cmdlist.sh +1 -1
@@ -14,7 +14,7 @@ sort | while read cmd do sed -n ' - /NAME/,/git-'"$cmd"'/H + /^NAME/,/git-'"$cmd"'/H ${ x s/.*git-'"$cmd"' - \(.*\)/ {"'"$cmd"'", "\1"},/
Signature · 1 line
1.6.0.3.890.g95457
PATCH 2/8 Introduce "sparse patterns"
Sparse patterns are basically .gitignore patterns, with the following exceptions:
- a leading slash means toplevel working directory
- ./ will be used if you want to apply "slash in pattern" rule, similar to leading slash case in .gitignore
- prefix can be specified in form prefix//pattern
- patterns are separated by colons
"git ls-files --narrow-match" is added to test sparse patterns.
--- Documentation/git-checkout.txt | 57 +++++++++++++ Documentation/git-ls-files.txt | 8 ++- builtin-ls-files.c | 23 +++++- t/t3003-ls-files-narrow-match.sh | 41 +++++++++ t/t3003/1 | 4 + t/t3003/12 | 8 ++ t/t3003/clone-escape | 5 + t/t3003/cur-12 | 2 + t/t3003/prefix-sub2 | 3 + t/t3003/root-sub-1 | 1 + t/t3003/slash-1 | 1 + t/t3003/sub-1 | 2 + t/t3003/sub-only | 3 + t/t3003/subsub-slash | 3 + unpack-trees.c | 170 ++++++++++++++++++++++++++++++++++++++ unpack-trees.h | 20 +++++ 16 files changed, 347 insertions(+), 4 deletions(-) create mode 100755 t/t3003-ls-files-narrow-match.sh create mode 100644 t/t3003/1 create mode 100644 t/t3003/12 create mode 100644 t/t3003/clone-escape create mode 100644 t/t3003/cur-12 create mode 100644 t/t3003/prefix-sub2 create mode 100644 t/t3003/root-sub-1 create mode 100644 t/t3003/slash-1 create mode 100644 t/t3003/sub create mode 100644 t/t3003/sub-1 create mode 100644 t/t3003/sub-only create mode 100644 t/t3003/subsub-slash
Documentation/git-checkout.txt +57 -0
@@ -205,6 +205,63 @@ is "assume unchanged" bit just ignores corresponding files in working directory while sparse checkout goes a bit farther, remove those files when it is safe to do so. +Sparse patterns +--------------- + +Sparse patterns specify how do you want to form your checkout area. +Many patterns can be specified on one line, separated by colons. +The patterns specify what files should or should not be checked out +on working directory (depends on the option used with the patterns). +Patterns have the following format: + + - An optional prefix '!' which negates the pattern; any + matching file by a previous pattern will become + unmatched again. If a negated pattern matches, this will + override lower precedence patterns sources. + + - If the pattern ends with a slash, it is removed for the + purpose of the following description, but it would only find + a match with a directory. In other words, `foo/` will match a + directory `foo` and paths underneath it, but will not match a + regular file or a symbolic link `foo` (this is consistent + with the way how pathspec works in general in git). + + - If the pattern does not contain a slash '/', git treats it as + a shell glob pattern and checks for a match against the + pathname without leading directories. + + - If the pattern contains two consecutive slashes '//', git uses + the first part of the pattern before '//' as prefix to apply + the pattern on, and the rest as "true" sparse pattern. The + pattern will be only applied if pathname has the same prefix. It + is the same as you apply the pattern with the current directory + being the extracted prefix. Prefix will always be relative to + top-level working directory. This could be used to if you want to + apply the above rule only in a specific subdirectory. + + - Otherwise, git treats the pattern as a shell glob suitable + for consumption by fnmatch(3) with the FNM_PATHNAME flag: + wildcards in the pattern will not match a / in the pathname. + For example, "Documentation/\*.html" matches + "Documentation/git.html" but not + "Documentation/ppc/ppc.html". A leading slash matches the + beginning of the pathname; for example, "/*.c" matches + "cat-file.c" but not "mozilla-sha1/sha1.c". + + - Patterns with a leading slash will match against full pathname, + as opposed to normal case when it only matches pathnames relative + to current working directory. + + - Patterns begin with "./" are treated like normal patterns. That is + it will follow above rules. But since it has a slash inside, + "fnmatch rule" will apply. This is a work-around when you do not + want to apply "no slash" rule. + + - Because colons are used to separate patterns, you cannot put them + in patterns directly. You must quote them using backslash. + + - Sparse patterns do not apply to .gitignore and .gitattributes + files. They are always checked out. EXAMPLES --------
Documentation/git-ls-files.txt +7 -1
@@ -12,7 +12,7 @@ SYNOPSIS 'git ls-files' [-z] [-t] [-v] (--[cached|deleted|others|ignored|stage|unmerged|killed|modified|orphaned|no-checkout])\* (-[c|d|o|i|s|u|k|m])\* - [--sparse] + [--sparse] [--narrow-match=<sparse patterns>] [-x <pattern>|--exclude=<pattern>] [-X <file>|--exclude-from=<file>] [--exclude-per-directory=<file>]
@@ -90,6 +90,12 @@ OPTIONS No-checkout entries can be shown using --orphaned or --no-checkout (or both). +--narrow-match=<sparse patterns>:: + This option can be used to test sparse patterns. The given sparse patterns will + be used to filter ls-files output. Entries not matching the spec will be + ignored. This option can only be used with --cached or --stage. + See linkgit:git-checkout[1] for more information about sparse patterns. + -z:: \0 line termination on output.
builtin-ls-files.c +20 -3
@@ -10,6 +10,8 @@#include "dir.h" #include "builtin.h" #include "tree.h" +#include "tree-walk.h" +#include "unpack-trees.h" static int abbrev;static int show_deleted;
@@ -31,6 +33,7 @@ static const char **pathspec;static int error_unmatch;static char *ps_matched;static const char *with_tree; +static struct narrow_spec *narrow_spec;static const char *tag_cached ="" ;static const char *tag_unmerged ="" ;
@@ -158,7 +161,8 @@ static void show_ce_entry(const char *tag, struct cache_entry *ce)int len = prefix_len;int offset = prefix_offset; -if (len >=ce_namelen (ce)) +/* when narrow_spec->full_index is true, the_index is not pruned */ +if (len >=ce_namelen (ce) && (!narrow_spec || !narrow_spec->full_index))die ("git ls-files: internal error - cache entry not superset of prefix" );if (pathspec && !pathspec_match (pathspec, ps_matched, ce->name, len))
@@ -231,6 +235,8 @@ static void show_files(struct dir_struct *dir, const char *prefix) }if (!(show_cached | show_stage))continue ; +if (narrow_spec && !match_narrow_spec (narrow_spec, ce->name)) +continue ;show_ce_entry (ce_stage (ce) ? tag_unmerged : tag_cached, ce); } }
@@ -412,7 +418,7 @@ int report_path_error(const char *ps_matched, const char **pathspec, int prefix_static const char ls_files_usage[] ="git ls-files [-z] [-t] [-v] (--[cached|deleted|others|stage|unmerged|killed|modified|orphaned|no-checkout])* " -"[ --sparse ] " +"[ --sparse ] [--narrow-match=<narrow_spec>] " "[ --ignored ] [--exclude=<pattern>] [--exclude-from=<file>] " "[ --exclude-per-directory=<filename> ] [--exclude-standard] " "[--full-name] [--abbrev] [--] [<file>]*" ;
@@ -471,6 +477,10 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) sparse_checkout =1 ;continue ; } +if (!prefixcmp (arg,"--narrow-match=" )) { + narrow_spec =parse_narrow_spec (arg+15 , prefix); +continue ; + }if (!strcmp (arg,"-d" ) || !strcmp (arg,"--deleted" )) { show_deleted =1 ;continue ;
@@ -602,8 +612,14 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix) show_killed | show_modified | show_orphaned | show_no_checkout)) show_cached =1 ; +if (narrow_spec && !show_cached && !show_stage) +die ("ls-files: --narrow-match can only be used with either --cached or --stage" ); + +if (narrow_spec && narrow_spec->full_index && prefix_offset !=0 ) +die ("ls-files: --narrow-match with root matching patterns requires --full-name" ); +read_cache (); -if (prefix) +if (prefix && (!narrow_spec || !narrow_spec->full_index))prune_cache (prefix);if (with_tree) {/*
@@ -625,5 +641,6 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)return bad ?1 :0 ; } +free_narrow_spec (narrow_spec);return 0 ; }
t/t3003-ls-files-narrow-match.sh new file +41 -0
41 lines not on this page · raw message
t/t3003/1 new file +4 -0
@@ -0,0 +1,4 @@ +1 +sub/1 +sub/subsub/1 +sub2/1
t/t3003/12 new file +8 -0
@@ -0,0 +1,8 @@ +1 +2 +sub/1 +sub/2 +sub/subsub/1 +sub/subsub/2 +sub2/1 +sub2/2
t/t3003/clone-escape new file +5 -0
@@ -0,0 +1,5 @@ +1 +1:2 +sub/1 +sub/subsub/1 +sub2/1
t/t3003/cur-12 new file +2 -0
@@ -0,0 +1,2 @@ +1 +2
t/t3003/prefix-sub2 new file +3 -0
@@ -0,0 +1,3 @@ +sub/1 +sub/subsub/1 +sub2/2
t/t3003/root-sub-1 new file +1 -0
@@ -0,0 +1 @@ +1
t/t3003/slash-1 new file +1 -0
@@ -0,0 +1 @@ +sub/1
t/t3003/sub new file +0 -0
t/t3003/sub-1 new file +2 -0
@@ -0,0 +1,2 @@ +sub/1 +sub/subsub/1
t/t3003/sub-only new file +3 -0
@@ -0,0 +1,3 @@ +sub/1 +sub/2 +sub/3
t/t3003/subsub-slash new file +3 -0
@@ -0,0 +1,3 @@ +sub/subsub/1 +sub/subsub/2 +sub/subsub/3
unpack-trees.c +170 -0
176 lines not on this page · raw message
unpack-trees.h +20 -0
@@ -16,6 +16,23 @@ struct unpack_trees_error_msgs {const char *bind_overlap; }; +struct narrow_spec { +int nr; +int alloc; +int full_index; +char *prefix; +struct narrow_pattern { +int len; +int has_root:1 ; +int has_slashes:1 ; +int has_wildcards:1 ; +int has_trailing_slash:1 ; +int negative:1 ; +char *pattern; +char *prefix; + } **patterns; +}; +struct unpack_trees_options {unsigned int reset:1 , merge:1,
@@ -48,6 +65,9 @@ struct unpack_trees_options {extern int unpack_trees (unsigned n,struct tree_desc *t,struct unpack_trees_options *options); +struct narrow_spec *parse_narrow_spec (const char *spec,const char *prefix); +void free_narrow_spec (struct narrow_spec *spec); +int match_narrow_spec (struct narrow_spec *spec,const char *path);int threeway_merge (struct cache_entry **stages,struct unpack_trees_options *o);int twoway_merge (struct cache_entry **src,struct unpack_trees_options *o);int bind_merge (struct cache_entry **src,struct unpack_trees_options *o);
Signature · 1 line
1.6.0.3.890.g95457
PATCH 3/8 unpack_trees(): keep track of unmerged entries
"git read-tree --reset" will currently remove all unmerged entries in index before feeding the index to unpack_trees(). Because the lack of unmerged entries, these entries, when read from tree, will be seen as "new entries" by {one,two,three}way_merge().
This is fine for now. But for sparse checkout, it needs to know whether an entry is new entry, because it will handle it different way than already-in entry.
So the patch moves "unmerged entries removal" part into unpack_trees(), actually unpack_callback(). The function then can turn on o->has_unmerged flag, which can be utilized by sparse checkout.
--- builtin-read-tree.c | 3 ++- unpack-trees.c | 7 +++++++ unpack-trees.h | 2 ++ 3 files changed, 11 insertions(+), 1 deletions(-)
builtin-read-tree.c +2 -1
@@ -136,9 +136,10 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)if (stage || opts.merge || opts.prefix)usage (read_tree_usage); opts.reset =1 ; + opts.prune_unmerged =1 ; opts.merge =1 ; stage =1 ; -read_cache_unmerged (); +read_cache ();continue ; }
unpack-trees.c +7 -0
@@ -301,6 +301,7 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str/* Are we supposed to look at the index too? */ if (o->merge) { + o->has_unmerged =0 ;while (o->pos < o->src_index->cache_nr) {struct cache_entry *ce = o->src_index->cache[o->pos];int cmp =compare_entry (ce, info, p);
@@ -320,6 +321,12 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, stradd_entry (o, ce,0 ,0 );return mask; } + +if (o->prune_unmerged) { + o->has_unmerged =1 ; +/* leave src[0] as NULL and go over all other staged entries */ +continue ; + } } src[0 ] = ce; }
unpack-trees.h +2 -0
@@ -43,6 +43,8 @@ struct unpack_trees_options { verbose_update:1, aggressive:1, skip_unmerged:1, + prune_unmerged:1, + has_unmerged:1, initial_checkout:1, gently:1;const char *prefix;
Signature · 1 line
1.6.0.3.890.g95457
PATCH 4/8 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. There are three kind of changes:
- new_narrow_path: reset workdir to a completely new checkout area
- add_narrow_path: keep current areas and add more entries
- remove_narrow_path: remove some entries from current areas
When unpack_trees() is called without any of those options, changes in no-checkout entries will not get checked out on working directory. New files still appear on working directory though. That will be handled later by core.defaultsparse
CE_WD_REMOVE is introduced to remove entries from working directories, but still keep them in index
--- cache.h | 3 + unpack-trees.c | 131 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- unpack-trees.h | 6 +++ 3 files changed, 134 insertions(+), 6 deletions(-)
cache.h +3 -0
@@ -173,6 +173,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 */
unpack-trees.c +125 -6
197 lines not on this page · raw message
unpack-trees.h +6 -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 narrow_spec {
@@ -46,6 +48,9 @@ struct unpack_trees_options { prune_unmerged:1, has_unmerged:1, initial_checkout:1, + new_narrow_path:1, + add_narrow_path:2, + remove_narrow_path:2, gently:1;const char *prefix;int pos;
@@ -57,6 +62,7 @@ struct unpack_trees_options {int merge_size;struct cache_entry *df_conflict_entry; +struct narrow_spec *narrow_spec;void *unpack_data;struct index_state *dst_index;
Signature · 1 line
1.6.0.3.890.g95457
PATCH 5/8 clone: support sparse checkout with --sparse-checkout option
--- Documentation/git-clone.txt | 10 +++++++++- builtin-clone.c | 14 ++++++++++++++ t/t5703-clone-narrow.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletions(-) create mode 100755 t/t5703-clone-narrow.sh
Documentation/git-clone.txt +9 -1
@@ -12,7 +12,8 @@ SYNOPSIS 'git clone' [--template=<template_directory>] [-l] [-s] [--no-hardlinks] [-q] [-n] [--bare] [--mirror] [-o <name>] [-u <upload-pack>] [--reference <repository>] - [--depth <depth>] [--] <repository> [<directory>] + [--depth <depth>] [-S|--sparse-checkout=<sparse patterns>] [--] + <repository> [<directory>] DESCRIPTION -----------
@@ -99,6 +100,13 @@ then the cloned repository will become corrupt. -n:: No checkout of HEAD is performed after the clone is complete. +-S=<sparse patterns>:: +--sparse-checkout=<sparse patterns>:: + Make a sparse checkout instead of a full one. + This option will not work with either --no-checkout or --bare. + Please refer to linkgit:git-checkout[1] for more detail on + sparse checkout and sparse patterns. + --bare:: Make a 'bare' GIT repository. That is, instead of creating `<directory>` and placing the administrative
builtin-clone.c +14 -0
@@ -36,6 +36,7 @@ static const char * const builtin_clone_usage[] = {static int option_quiet, option_no_checkout, option_bare, option_mirror;static int option_local, option_no_hardlinks, option_shared;static char *option_template, *option_reference, *option_depth; +static char *option_narrow_path;static char *option_origin =NULL ;static char *option_upload_pack ="git-upload-pack" ;static int option_verbose;
@@ -45,6 +46,8 @@ static struct option builtin_clone_options[] = {OPT__VERBOSE (&option_verbose),OPT_BOOLEAN ('n' ,"no-checkout" , &option_no_checkout,"don't create a checkout" ), +OPT_STRING ('S' ,"sparse-checkout" , &option_narrow_path,"sparse patterns" , +"only checkout certain files based on patterns" ),OPT_BOOLEAN (0 ,"bare" , &option_bare,"create a bare repository" ),OPT_BOOLEAN (0 ,"naked" , &option_bare,"create a bare repository" ), OPT_BOOLEAN(0, "mirror", &option_mirror,
@@ -383,10 +386,15 @@ int cmd_clone(int argc, const char **argv, const char *prefix)if (option_origin)die ("--bare and --origin %s options are incompatible." , option_origin); +if (option_narrow_path) +die ("--bare and --sparse-checkout options are incompatible." ); option_no_checkout =1 ; use_separate_remote =0 ; } +if (option_no_checkout && option_narrow_path) +die ("--no-checkout and --sparse-checkout options are incompatible." ); +if (!option_origin) option_origin ="origin" ;
@@ -597,10 +605,16 @@ int cmd_clone(int argc, const char **argv, const char *prefix) opts.src_index = &the_index; opts.dst_index = &the_index; +if (option_narrow_path) { + opts.new_narrow_path =1 ; + opts.narrow_spec =parse_narrow_spec (option_narrow_path,NULL ); + } + tree =parse_tree_indirect (remote_head->old_sha1);parse_tree (tree);init_tree_desc (&t, tree->buffer, tree->size);unpack_trees (1 , &t, &opts); +free_narrow_spec (opts.narrow_spec);if (write_cache (fd, active_cache, active_nr) ||commit_locked_index (lock_file))
t/t5703-clone-narrow.sh new file +41 -0
41 lines not on this page · raw message
Signature · 1 line
1.6.0.3.890.g95457
PATCH 6/8 checkout: add new options to support sparse checkout
This patch adds main interface to manipulate sparse checkout. New options are added to support entering/updating/leaving sparse checkout:
--full: return to full checkout (default)
--sparse: set checkout area according to given spec --{include,exclude}-sparse: adjust current sparse checkout area
--- Documentation/git-checkout.txt | 55 ++++++++++++++++- builtin-checkout.c | 39 ++++++++++++ t/t2011-checkout-sparse.sh | 128 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 219 insertions(+), 3 deletions(-) create mode 100755 t/t2011-checkout-sparse.sh
Documentation/git-checkout.txt +52 -3
@@ -8,8 +8,10 @@ git-checkout - Checkout a branch or paths to the working tree SYNOPSIS -------- [verse] -'git checkout' [-q] [-f] [--track | --no-track] [-b <new_branch> [-l]] [-m] [<branch>] -'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] [--] <paths>... +'git checkout' [-q] [-f] [--track | --no-track] [-b <new_branch> [-l]] [-m] + [<sparse checkout options>] [<branch>] +'git checkout' [-f|--ours|--theirs|-m|--conflict=<style>] [<tree-ish>] + [<sparse checkout options>] [--] <paths>... DESCRIPTION -----------
@@ -34,6 +36,10 @@ used to specify a specific tree-ish (i.e. commit, tag or tree) to update the index for the given paths before updating the working tree. +<sparse checkout options> include --full, --sparse, --include-sparse +and --exclude-sparse. The last three require sparse patterns. Please refer +to "sparse checkout" section for more information about this mode. + The index may contain unmerged entries after a failed merge. By default, if you try to check out such an entry from the index, the checkout operation will fail and nothing will be checked out.
@@ -117,6 +123,35 @@ should result in deletion of the path). When checking out paths from the index, this option lets you recreate the conflicted merge in the specified paths. +--full:: + Quit sparse checkout mode. Return to full checkout. + This option cannot be used with either --sparse, + --include-sparse, --exclude-sparse or <paths>. + +-S=<sparse patterns>:: +--sparse=<sparse patterns>:: + Re-apply new sparse patterns on current working directory to + form new checkout area. All no-checkout bits will be wiped + out before applying the patterns. + This option cannot be used with --full, --include-sparse, + --exclude-sparse or <paths>. Multiple --sparse is not allowed. + +-I=<sparse patterns>:: +--include-sparse=<sparse patterns>:: + Checkout more areas specified by sparse patterns to current + checkout area. Already checked out entries are not affected. + This option cannot be used with --full, --sparse, + --exclude-sparse or <paths>. Multiple --include-sparse is not allowed. + +-E=<sparse patterns>:: +--exclude-sparse=<sparse patterns>:: + Narrow checkout area by removing files specified by sparse patterns + from current checkout area. This operation will fail if there + are unmerged or modified files in the removing areas. No-checkout + entries are not affected. + This option cannot be used with --full, --sparse, + --include-sparse or <paths>. Multiple --exclude-sparse is not allowed. + --conflict=<style>:: The same as --merge option above, but changes the way the conflicting hunks are presented, overriding the
@@ -186,7 +221,10 @@ Because sparse checkout uses a new index format, it will be incompatible with git prior to 1.6.0 regarding worktree operations. Operations that only need access to the repository itself, such as clone, push, or pull/fetch from another (normal) repository... should -not be affected by sparse checkout. +not be affected by sparse checkout. In order to make your working +directory work again with those versions, you can use +`git checkout --full` to return to normal mode (and compatible index +format). In sparse checkout mode, checkout status of every files in your working directory will be recorded in index. If a file is marked
@@ -263,6 +301,17 @@ Patterns have the following format: - Sparse patterns do not apply to .gitignore and .gitattributes files. They are always checked out. +When you apply new sparse patterns to your working directory using either +--sparse, --include-sparse or --exclude-sparse, it will update "checkout" status +in index accordingly. Moreover, if a file is marked "no-checkout" and +is present in working directory, it will be removed. If a file is +turned from "no-checkout" to "checkout", then it will be added again +to working directory. Unmerged entries will always be "checkout" regardless +the sparse patterns. Modified entries will refuse to become "no-checkout". + +You can form your checkout area in one go with --sparse option, +or do it incrementally with --include-sparse and --exclude-sparse. + EXAMPLES --------
builtin-checkout.c +39 -0
@@ -33,6 +33,12 @@ struct checkout_opts {const char *new_branch;int new_branch_log;enum branch_track track; + +const char *prefix; +char *new_path; +char *add_path; +char *remove_path; +int all_path; }; static int post_checkout_hook(struct commit *old, struct commit *new,
@@ -388,6 +394,7 @@ static int merge_working_tree(struct checkout_opts *opts, topts.dst_index = &the_index; topts.msgs.not_uptodate_file ="You have local changes to '%s'; cannot switch branches." ; + topts.msgs.sparse_not_uptodate_file ="You have local changes to '%s'; cannot update sparse checkout." ;refresh_cache (REFRESH_QUIET );
@@ -411,7 +418,25 @@ static int merge_working_tree(struct checkout_opts *opts, tree =parse_tree_indirect (new->commit->object.sha1);init_tree_desc (&trees[1 ], tree->buffer, tree->size); +if (opts->all_path) { +/* leave narrow_spec NULL */ + topts.new_narrow_path =1 ; + } +else if (opts->new_path) { + topts.narrow_spec =parse_narrow_spec (opts->new_path, opts->prefix); + topts.new_narrow_path =1 ; + } +else if (opts->add_path) { + topts.narrow_spec =parse_narrow_spec (opts->add_path, opts->prefix); + topts.add_narrow_path =1 ; + } +else if (opts->remove_path) { + topts.narrow_spec =parse_narrow_spec (opts->remove_path, opts->prefix); + topts.remove_narrow_path =1 ; + } + ret =unpack_trees (2 , trees, &topts); +free_narrow_spec (topts.narrow_spec);if (ret ==-1 ) {/* * Unpack couldn't do a trivial merge; either
@@ -598,6 +623,10 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)OPT_BOOLEAN ('m' ,"merge" , &opts.merge,"merge" ),OPT_STRING (0 ,"conflict" , &conflict_style,"style" ,"conflict style (merge or diff3)" ), +OPT_BOOLEAN (0 ,"full" , &opts.all_path,"quit sparse checkout" ), +OPT_STRING ('S' ,"sparse" , &opts.new_path,"sparse patterns" ,"set new sparse checkout" ), +OPT_STRING ('I' ,"include-sparse" , &opts.add_path,"sparse patterns" ,"widen checkout area" ), +OPT_STRING ('E' ,"exclude-sparse" , &opts.remove_path,"sparse patterns" ,"narrow checkout area" ), OPT_END(), };int has_dash_dash;
@@ -608,6 +637,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)git_config (git_checkout_config,NULL ); opts.track =BRANCH_TRACK_UNSPECIFIED ; + opts.prefix = prefix; argc =parse_options (argc, argv, options, checkout_usage,PARSE_OPT_KEEP_DASHDASH );
@@ -634,6 +664,12 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)git_xmerge_config ("merge.conflictstyle" , conflict_style,NULL ); } +if (((opts.all_path ?1 :0 ) + + (opts.new_path ?1 :0 ) + + (opts.add_path ?1 :0 ) + + (opts.remove_path ?1 :0 )) >1 ) +die ("git checkout: --full, --sparse, --include-sparse and --exclude-sparse are incompatible" ); +if (opts.force && opts.merge)die ("git checkout: -f and -m are incompatible" );
@@ -727,6 +763,9 @@ no_reference:if (1 < !!opts.writeout_stage + !!opts.force + !!opts.merge)die ("git checkout: --ours/--theirs, --force and --merge are incompatible when\nchecking out of the index." ); +if (opts.all_path || opts.new_path || opts.add_path || opts.remove_path) +die ("git checkout: updating paths is incompatible with setting sparse checkout" ); +return checkout_paths (source_tree, pathspec, &opts); }
t/t2011-checkout-sparse.sh new file +128 -0
128 lines not on this page · raw message
Signature · 1 line
1.6.0.3.890.g95457
PATCH 7/8 Introduce default sparse patterns (core.defaultsparse)
As noted in the previous commit message, new files will always get added into working directory by unpack_trees(). This can be annoying so we keep track of the sparse patterns people use to form their checkout area and apply the patterns on new files. Those files that get filtered out by this will be reported if verbose_update is TRUE.
--- Documentation/config.txt | 10 +++++++ Documentation/git-checkout.txt | 21 ++++++++++++++- Documentation/git-clone.txt | 1 + builtin-checkout.c | 54 ++++++++++++++++++++++++++++++++++++++++ builtin-clone.c | 2 + cache.h | 2 + config.c | 5 +++ environment.c | 1 + t/t2011-checkout-sparse.sh | 19 ++++++++++++++ t/t5703-clone-narrow.sh | 1 + unpack-trees.c | 52 ++++++++++++++++++++++++++++++++++++++ unpack-trees.h | 1 + 12 files changed, 167 insertions(+), 2 deletions(-)
Documentation/config.txt +10 -0
@@ -422,6 +422,16 @@ relatively high IO latencies. With this set to 'true', git will do the index comparison to the filesystem data in parallel, allowing overlapping IO's. +core.defaultsparse:: + The default sparse patterns that will be used to decide + whether a new file should be added into working + directory. If a new file matches the default sparse + patterns, then it will be checked out. Otherwise it will + be ignored and marked "no-checkout" in index. + Sparse update operations via "git clone" or "git checkout" will + automatically update this config. See linkgit:git-clone[1] and + linkgit:git-checkout[1] for more information. + alias.*:: Command aliases for the linkgit:git[1] command wrapper - e.g. after defining "alias.last = cat-file commit HEAD", the invocation
Documentation/git-checkout.txt +19 -2
@@ -125,6 +125,7 @@ the conflicted merge in the specified paths. --full:: Quit sparse checkout mode. Return to full checkout. + `core.defaultsparse` will be removed. This option cannot be used with either --sparse, --include-sparse, --exclude-sparse or <paths>.
@@ -133,6 +134,7 @@ the conflicted merge in the specified paths. Re-apply new sparse patterns on current working directory to form new checkout area. All no-checkout bits will be wiped out before applying the patterns. + `core.defaultsparse` will be set with the given patterns. This option cannot be used with --full, --include-sparse, --exclude-sparse or <paths>. Multiple --sparse is not allowed.
@@ -140,6 +142,11 @@ the conflicted merge in the specified paths. --include-sparse=<sparse patterns>:: Checkout more areas specified by sparse patterns to current checkout area. Already checked out entries are not affected. + `core.defaultsparse` will be appended with the given patterns. + Repetitive use of --include-sparse and --exclude-sparse may + leave cruft in `core.defaultsparse`, and may slow down + checkout operations. You may want to clean up + `core.defaultsparse` with --sparse. This option cannot be used with --full, --sparse, --exclude-sparse or <paths>. Multiple --include-sparse is not allowed.
@@ -149,6 +156,11 @@ the conflicted merge in the specified paths. from current checkout area. This operation will fail if there are unmerged or modified files in the removing areas. No-checkout entries are not affected. + `core.defaultsparse` will be appended with the negated version of the given patterns. + Repetitive use of --include-sparse and --exclude-sparse may + leave cruft in `core.defaultsparse`, and may slow down + checkout operations. You may want to clean up + `core.defaultsparse` with --sparse. This option cannot be used with --full, --sparse, --include-sparse or <paths>. Multiple --exclude-sparse is not allowed.
@@ -230,8 +242,11 @@ In sparse checkout mode, checkout status of every files in your working directory will be recorded in index. If a file is marked "no-checkout", it means that file is not needed to be present in working directory by user or any git command. When a new file is added -to index, it will be marked "checkout" unless sparse patterns are -applied. Unmerged files are always "checkout". When you checkout new +to index, it will be checked with default sparse pattern (see +`core.defaultsparse` in linkgit:git-config.txt[1]). If the file +matches the pattern, it will be marked "checkout" and added to +working directory. Otherwise it will be marked "no-checkout" in +index. Unmerged files are always "checkout". When you checkout new files using "git checkout <file>" they will be automatically marked "checkout". Other commands such as "git apply" can also checkout new files if they are needed. linkgit:git-update-index[1] can be used to
@@ -311,6 +326,8 @@ the sparse patterns. Modified entries will refuse to become "no-checkout". You can form your checkout area in one go with --sparse option, or do it incrementally with --include-sparse and --exclude-sparse. +Patterns used in those options will be automatically recorded in +`core.defaultsparse`. EXAMPLES --------
Documentation/git-clone.txt +1 -0
@@ -103,6 +103,7 @@ then the cloned repository will become corrupt. -S=<sparse patterns>:: --sparse-checkout=<sparse patterns>:: Make a sparse checkout instead of a full one. + `core.defaultsparse` will be set with the given sparse patterns. This option will not work with either --no-checkout or --bare. Please refer to linkgit:git-checkout[1] for more detail on sparse checkout and sparse patterns.
builtin-checkout.c +54 -0
60 lines not on this page · raw message
builtin-clone.c +2 -0
@@ -619,6 +619,8 @@ int cmd_clone(int argc, const char **argv, const char *prefix)if (write_cache (fd, active_cache, active_nr) ||commit_locked_index (lock_file))die ("unable to write new index file" ); + +git_config_set ("core.defaultsparse" , option_narrow_path); }strbuf_release (&reflog_msg);
cache.h +2 -0
@@ -175,6 +175,7 @@ struct cache_entry {/* Only remove in work directory, not index */ #define CE_WT_REMOVE (0x400000) +#define CE_NEW (0x800000)/* * Extended on-disk flags
@@ -522,6 +523,7 @@ extern size_t delta_base_cache_limit;extern int auto_crlf;extern int fsync_object_files;extern int core_preload_index; +extern const char *core_default_sparse;enum safe_crlf {SAFE_CRLF_FALSE =0 ,
config.c +5 -0
@@ -495,6 +495,11 @@ static int git_default_core_config(const char *var, const char *value)return 0 ; } +if (!strcmp (var,"core.defaultsparse" )) { + core_default_sparse =xstrdup (value); +return 0 ; + } +/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
environment.c +1 -0
@@ -30,6 +30,7 @@ int zlib_compression_level = Z_BEST_SPEED;int core_compression_level;int core_compression_seen;int fsync_object_files; +const char *core_default_sparse;size_t packed_git_window_size =DEFAULT_PACKED_GIT_WINDOW_SIZE ;size_t packed_git_limit =DEFAULT_PACKED_GIT_LIMIT ;size_t delta_base_cache_limit =16 *1024 *1024 ;
t/t2011-checkout-sparse.sh +19 -0
@@ -45,6 +45,7 @@ test_expect_success 'limit worktree to work1 and work2' ' test_expect_success 'exit sparse checkout' ' git checkout --full && + test -z "$(git config core.defaultsparse)" && test -f work1/one && test -f work2/two && test -f work3/three &&
@@ -125,4 +126,22 @@ test_expect_success 'removal outside checkout area' ' git checkout --sparse=work2/ HEAD^ ' +test_expect_success 'core.defaultsparse, new files get filtered' ' + git checkout --sparse=work2/ $WORK2 && + git config core.defaultsparse "./*:work2/" + git checkout $WORK3 && + test -f three && + ! test -f work3/three && + git config --unset core.defaultsparse +' + +test_expect_success 'save core.defaultsparse' ' + git checkout --sparse="./*:work2/" $WORK2 && + test "$(git config core.defaultsparse)" = "./*:work2/" && + cd work3 && git checkout --include-sparse=1 $WORK2 && cd .. && + test "$(git config core.defaultsparse)" = "./*:work2/:work3//1" && + git checkout --exclude-sparse=work3/ $WORK2 && + test "$(git config core.defaultsparse)" = "./*:work2/:work3//1:!work3/" +' + test_done
t/t5703-clone-narrow.sh +1 -0
@@ -34,6 +34,7 @@ test_expect_success 'clone with --sparse-checkout' ' rm -fr dst && git clone --sparse-checkout=work/ src dst && cd dst && + test "$(git config core.defaultsparse)" = "work/" && test -z "$(git ls-files --sparse | grep -v ^work/)" ) '
unpack-trees.c +52 -0
76 lines not on this page · raw message
unpack-trees.h +1 -0
@@ -75,6 +75,7 @@ extern int unpack_trees(unsigned n, struct tree_desc *t,struct narrow_spec *parse_narrow_spec (const char *spec,const char *prefix);void free_narrow_spec (struct narrow_spec *spec); +void narrow_spec_to_strbuf (struct narrow_pattern *p,struct strbuf *sb);int match_narrow_spec (struct narrow_spec *spec,const char *path);int threeway_merge (struct cache_entry **stages,struct unpack_trees_options *o);int twoway_merge (struct cache_entry **src,struct unpack_trees_options *o);
Signature · 1 line
1.6.0.3.890.g95457
PATCH 8/8 wt-status: show sparse checkout info
This will make "git status" show core.defaultsparse and list of orphaned files if present.
--- wt-status.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ wt-status.h | 1 + 2 files changed, 45 insertions(+), 0 deletions(-)
wt-status.c +44 -0
@@ -20,6 +20,7 @@ static char wt_status_colors[][COLOR_MAXLEN] = {"\033[31m" ,/* WT_STATUS_CHANGED: red */ "\033[31m" ,/* WT_STATUS_UNTRACKED: red */ "\033[31m" ,/* WT_STATUS_NOBRANCH: red */ + "\033[31m", /* WT_STATUS_ORPHANED: red */ };enum untracked_status_type show_untracked_files =SHOW_NORMAL_UNTRACKED_FILES ;
@@ -83,6 +84,16 @@ static void wt_status_print_dirty_header(struct wt_status *s,color_fprintf_ln (s->fp, c,"#" ); } +static void wt_status_print_orphaned_header (struct wt_status *s) +{ +const char *c =color (WT_STATUS_HEADER ); +color_fprintf_ln (s->fp, c,"# Orphaned files:" ); +color_fprintf_ln (s->fp, c,"# (these are tracked, but marked no-checkout and should not be present)" ); +color_fprintf_ln (s->fp, c,"# (use \"git update-index --checkout\" to remove no-checkout status)" ); +color_fprintf_ln (s->fp, c,"# (otherwise remove them to avoid confusion because git will ignore them)" ); +color_fprintf_ln (s->fp, c,"#" ); +} +static void wt_status_print_untracked_header (struct wt_status *s) {const char *c =color (WT_STATUS_HEADER );
@@ -211,6 +222,33 @@ static void wt_status_print_changed(struct wt_status *s)run_diff_files (&rev,0 ); } +static void wt_status_print_orphaned (struct wt_status *s) +{ +int i, show_header =0 ; +struct stat st; +struct strbuf buf; + +strbuf_init (&buf,0 ); +for (i =0 ; i < the_index.cache_nr; i++) { +struct cache_entry *ce = the_index.cache[i]; + +if (ce_checkout (ce) ||lstat (ce->name, &st)) +continue ; + +if (!show_header) { +wt_status_print_orphaned_header (s); + show_header =1 ; + } + +color_fprintf (s->fp,color (WT_STATUS_HEADER ),"#\t" ); +color_fprintf_ln (s->fp,color (WT_STATUS_ORPHANED ),"%s" , +quote_path (ce->name,-1 , &buf, s->prefix)); + } + +if (show_header) +color_fprintf_ln (s->fp,color (WT_STATUS_HEADER ),"#" ); +} +static void wt_status_print_submodule_summary (struct wt_status *s) {struct child_process sm_summary;
@@ -344,8 +382,14 @@ void wt_status_print(struct wt_status *s)color_fprintf_ln (s->fp,color (WT_STATUS_HEADER ),"#" ); } +if (core_default_sparse) { +color_fprintf_ln (s->fp,color (WT_STATUS_HEADER ),"# Sparse patterns: %s" , core_default_sparse); +color_fprintf_ln (s->fp,color (WT_STATUS_HEADER ),"#" ); + } +wt_status_print_updated (s);wt_status_print_changed (s); +wt_status_print_orphaned (s);if (wt_status_submodule_summary)wt_status_print_submodule_summary (s);if (show_untracked_files)
wt-status.h +1 -0
@@ -9,6 +9,7 @@ enum color_wt_status {WT_STATUS_CHANGED ,WT_STATUS_UNTRACKED ,WT_STATUS_NOBRANCH , + WT_STATUS_ORPHANED, }; enum untracked_status_type {
Signature · 1 line
1.6.0.3.890.g95457
Re: [PATCH 1/8] generate-cmdlist.sh: avoid selecting synopsis at wrong place
In reply to Nguyễn Thái Ngọc DuyHi,
Quoted 4 lines · Nguy�n Th�i Ng�c Duy
In "common" man pages there is luckily no "NAME" anywhere except at beginning of documents. If there is another "NAME", sed could mis-select it and lead to
common-cmds.hcorruption. So better nail it at beginning of line, which would reduce corruption chance.
I have no idea why you put this into the sparse checkout patch series.
As it is, the patch series is _already_ hard to review (as it is large not only in term of number of patches, but also individual patch size), _especially_ given the fact that there is no clear, precise and short description of why/how the sparse checkout is implemented.
For example, instead of using the BLURP area of the cover letter to put forth convincing arguments why this is needed, and why it is implemented in the best possible manner, you wasted two lines stating the obvious.
IMO that is almost like _asking_ people not to have a look at it.
Ciao,
Dscho
Re: [PATCH 1/8] generate-cmdlist.sh: avoid selecting synopsis at wrong place
Quoted 8 lines · Johannes Schindelin
Quoted 4 lines · Nguyễn Thái Ngọc Duy
In "common" man pages there is luckily no "NAME" anywhere except at beginning of documents. If there is another "NAME", sed could mis-select it and lead to
common-cmds.hcorruption. So better nail it at beginning of line, which would reduce corruption chance.I have no idea why you put this into the sparse checkout patch series.
That is because a documentation that triggers the misfortune this patch fixes is introduced in the series. I actually scratched head myself, though, and come to think of it, I should have complained that this patch should state that because it does not look like it has anything do with the main topic of the series.
Quoted 4 lines
As it is, the patch series is _already_ hard to review (as it is large not only in term of number of patches, but also individual patch size), _especially_ given the fact that there is no clear, precise and short description of why/how the sparse checkout is implemented.
Hmm, can you really tell the lack of such description without reading the series, I have to wonder...
Re: [PATCH 1/8] generate-cmdlist.sh: avoid selecting synopsis at wrong place
Hi,
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Johannes Schindelin
As it is, the patch series is _already_ hard to review (as it is large not only in term of number of patches, but also individual patch size), _especially_ given the fact that there is no clear, precise and short description of why/how the sparse checkout is implemented.
Hmm, can you really tell the lack of such description without reading the series, I have to wonder...
Okay, I thought it was obvious, but here is a template for the BLURP of the cover letter that would at least get me started:
-- snip --
A "sparse checkout" is an index/working directory pair where not all files/directories of the HEAD commit are actually checked out in the working directory. Instead, they are marked as "not being checked out" in the index.
The real meat of this series is patch *** M/N *** which teaches Git to understand the *** XYZ flag *** for index entries.
The following operations are affected by sparse checkout: *** X, Y, Z ***
These operations respect sparse checkouts by *** THIS, THIS AND THIS ***.
The first patch really should be independent, but patch *** M/N *** would fail without it.
-- snap --
And of course, the whole BLURP should not consist of 10-20 line paragraphs, but try to fit everything into 3-4 line paragraphs (I seem to remember that there was a mail on this list saying than more than 4 lines/paragraph are too much for the average attention span...).
Ciao,
Dscho
Re: [PATCH 1/8] generate-cmdlist.sh: avoid selecting synopsis at wrong place
In reply to Johannes SchindelinQuoted 5 lines · Johannes Schindelin
Hi,
On Sun, 30 Nov 2008, Nguyn Thái Ng÷c Duy wrote:
Quoted 7 lines
Quoted 4 lines
In "common" man pages there is luckily no "NAME" anywhere except at beginning of documents. If there is another "NAME", sed could mis-select it and lead to
common-cmds.hcorruption. So better nail it at beginning of line, which would reduce corruption chance.I have no idea why you put this into the sparse checkout patch series.
It's more an independent bug fix. I posted this once but it was not caught up. I intended to just put some comments in BLURB area to tell people to get this patch from mail archive. But that way seems inconvenient. Without this patch, you won't be able to compile the series because of common-cmds.h corruption.
Signature · 1 line
Duy