summaryrefslogtreecommitdiff
Commit message (Collapse)AuthorAgeFilesLines
* repack_without_ref(): call clear_packed_ref_cache()mh/ref-api-restMichael Haggerty2011-12-121-2/+5
| | | | | | | | | | | Call clear_packed_ref_cache() from repack_without_ref(). This is a more logical place to call it than from delete_ref(). Also, repack_without_ref() is smart enough to know that it doesn't have to invalidate the cache if the reference was not found among the packed refs. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* read_packed_refs(): keep track of the directory being worked inMichael Haggerty2011-12-121-1/+15
| | | | | | | | | | | Packed references are stored in $GIT_DIR/packed-refs sorted, so adjacent ones are pretty likely to be in the same directory. So while reading them, keep track of the last directory used, and reuse it if possible to avoid searching the reference namespace from the root each time. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* is_refname_available(): query only possibly-conflicting referencesMichael Haggerty2011-12-121-27/+47
| | | | | | | | | | | | | | | | | | | Instead of iterating through all of the references, inquire more pointedly about the references that could conflict with the new name. This requires checking for a few individual references, plus iterating through a small subtree of the rest of the references (and usually the subtree iteration ends without having to recurse). A big benefit is that populating the whole loose reference cache (which can be very expensive) can usually be avoided. Also, simplify name_conflict_fn(). Since it now will only be called for possibly-conflicting references, there is necessarily a conflict if it is called for *any* reference besides "oldrefname". Remove function names_conflict(), which is now unused. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* refs: read loose references lazilyMichael Haggerty2011-12-121-24/+88
| | | | | | | | | | | | | | Instead of reading the whole directory of loose references the first time any are needed, only read them on demand, one directory at a time. Use a new ref_entry flag value REF_DIR_INCOMPLETE to indicate that the entry represents a REF_DIR that hasn't been read yet. Whenever any entries from such a directory are needed, read all of the loose references from that directory. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* read_loose_refs(): take a (ref_entry *) as argumentMichael Haggerty2011-12-121-10/+11
| | | | | | | | | Rename get_ref_dir() to read_loose_refs(), and change its signature. This is another step towards reading loose references one directory at a time. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* struct ref_dir: store a reference to the enclosing ref_cacheMichael Haggerty2011-12-121-5/+16
| | | | | | | | This means that it contains enough information to serve as the sole argument to get_ref_dir(), which will be changed in the next commit. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* sort_ref_dir(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-7/+9
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* do_for_each_ref_in_dir*(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-16/+22
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* add_entry(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-5/+7
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* search_ref_dir(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-3/+6
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* find_containing_direntry(): use (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-39/+39
| | | | | | | Change type of both argument and return value. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* add_ref(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-4/+6
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* read_packed_refs(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-3/+4
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* find_ref(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-6/+8
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* is_refname_available(): take (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-5/+7
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* get_loose_refs(): return (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-4/+5
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* get_packed_refs(): return (ref_entry *) instead of (ref_dir *)Michael Haggerty2011-12-121-16/+17
| | | | | Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* refs: wrap top-level ref_dirs in ref_entriesMichael Haggerty2011-12-121-23/+29
| | | | | | | | | | | | | | | | | Wrap the top-level ref_dirs in REF_DIR style ref_entries so that we have the flag and name available when dealing with them. This affects: * cache_ref::loose * cache_ref::packed * extra_refs The next several commits will expand the use of ref_entry as opposed to ref_dir, culminating in the ability of a ref_entry representing a directory of loose references to load itself only when used. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* get_ref_dir(): keep track of the current ref_dirMichael Haggerty2011-12-121-17/+26
| | | | | | | | | Look up the ref_dir that will hold the new entries once at the start of processing of a directory. This eliminates the need to search down the reference tree to find the place to put each new reference. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* do_for_each_ref(): only iterate over the subtree that was requestedMichael Haggerty2011-12-121-6/+27
| | | | | | | | 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: sort ref_dirs lazilyMichael Haggerty2011-12-122-22/+20
| | | | | | | | | | | | | | | | | | | | | | | | | Sort ref_dirs lazily, when the ordering is needed: for searching via search_ref_dir(), and when iterating over the references via do_for_each_ref_in_dir() and do_for_each_ref_in_dirs(). This change means that we never have to sort directories recursively, so change sort_ref_dirs() to not recurse. 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 the directory that is currently being iterated over. This is not so likely, because a directory is always sorted just before being iterated over and thus can be searched through during the iteration without causing a re-sort. 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, inconsistency could result. 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(): do not sort if already sortedMichael Haggerty2011-12-121-5/+24
| | | | | | | | | | | | | | | | | | | | | | | | Keep track of how many entries in a ref_dir are already sorted. In sort_ref_dir(), only call qsort() if the dir contains unsorted entries. 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_dir(), 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_dir() 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_dir() 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>
* refs: store references hierarchicallyMichael Haggerty2011-12-121-45/+220
| | | | | | | | | | | | | | | | | 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. Please note that this change causes some extra sorting to be required, and therefore a performance regression. The old performance will be regained in the next couple of commits by (1) keeping track of when a directory is already sorted and not re-sorting it; (2) only sorting a directory when the correct order needed; and (3) not sorting directories recursively. 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 Haggerty2011-12-121-83/+83
| | | | | | | | | | | 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 Haggerty2011-12-121-13/+19
| | | | | | | | 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 Haggerty2011-12-121-2/+2
| | | | | | | | | | | | 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 Haggerty2011-12-121-2/+7
| | | | | | | | 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>
* refs.c: reorder definitions more logicallyMichael Haggerty2011-12-121-319/+322
| | | | | | | | | | 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>
* is_refname_available(): reimplement using do_for_each_ref_in_array()Michael Haggerty2011-12-121-10/+30
| | | | | | | | This implementation will survive upcoming changes to the ref_array data structure. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* names_conflict(): simplify implementationMichael Haggerty2011-12-121-13/+4
| | | | | | | 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>
* names_conflict(): new function, extracted from is_refname_available()Michael Haggerty2011-12-121-12/+31
| | | | | | | | This costs an extra strlen() in the loop, but even that small price will be clawed back in the next patch. 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 Haggerty2011-12-121-18/+28
| | | | | | | | 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 Haggerty2011-12-121-29/+42
| | | | | | | | | 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 Haggerty2011-12-121-16/+23
| | | | | | | | | 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>
* do_for_each_ref(): correctly terminate while processesing extra_refsMichael Haggerty2011-12-121-1/+4
| | | | | | | | | | | | If the user-supplied function returns a nonzero value while processing extra_refs, terminate without processing the rest of the list. This probably has no practical importance, but makes the handling of extra_refs a little bit more consistent with the handling of other refs. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* add_ref(): take a (struct ref_entry *) parametermh/ref-apiMichael Haggerty2011-12-121-9/+5
| | | | | | | | | 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-121-15/+22
| | | | | | | 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-121-5/+2
| | | | | 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-121-24/+10
| | | | | | | | | 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-121-20/+20
| | | | | | | 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>
* resolve_gitlink_ref(): improve docstringMichael Haggerty2011-12-121-2/+6
| | | | | 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-121-9/+9
| | | | | | | | 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-121-19/+17
| | | | | | | | | | | | | | 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-121-12/+25
| | | | | | | 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-121-0/+1
| | | | | 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-121-0/+5
| | | | | 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-121-7/+13
| | | | | | | | 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-121-4/+4
| | | | | | | | 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-122-11/+11
| | | | | | | | 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-123-163/+175
| | | | | | | | 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>