summaryrefslogtreecommitdiff
path: root/builtin/checkout-index.c
AgeCommit message (Collapse)Author
2015-01-14standardize usage info string formatAlex Henrie
This patch puts the usage info strings that were not already in docopt- like format into docopt-like format, which will be a litle easier for end users and a lot easier for translators. Changes include: - Placing angle brackets around fill-in-the-blank parameters - Putting dashes in multiword parameter names - Adding spaces to [-f|--foobar] to make [-f | --foobar] - Replacing <foobar>* with [<foobar>...] Signed-off-by: Alex Henrie <alexhenrie24@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-12Merge branch 'es/checkout-index-temp'Junio C Hamano
"git checkout-index --temp=$target $path" did not work correctly for paths outside the current subdirectory in the project. * es/checkout-index-temp: checkout-index: fix --temp relative path mangling t2004: demonstrate broken relative path printing t2004: standardize file naming in symlink test t2004: drop unnecessary write-tree/read-tree t2004: modernize style
2014-12-29checkout-index: fix --temp relative path manglingEric Sunshine
checkout-index --temp only properly prints relative paths which are descendants of the current directory. Paths in ancestor or sibling directories (or their children) are often printed in mangled form. For example: mkdir a bbb && >file && >bbb/file && git update-index --add file bbb/file && cd a && git checkout-index --temp ../file ../bbb/file prints: .merge_file_ooblek le .merge_file_igloo0 b/file rather than the correct: .merge_file_ooblek ../file .merge_file_igloo0 ../bbb/file Internally, given the above example, checkout-index prefixes each input argument with the name of the current directory ("a/", in this case), and then assumes that it can simply skip forward by strlen("a/") bytes to recover the original name. This works for files in the current directory or its descendants, but fails for files in ancestors or siblings (or their children) due to path normalization. For instance, given "../file", "a/" is prepended, giving "a/../file". Path normalization folds out "a/../", resulting in "file". Attempting to recover the original name by skipping strlen("a/") bytes gives the incorrect "le" rather than the desired "../file". Fix this by taking advantage of write_name_quoted_relative() to recover the original name properly, rather than assuming that it can be recovered by skipping strlen(prefix) bytes. As a bonus, this also fixes a bug in which checkout-index --temp accessed and printed memory beyond the end-of-string. For instance, within a subdirectory named "subdirectory", and given argument "../file", prefixing would give "subdirectory/../file", which would become "file" after normalization. checkout-index would then attempt to recover the original name by skipping strlen("subdirectory/") bytes of "file", which placed it well beyond end-of-string. Despite this error, it often appeared to give the correct result, but only due to an accident of implementation which left an apparently correct copy of the path in memory following the normalized value. In particular, handed "subdirectory/../file", in-place processing by normalize_path_copy_len() resulted in "file\0rectory/../file". When checkout-index skipped strlen("subdirectory/") bytes, it ended up back at "../file" and thus appeared to give the correct answer, despite being past end-of-string. Reported-by: Russ Cox <rsc@golang.org> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-10-01lockfile.h: extract new header file for the functions in lockfile.cMichael Haggerty
Move the interface declaration for the functions in lockfile.c from cache.h to a new file, lockfile.h. Add #includes where necessary (and remove some redundant includes of cache.h by files that already include builtin.h). Move the documentation of the lock_file state diagram from lockfile.c to the new header file. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-13entry.c: update cache_changed if refresh_cache is set in checkout_entry()Nguyễn Thái Ngọc Duy
Other fill_stat_cache_info() is on new entries, which should set CE_ENTRY_ADDED in cache_changed, so we're safe. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-06-13read-cache: new API write_locked_index instead of write_index/write_cacheNguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-10-30Merge branch 'nd/lift-path-max'Junio C Hamano
* nd/lift-path-max: checkout_entry(): clarify the use of topath[] parameter entry.c: convert checkout_entry to use strbuf
2013-10-24checkout_entry(): clarify the use of topath[] parameterJunio C Hamano
The said function has this signature: extern int checkout_entry(struct cache_entry *ce, const struct checkout *state, char *topath); At first glance, it might appear that the caller of checkout_entry() can specify to which path the contents are written out by the last parameter, and it is tempting to add "const" in front of its type. In reality, however, topath[] is to point at a buffer to store the temporary path generated by the callchain originating from this function, and the temporary path is always short, much shorter than the buffer prepared by its only caller in builtin/checkout-index.c. Document the code a bit to clarify so that future callers know how to use the function better. Noticed-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-07checkout-index: fix negations of even numbers of -nStefan Beller
The --no-create was parsed with OPT_BOOLEAN, which has a counting up logic implemented. Since b04ba2bb (parse-options: deprecate OPT_BOOLEAN, 2011-09-27) the OPT_BOOLEAN is deprecated and is only a define: /* Deprecated synonym */ #define OPTION_BOOLEAN OPTION_COUNTUP However the variable not_new, which can be counted up by giving --no-create multiple times, is used to set a bit in the struct checkout bitfield (defined in cache.h:969, declared at builtin/checkout-index.c:19): state.not_new = not_new; When assigning a value other than 0 or 1 to a bit, all leading digits but the last are ignored and only the last bit is used for setting the bit variable. Hence the following: # in git.git: $ git status # working directory clean rm COPYING $ git status # deleted: COPYING $ git checkout-index -a -n $ git status # deleted: COPYING # which is expected as we're telling git to not restore or create # files, however: $ git checkout-index -a -n -n $ git status # working directory clean, COPYING is restored again! # That's the bug, we're fixing here. By restraining the variable not_new to a value being definitely 0 or 1 by the macro OPT_BOOL the bug is fixed. Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-08-05Replace deprecated OPT_BOOLEAN by OPT_BOOLStefan Beller
This task emerged from b04ba2bb (parse-options: deprecate OPT_BOOLEAN, 2011-09-27). All occurrences of the respective variables have been reviewed and none of them relied on the counting up mechanism, but all of them were using the variable as a true boolean. This patch does not change semantics of any command intentionally. Signed-off-by: Stefan Beller <stefanbeller@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-08-22Use imperative form in help usage to describe an actionNguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-08-20i18n: checkout-index: mark parseopt strings for translationNguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-17checkout-index: remove obsolete commentNguyễn Thái Ngọc Duy
The first paragraph about flag order is no longer true and is mentioned in git-checkout-index.txt. The rest is also mentioned in git-checkout-index.txt. Remove it and keep uptodate document in one place. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-13Merge branch 'jn/git-cmd-h-bypass-setup'Junio C Hamano
* jn/git-cmd-h-bypass-setup: update-index -h: show usage even with corrupt index merge -h: show usage even with corrupt index ls-files -h: show usage even with corrupt index gc -h: show usage even with broken configuration commit/status -h: show usage even with broken configuration checkout-index -h: show usage even in an invalid repository branch -h: show usage even in an invalid repository Conflicts: builtin/merge.c
2010-11-15Describe various forms of "be quiet" using OPT__QUIETJonathan Nieder
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15add OPT__FORCERené Scharfe
Add OPT__FORCE as a helper macro in the same spirit as OPT__VERBOSE et.al. to simplify defining -f/--force options. Signed-off-by: Rene Scharfe <rene.scharfe@lstfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-15add description parameter to OPT__QUIETRené Scharfe
Allows better help text to be defined than "be quiet". Also make use of the macro in a place that already had a different description. No object code changes intended. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-10-22checkout-index -h: show usage even in an invalid repositoryNguyễn Thái Ngọc Duy
checkout-index loads the index before parsing options. Erroring out is counterproductive at that point if the operator is hunting for a command to recover useful data from the broken repository. [jn: new commit message, tests] Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-10-08Fix {update,checkout}-index usage stringsŠtěpán Němec
The `<file>' argument is optional in both cases (the man pages are already correct). Signed-off-by: Štěpán Němec <stepnem@gmail.com> Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-02-22Move 'builtin-*' into a 'builtin/' subdirectoryLinus Torvalds
This shrinks the top-level directory a bit, and makes it much more pleasant to use auto-completion on the thing. Instead of [torvalds@nehalem git]$ em buil<tab> Display all 180 possibilities? (y or n) [torvalds@nehalem git]$ em builtin-sh builtin-shortlog.c builtin-show-branch.c builtin-show-ref.c builtin-shortlog.o builtin-show-branch.o builtin-show-ref.o [torvalds@nehalem git]$ em builtin-shor<tab> builtin-shortlog.c builtin-shortlog.o [torvalds@nehalem git]$ em builtin-shortlog.c you get [torvalds@nehalem git]$ em buil<tab> [type] builtin/ builtin.h [torvalds@nehalem git]$ em builtin [auto-completes to] [torvalds@nehalem git]$ em builtin/sh<tab> [type] shortlog.c shortlog.o show-branch.c show-branch.o show-ref.c show-ref.o [torvalds@nehalem git]$ em builtin/sho [auto-completes to] [torvalds@nehalem git]$ em builtin/shor<tab> [type] shortlog.c shortlog.o [torvalds@nehalem git]$ em builtin/shortlog.c which doesn't seem all that different, but not having that annoying break in "Display all 180 possibilities?" is quite a relief. NOTE! If you do this in a clean tree (no object files etc), or using an editor that has auto-completion rules that ignores '*.o' files, you won't see that annoying 'Display all 180 possibilities?' message - it will just show the choices instead. I think bash has some cut-off around 100 choices or something. So the reason I see this is that I'm using an odd editory, and thus don't have the rules to cut down on auto-completion. But you can simulate that by using 'ls' instead, or something similar. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>