summaryrefslogtreecommitdiff
path: root/builtin
AgeCommit message (Collapse)AuthorFilesLines
2015-03-27Merge branch 'jk/tag-h-column-is-a-listing-option' into maintLibravatar Junio C Hamano1-2/+2
"git tag -h" used to show the "--column" and "--sort" options that are about listing in a wrong section. * jk/tag-h-column-is-a-listing-option: tag: fix some mis-organized options in "-h" listing
2015-03-23Merge branch 'rs/deflate-init-cleanup' into maintLibravatar Junio C Hamano2-3/+0
Code simplification. * rs/deflate-init-cleanup: zlib: initialize git_zstream in git_deflate_init{,_gzip,_raw}
2015-03-13Merge branch 'nd/grep-exclude-standard-help-fix' into maintLibravatar Junio C Hamano1-1/+1
Description given by "grep -h" for its --exclude-standard option was phrased poorly. * nd/grep-exclude-standard-help-fix: grep: correct help string for --exclude-standard
2015-03-13Merge branch 'jc/apply-beyond-symlink' into maintLibravatar Junio C Hamano1-1/+141
"git apply" was not very careful about reading from, removing, updating and creating paths outside the working tree (under --index/--cached) or the current directory (when used as a replacement for GNU patch). * jc/apply-beyond-symlink: apply: do not touch a file beyond a symbolic link apply: do not read from beyond a symbolic link apply: do not read from the filesystem under --index apply: reject input that touches outside the working area
2015-03-12tag: fix some mis-organized options in "-h" listingLibravatar Jeff King1-2/+2
Running "git tag -h" currently prints: [...] Tag creation options [...] --column[=<style>] show tag list in columns --sort <type> sort tags Tag listing options --contains <commit> print only tags that contain the commit --points-at <object> print only tags of the object The "--column" and "--sort" options should go under the "Tag listing" group. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-03-06Merge branch 'rs/simple-cleanups' into maintLibravatar Junio C Hamano1-4/+3
Code cleanups. * rs/simple-cleanups: sha1_name: use strlcpy() to copy strings pretty: use starts_with() to check for a prefix for-each-ref: use skip_prefix() to avoid duplicate string comparison connect: use strcmp() for string comparison
2015-03-05zlib: initialize git_zstream in git_deflate_init{,_gzip,_raw}Libravatar René Scharfe2-3/+0
Clear the git_zstream variable at the start of git_deflate_init() etc. so that callers don't have to do that. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-03-05Merge branch 'es/blame-commit-info-fix' into maintLibravatar Junio C Hamano1-3/+2
"git blame" died, trying to free an uninitialized piece of memory. * es/blame-commit-info-fix: builtin/blame: destroy initialized commit_info only
2015-03-05Merge branch 'ab/merge-file-prefix' into maintLibravatar Junio C Hamano1-1/+2
"git merge-file" did not work correctly in a subdirectory. * ab/merge-file-prefix: merge-file: correctly open files when in a subdir
2015-03-05Merge branch 'dp/remove-duplicated-header-inclusion' into maintLibravatar Junio C Hamano1-1/+0
Code clean-up. * dp/remove-duplicated-header-inclusion: do not include the same header twice
2015-02-27grep: correct help string for --exclude-standardLibravatar Nguyễn Thái Ngọc Duy1-1/+1
The current help string is about --no-exclude-standard. But "git grep -h" would show --exclude-standard instead. Flip the string. See 0a93fb8 (grep: teach --untracked and --exclude-standard options - 2011-09-27) for more info about these options. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-24Merge branch 'jc/apply-ws-fix-expands' into maintLibravatar Junio C Hamano1-3/+28
"git apply --whitespace=fix" used to under-allocate the memory when the fix resulted in a longer text than the original patch. * jc/apply-ws-fix-expands: apply: count the size of postimage correctly apply: make update_pre_post_images() sanity check the given postlen apply.c: typofix
2015-02-24Merge branch 'mg/commit-author-no-match-malformed-message' into maintLibravatar Junio C Hamano1-1/+1
The error message from "git commit", when a non-existing author name was given as value to the "--author=" parameter, has been reworded to avoid misunderstanding. * mg/commit-author-no-match-malformed-message: commit: reword --author error message
2015-02-24Merge branch 'dk/format-patch-ignore-diff-submodule' into maintLibravatar Junio C Hamano1-1/+1
Setting diff.submodule to 'log' made "git format-patch" produce broken patches. * dk/format-patch-ignore-diff-submodule: format-patch: ignore diff.submodule setting t4255: test am submodule with diff.submodule
2015-02-24Merge branch 'jk/blame-commit-label' into maintLibravatar Junio C Hamano3-24/+15
"git blame HEAD -- missing" failed to correctly say "HEAD" when it tried to say "No such path 'missing' in HEAD". * jk/blame-commit-label: blame.c: fix garbled error message use xstrdup_or_null to replace ternary conditionals builtin/commit.c: use xstrdup_or_null instead of envdup builtin/apply.c: use xstrdup_or_null instead of null_strdup git-compat-util: add xstrdup_or_null helper
2015-02-22for-each-ref: use skip_prefix() to avoid duplicate string comparisonLibravatar René Scharfe1-4/+3
Use skip_prefix() to get the part after "color:" (if present) and only compare it with "reset" instead of comparing the whole string again. This gets rid of the duplicate "color:" part of the string constant. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-13do not include the same header twiceLibravatar Дилян Палаузов1-1/+0
A few files include the same header file directly more than once. As all these headers protect themselves against repeated inclusion by the "#ifndef FOO_H / #define FOO_H / ... / #endif" idiom, leave only the first inclusion and remove the later inclusion as a no-op clean-up. Signed-off-by: Дилян Палаузов <git-dpa@aegee.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-11merge-file: correctly open files when in a subdirLibravatar Aleksander Boruch-Gruszecki1-1/+2
run_setup_gently() is called before merge-file. This may result in changing current working directory, which wasn't taken into account when opening a file for writing. Fix by prepending the passed prefix. Previous var is left so that error messages keep referring to the file from the user's working directory perspective. Signed-off-by: Aleksander Boruch-Gruszecki <aleksander.boruchgruszecki@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-10apply: do not touch a file beyond a symbolic linkLibravatar Junio C Hamano1-0/+112
Because Git tracks symbolic links as symbolic links, a path that has a symbolic link in its leading part (e.g. path/to/dir/file, where path/to/dir is a symbolic link to somewhere else, be it inside or outside the working tree) can never appear in a patch that validly applies, unless the same patch first removes the symbolic link to allow a directory to be created there. Detect and reject such a patch. Things to note: - Unfortunately, we cannot reuse the has_symlink_leading_path() from dir.c, as that is only about the working tree, but "git apply" can be told to apply the patch only to the index or to both the index and to the working tree. - We cannot directly use has_symlink_leading_path() even when we are applying only to the working tree, as an early patch of a valid input may remove a symbolic link path/to/dir and then a later patch of the input may create a path path/to/dir/file, but "git apply" first checks the input without touching either the index or the working tree. The leading symbolic link check must be done on the interim result we compute in-core (i.e. after the first patch, there is no path/to/dir symbolic link and it is perfectly valid to create path/to/dir/file). Similarly, when an input creates a symbolic link path/to/dir and then creates a file path/to/dir/file, we need to flag it as an error without actually creating path/to/dir symbolic link in the filesystem. Instead, for any patch in the input that leaves a path (i.e. a non deletion) in the result, we check all leading paths against the resulting tree that the patch would create by inspecting all the patches in the input and then the target of patch application (either the index or the working tree). This way, we catch a mischief or a mistake to add a symbolic link path/to/dir and a file path/to/dir/file at the same time, while allowing a valid patch that removes a symbolic link path/to/dir and then adds a file path/to/dir/file. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-10apply: do not read from beyond a symbolic linkLibravatar Junio C Hamano1-0/+2
We should reject a patch, whether it renames/copies dir/file to elsewhere with or without modificiation, or updates dir/file in place, if "dir/" part is actually a symbolic link to elsewhere, by making sure that the code to read the preimage does not read from a path that is beyond a symbolic link. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-10apply: do not read from the filesystem under --indexLibravatar Junio C Hamano1-1/+1
We currently read the preimage to apply a patch from the index only when the --cached option is given. Do so also when the command is running under the --index option. With --index, the index entry and the working tree file for a path that is involved in a patch must be identical, so this should not affect the result, but by reading from the index, we will get the protection to avoid reading an unintended path beyond a symbolic link automatically. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-10apply: reject input that touches outside the working areaLibravatar Junio C Hamano1-0/+26
By default, a patch that affects outside the working area (either a Git controlled working tree, or the current working directory when "git apply" is used as a replacement of GNU patch) is rejected as a mistake (or a mischief). Git itself does not create such a patch, unless the user bends over backwards and specifies a non-standard prefix to "git diff" and friends. When `git apply` is used as a "better GNU patch", the user can pass the `--unsafe-paths` option to override this safety check. This option has no effect when `--index` or `--cached` is in use. The new test was stolen from Jeff King with slight enhancements. Note that a few new tests for touching outside the working area by following a symbolic link are still expected to fail at this step, but will be fixed in later steps. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-10builtin/blame: destroy initialized commit_info onlyLibravatar Eric Sunshine1-3/+2
Since ea02ffa3 (mailmap: simplify map_user() interface, 2013-01-05), find_alignment() has been invoking commit_info_destroy() on an uninitialized auto 'struct commit_info' (when METAINFO_SHOWN is not set). commit_info_destroy() calls strbuf_release() for each 'commit_info' strbuf member, which randomly invokes free() on whatever random stack value happens to reside in strbuf.buf, thus leading to periodic crashes. Reported-by: Dilyan Palauzov <dilyan.palauzov@aegee.org> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-26commit: reword --author error messageLibravatar Michael J Gruber1-1/+1
If an --author argument is specified but does not contain a '>' then git tries to find the argument within the existing authors; and gives the error message "No existing author found with '%s'" if there is no match. This is confusing for users who try to specify a valid complete author name. Rename the error message to make it clearer that the failure has two reasons in this case. (This codepath is touched only when we know already that the argument cannot be a completely wellformed author ident.) Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-22Merge branch 'ak/cat-file-clean-up'Libravatar Junio C Hamano1-2/+0
* ak/cat-file-clean-up: cat-file: use "type" and "size" from outer scope
2015-01-22apply: count the size of postimage correctlyLibravatar Junio C Hamano1-2/+21
Under --whitespace=fix option, match_fragment() function examines the preimage (the common context and the removed lines in the patch) and the file being patched and checks if they match after correcting all whitespace errors. When they are found to match, the common context lines in the preimage is replaced with the fixed copy, because these lines will then be copied to the corresponding place in the postimage by a later call to update_pre_post_images(). Lines that are added in the postimage, under --whitespace=fix, have their whitespace errors already fixed when apply_one_fragment() prepares the preimage and the postimage, so in the end, application of the patch can be done by replacing the block of text in the file being patched that matched the preimage with what is in the postimage that was updated by update_pre_post_images(). In the earlier days, fixing whitespace errors always resulted in reduction of size, either collapsing runs of spaces in the indent to a tab or removing the trailing whitespaces. These days, however, some whitespace error fix results in extending the size. 250b3c6c (apply --whitespace=fix: avoid running over the postimage buffer, 2013-03-22) tried to compute the final postimage size but its math was flawed. It counted the size of the block of text in the original being patched after fixing the whitespace errors on its lines that correspond to the preimage. That number does not have much to do with how big the final postimage would be. Instead count (1) the added lines in the postimage, whose size is the same as in the final patch result because their whitespace errors have already been corrected, and (2) the fixed size of the lines that are common. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-22apply: make update_pre_post_images() sanity check the given postlenLibravatar Junio C Hamano1-0/+6
"git apply --whitespace=fix" used to be able to assume that fixing errors will always reduce the size by e.g. stripping whitespaces at the end of lines or collapsing runs of spaces into tabs at the beginning of lines. An update to accomodate fixes that lengthens the result by e.g. expanding leading tabs into spaces were made long time ago but the logic miscounted the necessary space after such whitespace fixes, leading to either under-allocation or over-usage of already allocated space. Illustrate this with a runtime sanity-check to protect us from future breakage. The test was stolen from Kyle McKay who helped to identify the problem. Helped-by: "Kyle J. McKay" <mackyle@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-22apply.c: typofixLibravatar Junio C Hamano1-1/+1
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-20Merge branch 'ak/show-branch-usage-string'Libravatar Junio C Hamano1-3/+3
* ak/show-branch-usage-string: show-branch: fix indentation of usage string
2015-01-20show-branch: fix indentation of usage stringLibravatar Ralf Thielow1-3/+3
Noticed-by: Jean-Noël Avila <jn.avila@free.fr> Signed-off-by: Ralf Thielow <ralf.thielow@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-14Merge branch 'rc/for-each-ref-tracking'Libravatar Junio C Hamano1-2/+9
* rc/for-each-ref-tracking: for-each-ref: always check stat_tracking_info()'s return value
2015-01-14Merge branch 'ak/fewer-includes'Libravatar Junio C Hamano1-4/+0
* ak/fewer-includes: cat-file: remove unused includes git.c: remove unnecessary #includes
2015-01-14Merge branch 'ak/show-branch-usage-string'Libravatar Junio C Hamano1-1/+4
* ak/show-branch-usage-string: show-branch: line-wrap show-branch usage
2015-01-14Merge branch 'km/log-usage-string-i18n'Libravatar Junio C Hamano1-2/+2
* km/log-usage-string-i18n: log.c: fix translation markings
2015-01-14Merge branch 'js/remote-add-with-insteadof'Libravatar Junio C Hamano1-1/+3
"git remote add $name $URL" is now allowed when "url.$URL.insteadOf" is already defined. * js/remote-add-with-insteadof: Add a regression test for 'git remote add <existing> <same-url>' git remote: allow adding remotes agreeing with url.<...>.insteadOf
2015-01-13cat-file: use "type" and "size" from outer scopeLibravatar Alexander Kuleshov1-2/+0
In cat_one_file(), "type" and "size" variables are defined in the function scope, and then two variables of the same name are defined in a block in one of the if/else statement, hiding the definitions in the outer scope. Because the values of the outer variables before the control enters this scope, however, do not have to be preserved, we can remove useless definitions of variables from the inner scope safely without breaking anything. Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-13blame.c: fix garbled error messageLibravatar Lukas Fleischer1-5/+7
The helper functions prepare_final() and prepare_initial() return a pointer to a string that is a member of an object in the revs->pending array. This array is later rebuilt when running prepare_revision_walk() which potentially transforms the pointer target into a bogus string. Fix this by maintaining a copy of the original string. Signed-off-by: Lukas Fleischer <git@cryptocrack.de> Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-13builtin/commit.c: use xstrdup_or_null instead of envdupLibravatar Jeff King1-9/+3
The only reason for envdup to be its own function is that we have to save the result in a temporary string. With xstrdup_or_null, we can feed the result of getenv() directly. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-13builtin/apply.c: use xstrdup_or_null instead of null_strdupLibravatar Jeff King1-10/+5
This file had its own identical helper that predates xstrdup_or_null. Let's use the global one to avoid repetition. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-12for-each-ref: always check stat_tracking_info()'s return valueLibravatar Raphael Kubo da Costa1-2/+9
The code handling %(upstream:track) and %(upstream:trackshort) assumed that it always had a valid branch that had been sanitized earlier in populate_value(), and thus did not check the return value of the call to stat_tracking_info(). While there is indeed some sanitization code that basically corresponds to stat_tracking_info() returning 0 (no base branch set), the function can also return -1 when the base branch did exist but has since then been deleted. In this case, num_ours and num_theirs had undefined values and a call to `git for-each-ref --format="%(upstream:track)"` could print spurious values such as [behind -111794512] [ahead 38881640, behind 5103867] even for repositories with one single commit. Verify stat_tracking_info()'s return value and do not print anything if it returns -1. This behavior also matches the documentation ("has no effect if the ref does not have tracking information associated with it"). Helped-by: Eric Sunshine <sunshine@sunshineco.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Raphael Kubo da Costa <raphael.kubo.da.costa@intel.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-12Merge branch 'mg/add-ignore-errors' into maintLibravatar Junio C Hamano1-1/+1
* mg/add-ignore-errors: add: ignore only ignored files
2015-01-12Merge branch 'bc/fetch-thin-less-aggressive-in-normal-repository'Libravatar Junio C Hamano1-1/+6
Earlier we made "rev-list --object-edge" more aggressively list the objects at the edge commits, in order to reduce number of objects fetched into a shallow repository, but the change affected cases other than "fetching into a shallow repository" and made it unusably slow (e.g. fetching into a normal repository should not have to suffer the overhead from extra processing). Limit it to a more specific case by introducing --objects-edge-aggressive, a new option to rev-list. * bc/fetch-thin-less-aggressive-in-normal-repository: pack-objects: use --objects-edge-aggressive for shallow repos rev-list: add an option to mark fewer edges as uninteresting Documentation: add missing article in rev-list-options.txt
2015-01-12Merge branch 'rs/simplify-parsing-commit-tree-S'Libravatar Junio C Hamano1-3/+1
* rs/simplify-parsing-commit-tree-S: commit-tree: simplify parsing of option -S using skip_prefix()
2015-01-12Merge branch 'rs/plug-strbuf-leak-in-merge'Libravatar Junio C Hamano1-0/+1
* rs/plug-strbuf-leak-in-merge: merge: release strbuf after use in suggest_conflicts()
2015-01-12Merge branch 'es/checkout-index-temp'Libravatar Junio C Hamano1-8/+8
"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
2015-01-09cat-file: remove unused includesLibravatar Alexander Kuleshov1-4/+0
- "exec_cmd.h" became unnecessary at b931aa5a (Call builtin ls-tree in git-cat-file -p, 2006-05-26), when it changed an earlier code that delegated tree display to "ls-tree" via the run_command() API (hence needing "exec_cmd.h") to call cmd_ls_tree() directly. We should have removed the include in the same commit, but we forgot to do so. - "diff.h" was added at e5fba602 (textconv: support for cat_file, 2010-06-15), together with "userdiff.h", but "userdiff.h" can be included without including "diff.h"; the header was unnecessary from the beginning. - "tag.h" and "tree.h" were necessary since 8e440259 (Use blob_, commit_, tag_, and tree_type throughout., 2006-04-02) to check the type of object by comparing typename with tree_type and tag_type (pointers to extern strings). 21666f1a (convert object type handling from a string to a number, 2007-02-26) made these <type>_type strings unnecessary, and it could have switched to include "object.h", which is necessary to use typename(), but it forgot to do so. Because "tag.h" and "tree.h" include "object.h", it did not need to explicitly include "object.h" in order to start using typename() itself. We do not even have to include "object.h" after removing these two #includes, because "builtin.h" includes "commit.h" which in turn includes "object.h" these days. This happened at 7b9c0a69 (git-commit-tree: make it usable from other builtins, 2008-07-01). Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-08show-branch: line-wrap show-branch usageLibravatar Alexander Kuleshov1-1/+4
Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-07format-patch: ignore diff.submodule settingLibravatar Doug Kelly1-1/+1
diff.submodule when set to log produces output which git-am cannot handle. Ignore this setting when generating patch output. Signed-off-by: Doug Kelly <dougk.ff7@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-01-07Merge branch 'jc/merge-bases'Libravatar Junio C Hamano3-5/+5
The get_merge_bases*() API was easy to misuse by careless copy&paste coders, leaving object flags tainted in the commits that needed to be traversed. * jc/merge-bases: get_merge_bases(): always clean-up object flags bisect: clean flags after checking merge bases
2015-01-07Merge branch 'jc/clone-borrow'Libravatar Junio C Hamano1-0/+20
Allow "git clone --reference" to be used more safely. * jc/clone-borrow: clone: --dissociate option to mark that reference is only temporary