summaryrefslogtreecommitdiff
path: root/notes.c
AgeCommit message (Collapse)Author
2016-04-25struct name_entry: use struct object_id instead of unsigned char sha1[20]brian m. carlson
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-02-26Merge branch 'jk/tighten-alloc'Junio C Hamano
Update various codepaths to avoid manually-counted malloc(). * jk/tighten-alloc: (22 commits) ewah: convert to REALLOC_ARRAY, etc convert ewah/bitmap code to use xmalloc diff_populate_gitlink: use a strbuf transport_anonymize_url: use xstrfmt git-compat-util: drop mempcpy compat code sequencer: simplify memory allocation of get_message test-path-utils: fix normalize_path_copy output buffer size fetch-pack: simplify add_sought_entry fast-import: simplify allocation in start_packfile write_untracked_extension: use FLEX_ALLOC helper prepare_{git,shell}_cmd: use argv_array use st_add and st_mult for allocation size computation convert trivial cases to FLEX_ARRAY macros use xmallocz to avoid size arithmetic convert trivial cases to ALLOC_ARRAY convert manual allocations to argv_array argv-array: add detach function add helpers for allocating flex-array structs harden REALLOC_ARRAY and xcalloc against size_t overflow tree-diff: catch integer overflow in combine_diff_path allocation ...
2016-02-22convert trivial cases to ALLOC_ARRAYJeff King
Each of these cases can be converted to use ALLOC_ARRAY or REALLOC_ARRAY, which has two advantages: 1. It automatically checks the array-size multiplication for overflow. 2. It always uses sizeof(*array) for the element-size, so that it can never go out of sync with the declared type of the array. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-02-03Merge branch 'jk/notes-merge-from-anywhere'Junio C Hamano
"git notes merge" used to limit the source of the merged notes tree to somewhere under refs/notes/ hierarchy, which was too limiting when inventing a workflow to exchange notes with remote repositories using remote-tracking notes trees (located in e.g. refs/remote-notes/ or somesuch). * jk/notes-merge-from-anywhere: notes: allow merging from arbitrary references
2016-01-17notes: allow merging from arbitrary referencesJacob Keller
Create a new expansion function, expand_loose_notes_ref which will first check whether the ref can be found using get_sha1. If it can't be found then it will fallback to using expand_notes_ref. The content of the strbuf will not be changed if the notes ref can be located using get_sha1. Otherwise, it may be updated as done by expand_notes_ref. Since we now support merging from non-notes refs, remove the test case associated with that behavior. Add a test case for merging from a non-notes ref. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Reviewed-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-01-12notes: allow treeish expressions as notes refMike Hommey
init_notes() is the main point of entry to the notes API. It ensures that the input can be used as ref, because it needs a ref to update to store notes tree after modifying it. There however are many use cases where notes tree is only read, e.g. "git log --notes=...". Any notes-shaped treeish could be used for such purpose, but it is not allowed due to existing restriction. Allow treeish expressions to be used in the case the notes tree is going to be used without write "permissions". Add a flag to distinguish whether the notes tree is intended to be used read-only, or will be updated. With this change, operations that use notes read-only can be fed any notes-shaped tree-ish can be used, e.g. git log --notes=notes@{1}. Signed-off-by: Mike Hommey <mh@glandium.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-10-05notes: document length of fanout path with a constantJeff King
We know that a fanned-out sha1 in a notes tree cannot be more than "aa/bb/cc/...", and we have an assert() to confirm that. But let's factor out that length into a constant so we can be sure it is used consistently. And even though we assert() earlier, let's replace a strcpy with xsnprintf, so it is clear to a reader that all cases are covered. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-09-04Sync with 2.4.9Junio C Hamano
2015-09-04Sync with 2.2.3Junio C Hamano
2015-09-04notes: use a strbuf in add_non_noteJeff King
When we are loading a notes tree into our internal hash table, we also collect any files that are clearly non-notes. We format the name of the file into a PATH_MAX buffer, but unlike true notes (which cannot be larger than a fanned-out sha1 hash), these tree entries can be arbitrarily long, overflowing our buffer. We can fix this by switching to a strbuf. It doesn't even cost us an extra allocation, as we can simply hand ownership of the buffer over to the non-note struct. This is of moderate security interest, as you might fetch notes trees from an untrusted remote. However, we do not do so by default, so you would have to manually fetch into the notes namespace. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-25string_list_add_one_ref(): rewrite to take an object_id argumentMichael Haggerty
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-05-25each_ref_fn: change to take an object_id parameterMichael Haggerty
Change typedef each_ref_fn to take a "const struct object_id *oid" parameter instead of "const unsigned char *sha1". To aid this transition, implement an adapter that can be used to wrap old-style functions matching the old typedef, which is now called "each_ref_sha1_fn"), and make such functions callable via the new interface. This requires the old function and its cb_data to be wrapped in a "struct each_ref_fn_sha1_adapter", and that object to be used as the cb_data for an adapter function, each_ref_fn_adapter(). This is an enormous diff, but most of it consists of simple, mechanical changes to the sites that call any of the "for_each_ref" family of functions. Subsequent to this change, the call sites can be rewritten one by one to use the new interface. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-02-25Merge branch 'jk/blame-commit-label' into maintJunio C Hamano
"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-11Merge branch 'jk/blame-commit-label'Junio C Hamano
"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-01-13use xstrdup_or_null to replace ternary conditionalsJeff King
This replaces "x ? xstrdup(x) : NULL" with xstrdup_or_null(x). The change is fairly mechanical, with the exception of resolve_refdup, which can eliminate a temporary variable. There are still a few hits grepping for "?.*xstrdup", but these are of slightly different forms and cannot be converted (e.g., "x ? xstrdup(x->foo) : NULL"). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-12-22Merge branch 'mh/simplify-repack-without-refs'Junio C Hamano
"git remote update --prune" to drop many refs has been optimized. * mh/simplify-repack-without-refs: sort_string_list(): rename to string_list_sort() prune_remote(): iterate using for_each_string_list_item() prune_remote(): rename local variable repack_without_refs(): make the refnames argument a string_list prune_remote(): sort delete_refs_list references en masse prune_remote(): initialize both delete_refs lists in a single loop prune_remote(): exit early if there are no stale references
2014-11-25sort_string_list(): rename to string_list_sort()Michael Haggerty
The new name is more consistent with the names of other string_list-related functions. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-12notes: empty notes should be shown by 'git log'Johan Herland
If the user has gone through the trouble of explicitly adding an empty note, then "git log" should not silently skip it (as if it didn't exist). Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-05-27notes.c: rearrange xcalloc argumentsBrian Gesiak
xcalloc() takes two arguments: the number of elements and their size. notes.c includes several calls to xcalloc() that pass the arguments in reverse order. Rearrange them so they are in the correct order. Signed-off-by: Brian Gesiak <modocache@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-12-05replace {pre,suf}fixcmp() with {starts,ends}_with()Christian Couder
Leaving only the function definitions and declarations so that any new topic in flight can still make use of the old functions, replace existing uses of the prefixcmp() and suffixcmp() with new API functions. The change can be recreated by mechanically applying this: $ git grep -l -e prefixcmp -e suffixcmp -- \*.c | grep -v strbuf\\.c | xargs perl -pi -e ' s|!prefixcmp\(|starts_with\(|g; s|prefixcmp\(|!starts_with\(|g; s|!suffixcmp\(|ends_with\(|g; s|suffixcmp\(|!ends_with\(|g; ' on the result of preparatory changes in this series. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-02string_list_add_refs_by_glob(): add a comment about memory managementMichael Haggerty
Since string_list_add_one_ref() adds refname to the string list, but the lifetime of refname is limited, it is important that the string_list passed to string_list_add_one_ref() has strdup_strings set. Document this fact. All current callers do the right thing. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2013-06-02string_list_add_one_ref(): rename first parameter to "refname"Michael Haggerty
This is the usual convention. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-11-15Merge branch 'jc/prettier-pretty-note'Junio C Hamano
Emit the notes attached to the commit in "format-patch --notes" output after three-dashes. * jc/prettier-pretty-note: format-patch: add a blank line between notes and diffstat Doc User-Manual: Patch cover letter, three dashes, and --notes Doc format-patch: clarify --notes use case Doc notes: Include the format-patch --notes option Doc SubmittingPatches: Mention --notes option after "cover letter" Documentation: decribe format-patch --notes format-patch --notes: show notes after three-dashes format-patch: append --signature after notes pretty_print_commit(): do not append notes message pretty: prepare notes message at a centralized place format_note(): simplify API pretty: remove reencode_commit_message()
2012-11-15Merge branch 'mh/notes-string-list'Junio C Hamano
Improve the asymptotic performance of the cat_sort_uniq notes merge strategy. * mh/notes-string-list: string_list_add_refs_from_colon_sep(): use string_list_split() notes: fix handling of colon-separated values combine_notes_cat_sort_uniq(): sort and dedup lines all at once Initialize sort_uniq_list using named constant string_list: add a function string_list_remove_empty_items()
2012-11-15Merge branch 'jc/same-encoding'Junio C Hamano
Various codepaths checked if two encoding names are the same using ad-hoc code and some of them ended up asking iconv() to convert between "utf8" and "UTF-8". The former is not a valid way to spell the encoding name, but often people use it by mistake, and we equated them in some but not all codepaths. Introduce a new helper function to make these codepaths consistent. * jc/same-encoding: reencode_string(): introduce and use same_encoding() Conflicts: builtin/mailinfo.c
2012-11-08string_list_add_refs_from_colon_sep(): use string_list_split()Michael Haggerty
It makes for simpler code than strbuf_split(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Acked-by: Johan Herland <johan@herland.net> Signed-off-by: Jeff King <peff@peff.net>
2012-11-08notes: fix handling of colon-separated valuesMichael Haggerty
The substrings output by strbuf_split() include the ':' delimiters. When processing GIT_NOTES_DISPLAY_REF and GIT_NOTES_REWRITE_REF, strip off the delimiter character *before* checking whether the substring is empty rather than after, so that empty strings within the list are also skipped. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Acked-by: Johan Herland <johan@herland.net> Signed-off-by: Jeff King <peff@peff.net>
2012-11-08combine_notes_cat_sort_uniq(): sort and dedup lines all at onceMichael Haggerty
Instead of reading lines one by one and insertion-sorting them into a string_list, read all of the lines, sort them, then remove duplicates. Aside from being less code, this reduces the complexity from O(N^2) to O(N lg N) in the total number of lines. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Acked-by: Johan Herland <johan@herland.net> Signed-off-by: Jeff King <peff@peff.net>
2012-11-08Initialize sort_uniq_list using named constantMichael Haggerty
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Acked-by: Johan Herland <johan@herland.net> Signed-off-by: Jeff King <peff@peff.net>
2012-11-04reencode_string(): introduce and use same_encoding()Junio C Hamano
Callers of reencode_string() that re-encodes a string from one encoding to another all used ad-hoc way to bypass the case where the input and the output encodings are the same. Some did strcmp(), some did strcasecmp(), yet some others when converting to UTF-8 used is_encoding_utf8(). Introduce same_encoding() helper function to make these callers use the same logic. Notably, is_encoding_utf8() has a work-around for common misconfiguration to use "utf8" to name UTF-8 encoding, which does not match "UTF-8" hence strcasecmp() would not consider the same. Make use of it in this helper function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-10-18format_note(): simplify APIJunio C Hamano
We either stuff the notes message without modification for %N userformat, or format it for human consumption. Using two bits is an overkill that does not benefit anybody. Signed-off-by: Junio C Hamano <gitster@pobox.com>
2012-09-16notes.c: mark a private file-scope symbol as staticJunio C Hamano
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-08-22Do not use C++-style commentsMichael Haggerty
Detected by "gcc -std=iso9899:1990 ...". This patch applies against "maint". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-29notes: refactor display notes default handlingJeff King
This is in preparation for more notes-related revision command-line options. The "suppress_default_notes" option is renamed to "use_default_notes", and is now a tri-state with values less than one indicating "not set". If the value is "not set", then we show default refs if and only if no other refs were given. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-29notes: refactor display notes extra refs fieldJeff King
There's no need to use an extra pointer, which just ends up leaking memory. The fact that the list is empty tells us the same thing. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2011-03-29notes: make expand_notes_ref globally accessibleJeff King
This function is useful for other commands besides "git notes" which want to let users refer to notes by their shorthand name. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-12-08Merge branch 'jh/notes-merge'Junio C Hamano
* jh/notes-merge: (23 commits) Provide 'git merge --abort' as a synonym to 'git reset --merge' cmd_merge(): Parse options before checking MERGE_HEAD Provide 'git notes get-ref' to easily retrieve current notes ref git notes merge: Add testcases for merging notes trees at different fanouts git notes merge: Add another auto-resolving strategy: "cat_sort_uniq" git notes merge: --commit should fail if underlying notes ref has moved git notes merge: List conflicting notes in notes merge commit message git notes merge: Manual conflict resolution, part 2/2 git notes merge: Manual conflict resolution, part 1/2 Documentation: Preliminary docs on 'git notes merge' git notes merge: Add automatic conflict resolvers (ours, theirs, union) git notes merge: Handle real, non-conflicting notes merges builtin/notes.c: Refactor creation of notes commits. git notes merge: Initial implementation handling trivial merges only builtin/notes.c: Split notes ref DWIMmery into a separate function notes.c: Use two newlines (instead of one) when concatenating notes (trivial) t3303: Indent with tabs instead of spaces for consistency notes.h/c: Propagate combine_notes_fn return value to add_note() and beyond notes.h/c: Allow combine_notes functions to remove notes notes.c: Reorder functions in preparation for next commit ... Conflicts: builtin.h
2010-11-17git notes merge: Add another auto-resolving strategy: "cat_sort_uniq"Johan Herland
This new strategy is similar to "concatenate", but in addition to concatenating the two note candidates, this strategy sorts the resulting lines, and removes duplicate lines from the result. This is equivalent to applying the "cat | sort | uniq" shell pipeline to the two note candidates. This strategy is useful if the notes follow a line-based format where one wants to avoid duplicate lines in the merge result. Note that if either of the note candidates contain duplicate lines _prior_ to the merge, these will also be removed by this merge strategy. The patch also contains tests and documentation for the new strategy. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-17notes.c: Use two newlines (instead of one) when concatenating notesJohan Herland
When using combine_notes_concatenate() to concatenate notes, it currently ensures exactly one newline character between the given notes. However, when using builtin/notes.c:create_note() to concatenate notes (e.g. by 'git notes append'), it adds a newline character to the trailing newline of the preceding notes object, thus resulting in _two_ newlines (aka. a blank line) separating contents of the two notes. This patch brings combine_notes_concatenate() into consistency with builtin/notes.c:create_note(), by ensuring exactly _two_ newline characters between concatenated notes. The patch also changes a few notes-related selftests accordingly. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-17notes.h/c: Propagate combine_notes_fn return value to add_note() and beyondJohan Herland
The combine_notes_fn functions uses a non-zero return value to indicate failure. However, this return value was converted to a call to die() in note_tree_insert(). Instead, propagate this return value out to add_note(), and return it from there to enable the caller to handle errors appropriately. Existing add_note() callers are updated to die() upon failure, thus preserving the current behaviour. The only exceptions are copy_note() and notes_cache_put() where we are able to propagate the add_note() return value instead. This patch has been improved by the following contributions: - Jonathan Nieder: Future-proof by always checking add_note() return value - Jonathan Nieder: Improve clarity of final if-condition in note_tree_insert() Thanks-to: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10notes.h/c: Allow combine_notes functions to remove notesJohan Herland
Allow combine_notes functions to request that a note be removed, by setting the resulting note SHA1 to null_sha1 (0000000...). For consistency, also teach note_tree_insert() to skip insertion of an empty note (a note with entry->val_sha1 equal to null_sha1) when there is no note to combine it with. In general, an empty note (null_sha1) is treated identically to no note at all, but when adding an empty note where there already exists a non-empty note, we allow the combine_notes function to potentially record a new/changed note. Document this behaviour, and clearly specify how combine_notes functions are expected to handle null_sha1 in input. Before this patch, storing null_sha1s in the notes tree were silently allowed, causing an invalid notes tree (referring to blobs with null_sha1) to be produced by write_notes_tree(). Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10notes.c: Reorder functions in preparation for next commitJohan Herland
This patch introduces no functional change. It consists solely of reordering functions in notes.c to avoid use-before-declaration errors after applying the next commit in this series. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10notes.h: Make default_notes_ref() available in notes APIJohan Herland
Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-11-10notes.c: Hexify SHA1 in die() message from init_notes()Johan Herland
Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-08-31notes: Don't create (empty) commit when removing non-existing notesJohan Herland
Extend remove_note() in the notes API to return whether or not a note was actually removed. Use this in 'git notes remove' to skip the creation of a notes commit when no notes were actually removed. Also add a test illustrating the change in behavior. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-07-05Convert the users of for_each_string_list to for_each_string_list_item macroAlex Riesen
The rule for selecting the candidates for conversion is: if the callback function returns only 0 (the condition for for_each_string_list to exit early), than it can be safely converted to the macro. A notable exception are the callers in builtin/remote.c. If converted, the readability in the file will suffer greately. Besides, the code is not very performance critical (at the moment, at least): it does output formatting of the list of remotes. Signed-off-by: Alex Riesen <raa.lkml@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-06-30Merge branch 'jp/string-list-api-cleanup'Junio C Hamano
* jp/string-list-api-cleanup: string_list: Fix argument order for string_list_append string_list: Fix argument order for string_list_lookup string_list: Fix argument order for string_list_insert_at_index string_list: Fix argument order for string_list_insert string_list: Fix argument order for for_each_string_list string_list: Fix argument order for print_string_list
2010-06-29Merge branch 'maint'Junio C Hamano
* maint: Update draft release notes to 1.7.1.1 notes: Initialise variable to appease gcc notes: check number of parameters to "git notes copy"
2010-06-28notes: Initialise variable to appease gccRamsay Jones
gcc version 3.4.4 thinks that the 'cmp' variable could be used while uninitialised and complains thus: notes.c: In function `write_each_non_note_until': notes.c:719: warning: 'cmp' might be used uninitialized in \ this function Note that gcc versions 4.1.2 and 4.4.0 do not issue this warning. Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>
2010-06-27string_list: Fix argument order for string_list_appendJulian Phillips
Update the definition and callers of string_list_append to use the string_list as the first argument. This helps make the string_list API easier to use by being more consistent. Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk> Signed-off-by: Junio C Hamano <gitster@pobox.com>