aboutsummaryrefslogtreecommitdiff
path: root/refs.c
Commit message (Collapse)AuthorAge
* Merge branch 'nd/i18n'Junio C Hamano2012-05-02
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | More message strings marked for i18n. By Nguyễn Thái Ngọc Duy (10) and Jonathan Nieder (1) * nd/i18n: help: replace underlining "help -a" headers using hyphens with a blank line i18n: bundle: mark strings for translation i18n: index-pack: mark strings for translation i18n: apply: update say_patch_name to give translators complete sentence i18n: apply: mark strings for translation i18n: remote: mark strings for translation i18n: make warn_dangling_symref() automatically append \n i18n: help: mark strings for translation i18n: mark relative dates for translation strbuf: convenience format functions with \n automatically appended Makefile: feed all header files to xgettext
| * i18n: make warn_dangling_symref() automatically append \nNguyễn Thái Ngọc Duy2012-04-24
| | | | | | | | | | | | | | This helps remove \n from translatable strings Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | do_for_each_ref(): only iterate over the subtree that was requestedMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | If the base argument has a "/" chararacter, then only iterate over the reference subdir whose name is the part up to the last "/". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | refs: store references hierarchicallyMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Store references hierarchically in a tree that matches the pseudo-directory structure of the reference names. Add a new kind of ref_entry (with flag REF_DIR) to represent a whole subdirectory of references. Sort ref_dirs one subdirectory at a time. NOTE: the dirs can now be sorted as a side-effect of other function calls. Therefore, it would be problematic to do something from a each_ref_fn callback that could provoke the sorting of a directory that is currently being iterated over (i.e., the directory containing the entry that is being processed or any of its parents). This is a bit far-fetched, because a directory is always sorted just before being iterated over. Therefore, read-only accesses cannot trigger the sorting of a directory whose iteration has already started. But if a callback function would add a reference to a parent directory of the reference in the iteration, then try to resolve a reference under that directory, a re-sort could be triggered and cause the iteration to work incorrectly. Nevertheless...add a comment in refs.h warning against modifications during iteration. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | sort_ref_dir(): simplify logicMichael Haggerty2012-04-10
| | | | | | | | | | | | | | Use the more usual indexing idiom for clarity. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | refs.c: rename ref_array -> ref_dirMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | | | | | | | This purely textual change is in preparation for storing references hierarchically, when the old ref_array structure will represent one "directory" of references. Rename functions that deal with this structure analogously, and also rename the structure's "refs" member to "entries". Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | struct ref_entry: nest the value part in a unionMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | This change is obviously silly by itself, but it is a step towards adding a second member to the union. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | check_refname_component(): return 0 for zero-length componentsMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | | | | | | | | | Return 0 (instead of -1) for zero-length components. Move the interpretation of zero-length components as illegal to check_refname_format(). This will make it easier to extend check_refname_format() to also check whether directory names are valid. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | free_ref_entry(): new functionMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | Add a function free_ref_entry(). This function will become nontrivial when ref_entry (soon) becomes polymorphic. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | names_conflict(): simplify implementationMichael Haggerty2012-04-10
| | | | | | | | | | | | | | Save a bunch of lines of code and a couple of strlen() calls. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | repack_without_ref(): reimplement using do_for_each_ref_in_array()Michael Haggerty2012-04-10
| | | | | | | | | | | | | | | | It costs a bit of boilerplate, but it means that the function can be ignorant of how cached refs are stored. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | do_for_each_ref_in_arrays(): new functionMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | | | Extract function do_for_each_ref_in_arrays() from do_for_each_ref(). The new function will be a useful building block for storing refs hierarchically. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | do_for_each_ref_in_array(): new functionMichael Haggerty2012-04-10
| | | | | | | | | | | | | | | | | | Extract function do_for_each_ref_in_array() from do_for_each_ref(). The new function will be a useful building block for storing refs hierarchically. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | refs: manage current_ref within do_one_ref()Michael Haggerty2012-04-10
| | | | | | | | | | | | | | | | Set and clear current_ref within do_one_ref() instead of setting it here and leaving it to somebody else to clear it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | refs.c: reorder definitions more logicallyMichael Haggerty2012-04-10
|/ | | | | | | | | | Reorder definitions in file: first check_refname_format() and helper functions, then the functions for managing the ref_entry and ref_array data structures, then ref_cache, then the more "business-logicky" stuff. No code is changed. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* refs: remove the extra_refs APIMichael Haggerty2012-02-12
| | | | | | | | | | The extra_refs provided a kludgy way to create fake references at a global level in the hope that they would only affect some particular code path. The last user of this API been rewritten, so strip this stuff out before somebody else gets the bad idea of using it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* add_packed_ref(): new function in the refs API.Michael Haggerty2012-01-17
| | | | | | | | | Add a new function add_packed_ref() that adds a reference directly to the in-memory packed reference cache. This will be useful for creating local references while cloning. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* ref_array: keep track of whether references are sortedMichael Haggerty2012-01-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Keep track of how many entries at the beginning of a ref_array are already sorted. In sort_ref_array(), return early if the the array is already sorted (i.e., if no new references has been appended to the end of the list since the last call to sort_ref_array()). Sort ref_arrays only when needed, namely in search_ref_array() and in do_for_each_ref(). However, never call sort_ref_array() on the extra_refs, because extra_refs can contain multiple entries with the same name and because sort_ref_array() not only sorts, but de-dups its contents. This change is currently not useful, because entries are not added to ref_arrays after they are created. But in a moment they will be... Implementation note: we could store a binary "sorted" value instead of an integer, but storing the number of sorted entries leaves the way open for a couple of possible future optimizations: * In sort_ref_array(), sort *only* the unsorted entries, then merge them with the sorted entries. This should be faster if most of the entries are already sorted. * Teach search_ref_array() to do a binary search of any sorted entries, and if unsuccessful do a linear search of any unsorted entries. This would avoid the need to sort the list every time that search_ref_array() is called, and (given some intelligence about how often to sort) could significantly improve the speed in certain hypothetical usage patterns. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'mh/ref-api'Junio C Hamano2011-12-20
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * mh/ref-api: add_ref(): take a (struct ref_entry *) parameter create_ref_entry(): extract function from add_ref() repack_without_ref(): remove temporary resolve_gitlink_ref_recursive(): change to work with struct ref_cache Pass a (ref_cache *) to the resolve_gitlink_*() helper functions resolve_gitlink_ref(): improve docstring get_ref_dir(): change signature refs: change signatures of get_packed_refs() and get_loose_refs() is_dup_ref(): extract function from sort_ref_array() add_ref(): add docstring parse_ref_line(): add docstring is_refname_available(): remove the "quiet" argument clear_ref_array(): rename from free_ref_array() refs: rename parameters result -> sha1 refs: rename "refname" variables struct ref_entry: document name member Conflicts: cache.h refs.c
| * add_ref(): take a (struct ref_entry *) parameterMichael Haggerty2011-12-12
| | | | | | | | | | | | | | | | | | Take a pointer to the ref_entry to add to the array, rather than creating the ref_entry within the function. This opens the way to having multiple kinds of ref_entries. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * create_ref_entry(): extract function from add_ref()Michael Haggerty2011-12-12
| | | | | | | | | | | | | | Separate the creation of the ref_entry from its addition to a ref_array. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * repack_without_ref(): remove temporaryMichael Haggerty2011-12-12
| | | | | | | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * resolve_gitlink_ref_recursive(): change to work with struct ref_cacheMichael Haggerty2011-12-12
| | | | | | | | | | | | | | | | | | resolve_gitlink_ref() and resolve_gitlink_ref_recursive(), together, basically duplicated the code in git_path_submodule(). So use that function instead. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * Pass a (ref_cache *) to the resolve_gitlink_*() helper functionsMichael Haggerty2011-12-12
| | | | | | | | | | | | | | And remove some redundant arguments from resolve_gitlink_packed_ref(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * get_ref_dir(): change signatureMichael Haggerty2011-12-12
| | | | | | | | | | | | | | | | Change get_ref_dir() to take a (struct ref_cache *) in place of the submodule name. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * refs: change signatures of get_packed_refs() and get_loose_refs()Michael Haggerty2011-12-12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Change get_packed_refs() and get_loose_refs() to take a (struct ref_cache *) instead of the name of the submodule. Change get_ref_dir() to take a submodule name (i.e., "" for the main module) rather than a submodule pointer (i.e., NULL for the main module) so that refs->name can be used as its argument. (In a moment this function will also be changed to take a (struct ref_cache *), too.) Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * is_dup_ref(): extract function from sort_ref_array()Michael Haggerty2011-12-12
| | | | | | | | | | | | | | Giving the function a name makes the code easier to understand. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * add_ref(): add docstringMichael Haggerty2011-12-12
| | | | | | | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * parse_ref_line(): add docstringMichael Haggerty2011-12-12
| | | | | | | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * is_refname_available(): remove the "quiet" argumentMichael Haggerty2011-12-12
| | | | | | | | | | | | | | | | quiet was always set to 0, so get rid of it. Add a function docstring for good measure. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * clear_ref_array(): rename from free_ref_array()Michael Haggerty2011-12-12
| | | | | | | | | | | | | | | | Rename the function since it doesn't actually free the array object that is passed to it. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * refs: rename parameters result -> sha1Michael Haggerty2011-12-12
| | | | | | | | | | | | | | | | Try consistently to use the name "sha1" for parameters to which a SHA1 will be stored. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * refs: rename "refname" variablesMichael Haggerty2011-12-12
| | | | | | | | | | | | | | | | Try to consistently use the variable name "refname" when referring to a string that names a reference. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * struct ref_entry: document name memberMichael Haggerty2011-12-12
| | | | | | | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Rename resolve_ref() to resolve_ref_unsafe()Nguyễn Thái Ngọc Duy2011-12-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | resolve_ref() may return a pointer to a shared buffer and can be overwritten by the next resolve_ref() calls. Callers need to pay attention, not to keep the pointer when the next call happens. Rename with "_unsafe" suffix to warn developers (or reviewers) before introducing new call sites. This patch is generated using the following command git grep -l 'resolve_ref(' -- '*.[ch]'|xargs sed -i 's/resolve_ref(/resolve_ref_unsafe(/g' Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Convert resolve_ref+xstrdup to new resolve_refdup functionNguyễn Thái Ngọc Duy2011-12-13
|/ | | | | Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'nd/resolve-ref'Junio C Hamano2011-12-09
|\ | | | | | | | | | | | | | | | | | | | | * nd/resolve-ref: Copy resolve_ref() return value for longer use Convert many resolve_ref() calls to read_ref*() and ref_exists() Conflicts: builtin/fmt-merge-msg.c builtin/merge.c refs.c
| * Convert many resolve_ref() calls to read_ref*() and ref_exists()Nguyễn Thái Ngọc Duy2011-11-13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | resolve_ref() may return a pointer to a static buffer, which is not safe for long-term use because if another resolve_ref() call happens, the buffer may be changed. Many call sites though do not care about this buffer. They simply check if the return value is NULL or not. Convert all these call sites to new wrappers to reduce resolve_ref() calls from 57 to 34. If we change resolve_ref() prototype later on to avoid passing static buffer out, this helps reduce changes. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'jc/pull-signed-tag'Junio C Hamano2011-12-09
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * jc/pull-signed-tag: commit-tree: teach -m/-F options to read logs from elsewhere commit-tree: update the command line parsing commit: teach --amend to carry forward extra headers merge: force edit and no-ff mode when merging a tag object commit: copy merged signed tags to headers of merge commit merge: record tag objects without peeling in MERGE_HEAD merge: make usage of commit->util more extensible fmt-merge-msg: Add contents of merged tag in the merge message fmt-merge-msg: package options into a structure fmt-merge-msg: avoid early returns refs DWIMmery: use the same rule for both "git fetch" and others fetch: allow "git fetch $there v1.0" to fetch a tag merge: notice local merging of tags and keep it unwrapped fetch: do not store peeled tag object names in FETCH_HEAD Split GPG interface into its own helper library Conflicts: builtin/fmt-merge-msg.c builtin/merge.c
| * | refs DWIMmery: use the same rule for both "git fetch" and othersJunio C Hamano2011-11-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "git log frotz" can DWIM to "refs/remotes/frotz/HEAD", but in the remote access context, "git fetch frotz" to fetch what the other side happened to have fetched from what it calls 'frotz' (which may not have any relation to what we consider is 'frotz') the last time would not make much sense, so the fetch rules table did not include "refs/remotes/%.*s/HEAD". When the user really wants to, "git fetch $there remotes/frotz/HEAD" would let her do so anyway, so this is not about safety or security; it merely is about confusion avoidance and discouraging meaningless usage. Specifically, it is _not_ about ambiguity avoidance. A name that would become ambiguous if we use the same rules table for both fetch and local rev-parse would be ambiguous locally at the remote side. So for the same reason as we added rule to allow "git fetch $there v1.0" instead of "git fetch $there tags/v1.0" in the previous commit, here is a bit longer rope for the users, which incidentally simplifies our code. Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | fetch: allow "git fetch $there v1.0" to fetch a tagJunio C Hamano2011-11-07
| | | | | | | | | | | | | | | | | | | | | You can already do so with "git fetch $there tags/v1.0" but if it is not ambiguous there is no reason to force users to type more. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | refs: loosen over-strict "format" checkJunio C Hamano2011-11-16
| |/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The add_extra_ref() interface is used to add an extra-ref that is _not_ our ref for the purpose of helping auto-following of tags and reducing object transfer from remote repository, and they are typically formatted as a tagname followed by ^{} to make sure no valid refs match that pattern. In other words, these entries are deliberately formatted not to pass check-refname-format test. A recent series however added a test unconditionally to the add_ref() function that is called from add_extra_ref(). The check may be sensible for other two callsites of the add_ref() interface, but definitely is a wrong thing to do in add_extra_ref(). Disable it. Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu>
* | Merge branch 'jc/broken-ref-dwim-fix'Junio C Hamano2011-10-21
|\ \ | | | | | | | | | | | | | | | | | | * jc/broken-ref-dwim-fix: resolve_ref(): report breakage to the caller without warning resolve_ref(): expose REF_ISBROKEN flag refs.c: move dwim_ref()/dwim_log() from sha1_name.c
| * | resolve_ref(): report breakage to the caller without warningJunio C Hamano2011-10-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 629cd3a (resolve_ref(): emit warnings for improperly-formatted references, 2011-09-15) made resolve_ref() warn against files that are found in the directories the ref dwimmery looks at. The intent may be good, but these messages come from a wrong level of the API hierarchy. Instead record the breakage in "flags" whose purpose is to explain the result of the function to the caller, who is in a much better position to make intelligent decision based on the information. This updates sha1_name.c::dwim_ref() to warn against such a broken candidate only when it does not appear directly below $GIT_DIR to restore the traditional behaviour, as we know many files directly underneath $GIT_DIR/ are not refs. Warning against "git show config --" with "$GIT_DIR/config does not look like a well-formed ref" does not make sense, and we may later tweak the dwimmery not to even consider them as candidates, but that is a longer term topic. Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | resolve_ref(): expose REF_ISBROKEN flagJunio C Hamano2011-10-19
| | | | | | | | | | | | | | | | | | | | | | | | Instead of keeping this as an internal API, let the callers find out the reason why resolve_ref() returned NULL is not because there was no such file in $GIT_DIR but because a file was corrupt. Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | refs.c: move dwim_ref()/dwim_log() from sha1_name.cJunio C Hamano2011-10-12
| | | | | | | | | | | | | | | | | | | | | | | | Both dwim_ref()/dwim_log() functions are intimately related to the ref parsing rules defined in refs.c and better fits there. Move them together with substitute_branch_name(), a file scope static helper function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Merge branch 'mh/ref-api'Junio C Hamano2011-10-21
|\ \ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * mh/ref-api: clear_ref_cache(): inline function write_ref_sha1(): only invalidate the loose ref cache clear_ref_cache(): extract two new functions clear_ref_cache(): rename parameter invalidate_ref_cache(): expose this function in the refs API invalidate_ref_cache(): take the submodule as parameter invalidate_ref_cache(): rename function from invalidate_cached_refs()
| * | | clear_ref_cache(): inline functionMichael Haggerty2011-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | clear_ref_cache() was only called from one place, so inline it there. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | | write_ref_sha1(): only invalidate the loose ref cacheMichael Haggerty2011-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since write_ref_sha1() can only write loose refs and cannot write symbolic refs, there is no need for it to invalidate the packed ref cache. Suggested by: Martin Fick <mfick@codeaurora.org> Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | | clear_ref_cache(): extract two new functionsMichael Haggerty2011-10-16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Extract two new functions from clear_cached_refs(): clear_loose_ref_cache() and clear_packed_ref_cache(). Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>