path: root/refs.h
AgeCommit message (Collapse)Author
2012-04-10refs: store references hierarchicallyMichael Haggerty
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 <> Signed-off-by: Junio C Hamano <>
2012-02-13refs: remove the extra_refs APIMichael Haggerty
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 <> Signed-off-by: Junio C Hamano <>
2012-01-17add_packed_ref(): new function in the refs API.Michael Haggerty
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 <> Signed-off-by: Junio C Hamano <>
2011-12-12resolve_gitlink_ref(): improve docstringMichael Haggerty
Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
2011-12-12refs: rename parameters result -> sha1Michael Haggerty
Try consistently to use the name "sha1" for parameters to which a SHA1 will be stored. Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
2011-12-12refs: rename "refname" variablesMichael Haggerty
Try to consistently use the variable name "refname" when referring to a string that names a reference. Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
2011-10-21Merge branch 'jc/broken-ref-dwim-fix'Junio C Hamano
* 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
2011-10-19resolve_ref(): expose REF_ISBROKEN flagJunio C Hamano
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 <>
2011-10-17invalidate_ref_cache(): expose this function in the refs APIMichael Haggerty
Make invalidate_ref_cache() an official part of the refs API. It is currently a fact of life that code outside of refs.c mucks about with references. This change gives such code a way of informing the refs module that it should no longer trust its cache. Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
2011-10-10Merge branch 'jp/get-ref-dir-unsorted'Junio C Hamano
* jp/get-ref-dir-unsorted: refs.c: free duplicate entries in the ref array instead of leaking them refs.c: abort ref search if ref array is empty refs.c: ensure struct whose member may be passed to realloc is initialized refs: Use binary search to lookup refs faster Don't sort ref_list too early Conflicts: refs.c
2011-10-05add_ref(): verify that the refname is formatted correctlyMichael Haggerty
In add_ref(), verify that the refname is formatted correctly before adding it to the ref_list. Here we have to allow refname components that start with ".", since (for example) the remote protocol uses synthetic reference name ".have". So add a new REFNAME_DOT_COMPONENT flag that can be passed to check_refname_format() to allow leading dots. Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
2011-10-05Change check_refname_format() to reject unnormalized refnamesMichael Haggerty
Since much of the infrastructure does not work correctly with unnormalized refnames, change check_refname_format() to reject them. Similarly, change "git check-ref-format" to reject unnormalized refnames by default. But add an option --normalize, which causes "git check-ref-format" to normalize the refname before checking its format, and print the normalized refname. This is exactly the behavior of the old --print option, which is retained but deprecated. Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
2011-10-05Change check_ref_format() to take a flags argumentMichael Haggerty
Change check_ref_format() to take a flags argument that indicates what is acceptable in the reference name (analogous to "git check-ref-format"'s "--allow-onelevel" and "--refspec-pattern"). This is more convenient for callers and also fixes a failure in the test suite (and likely elsewhere in the code) by enabling "onelevel" and "refspec-pattern" to be allowed independently of each other. Also rename check_ref_format() to check_refname_format() to make it obvious that it deals with refnames rather than references themselves. Signed-off-by: Michael Haggerty <> Signed-off-by: Junio C Hamano <>
2011-08-18Merge branch 'js/ref-namespaces'Junio C Hamano
* js/ref-namespaces: ref namespaces: tests ref namespaces: documentation ref namespaces: Support remote repositories via upload-pack and receive-pack ref namespaces: infrastructure Fix prefix handling in ref iteration functions
2011-07-06ref namespaces: infrastructureJosh Triplett
Add support for dividing the refs of a single repository into multiple namespaces, each of which can have its own branches, tags, and HEAD. Git can expose each namespace as an independent repository to pull from and push to, while sharing the object store, and exposing all the refs to operations such as git-gc. Storing multiple repositories as namespaces of a single repository avoids storing duplicate copies of the same objects, such as when storing multiple branches of the same source. The alternates mechanism provides similar support for avoiding duplicates, but alternates do not prevent duplication between new objects added to the repositories without ongoing maintenance, while namespaces do. To specify a namespace, set the GIT_NAMESPACE environment variable to the namespace. For each ref namespace, git stores the corresponding refs in a directory under refs/namespaces/. For example, GIT_NAMESPACE=foo will store refs under refs/namespaces/foo/. You can also specify namespaces via the --namespace option to git. Note that namespaces which include a / will expand to a hierarchy of namespaces; for example, GIT_NAMESPACE=foo/bar will store refs under refs/namespaces/foo/refs/namespaces/bar/. This makes paths in GIT_NAMESPACE behave hierarchically, so that cloning with GIT_NAMESPACE=foo/bar produces the same result as cloning with GIT_NAMESPACE=foo and cloning from that repo with GIT_NAMESPACE=bar. It also avoids ambiguity with strange namespace paths such as foo/refs/heads/, which could otherwise generate directory/file conflicts within the refs directory. Add the infrastructure for ref namespaces: handle the GIT_NAMESPACE environment variable and --namespace option, and support iterating over refs in a namespace. Signed-off-by: Josh Triplett <> Signed-off-by: Jamey Sharp <> Signed-off-by: Junio C Hamano <>
2011-06-30Merge branch 'jc/maint-1.7.3-checkout-describe'Junio C Hamano
* jc/maint-1.7.3-checkout-describe: checkout -b <name>: correctly detect existing branch
2011-06-06checkout -b <name>: correctly detect existing branchJunio C Hamano
When create a new branch, we fed "refs/heads/<proposed name>" as a string to get_sha1() and expected it to fail when a branch already exists. The right way to check if a ref exists is to check with resolve_ref(). A naïve solution that might appear attractive but does not work is to forbid slashes in get_describe_name() but that will not work. A describe name is is in the form of "ANYTHING-g<short sha1>", and that ANYTHING part comes from a original tag name used in the repository the user ran the describe command. A sick user could have a confusing hierarchical tag whose name is "refs/heads/foobar" (stored as refs/tags/refs/heads/foobar") to generate a describe name "refs/heads/foobar-6-g02ac983", and we should be able to use that name to refer to the object whose name is 02ac983. Signed-off-by: Junio C Hamano <>
2010-07-07setup_revisions(): Allow walking history in a submoduleHeiko Voigt
By passing the path to a submodule in opt->submodule, the function can be used to walk history in the named submodule repository, instead of the toplevel repository. Signed-off-by: Heiko Voigt <> Signed-off-by: Junio C Hamano <>
2010-06-12log_ref_setup: don't return stack-allocated arrayThomas Rast
859c301 (refs: split log_ref_write logic into log_ref_setup, 2010-05-21) refactors the stack allocation of the log_file array into the new log_ref_setup() function, but passes it back to the caller. Since the original intent seems to have been to split the work between log_ref_setup and log_ref_write, make it the caller's responsibility to allocate the buffer. Signed-off-by: Thomas Rast <> Reported-by: Ævar Arnfjörð Bjarmason <> Signed-off-by: Junio C Hamano <>
2010-06-02refs: split log_ref_write logic into log_ref_setupErick Mattos
Separation of the logic for testing and preparing the reflogs from function log_ref_write to a new non static new function: log_ref_setup. This allows to be performed from outside the first all reasonable checks and procedures for writing reflogs. Signed-off-by: Erick Mattos <> Signed-off-by: Junio C Hamano <>
2010-03-13Support showing notes from more than one notes treeThomas Rast
With this patch, you can set notes.displayRef to a glob that points at your favourite notes refs, e.g., [notes] displayRef = refs/notes/* Then git-log and friends will show notes from all trees. Thanks to Junio C Hamano for lots of feedback, which greatly influenced the design of the entire series and this commit in particular. Signed-off-by: Thomas Rast <> Acked-by: Johan Herland <> Signed-off-by: Junio C Hamano <>
2010-01-20rev-parse --branches/--tags/--remotes=patternIlari Liusvaara
Since local branch, tags and remote tracking branch namespaces are most often used, add shortcut notations for globbing those in manner similar to --glob option. With this, one can express the "what I have but origin doesn't?" as: 'git log --branches --not --remotes=origin' Original-idea-by: Johannes Sixt <> Signed-off-by: Ilari Liusvaara <> Signed-off-by: Junio C Hamano <>
2010-01-20rev-parse --globIlari Liusvaara
Add --glob=<glob-pattern> option to rev-parse and everything that accepts its options. This option matches all refs that match given shell glob pattern (complete with some DWIM logic). Example: 'git log --branches --not --glob=remotes/origin' To show what you have that origin doesn't. Signed-off-by: Ilari Liusvaara <> Signed-off-by: Junio C Hamano <>
2009-11-10teach warn_dangling_symref to take a FILE argumentJay Soffian
Different callers of warn_dangling_symref() may want to control whether its output goes to stdout or stderr so let it take a FILE argument. Signed-off-by: Jay Soffian <> Signed-off-by: Junio C Hamano <>
2009-06-01refs: add a "for_each_replace_ref" functionChristian Couder
This is some preparation work for the following patches that are using the "refs/replace/" ref namespace. Signed-off-by: Christian Couder <> Signed-off-by: Junio C Hamano <>
2009-05-14Change prettify_ref to prettify_refnameFelipe Contreras
In preparation to be used when the ref object is not available Signed-off-by: Felipe Contreras <> Acked-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2009-04-13shorten_unambiguous_ref(): add strict modeBert Wesarg
Add the strict mode of abbreviation to shorten_unambiguous_ref(), i.e. the resulting ref won't trigger the ambiguous ref warning. All users of shorten_unambiguous_ref() still use the loose mode. Signed-off-by: Bert Wesarg <> Signed-off-by: Junio C Hamano <>
2009-04-12Merge branch 'jk/show-upstream'Junio C Hamano
* jk/show-upstream: branch: show upstream branch when double verbose make get_short_ref a public function for-each-ref: add "upstream" format field for-each-ref: refactor refname handling for-each-ref: refactor get_short_ref function
2009-04-08make get_short_ref a public functionJeff King
Often we want to shorten a full ref name to something "prettier" to show a user. For example, "refs/heads/master" is often shown simply as "master", or "refs/remotes/origin/master" is shown as "origin/master". Many places in the code use a very simple formula: skip common prefixes like refs/heads, refs/remotes, etc. This is codified in the prettify_ref function. for-each-ref has a more correct (but more expensive) approach: consider the ref lookup rules, and try shortening as much as possible while remaining unambiguous. This patch makes the latter strategy globally available as shorten_unambiguous_ref. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2009-04-05Merge branch 'cc/sha1-bsearch' into HEADJunio C Hamano
* cc/sha1-bsearch: (95 commits) patch-ids: use the new generic "sha1_pos" function to lookup sha1 sha1-lookup: add new "sha1_pos" function to efficiently lookup sha1 Update draft release notes to 1.6.3 GIT send-email: ensure quoted addresses are rfc2047 encoded send-email: correct two tests which were going interactive Documentation: git-svn: fix trunk/fetch svn-remote key typo Mailmap: Allow empty email addresses to be mapped Cleanup warning about known issues in cvsimport documentation Documentation: Remove an odd "instead" send-email: ask_default should apply to all emails, not just the first send-email: don't attempt to prompt if tty is closed fix portability problem with IS_RUN_COMMAND_ERR Documentation: use "spurious .sp" XSLT if DOCBOOK_SUPPRESS_SP is set mailmap: resurrect lower-casing of email addresses builtin-clone.c: no need to strdup for setenv builtin-clone.c: make junk_pid static git-svn: add a double quiet option to hide git commits Update draft release notes to Documentation: push.default applies to all remotes ...
2009-03-30refs: add "for_each_ref_in" function to refactor "for_each_*_ref" functionsChristian Couder
The "for_each_{tag,branch,remote,replace,}_ref" functions are redefined in terms of "for_each_ref_in" so that we can lose the hardcoded length of prefix strings from the code. Signed-off-by: Christian Couder <>
2009-03-09Use a common function to get the pretty name of refsDaniel Barkalow
The result should be consistent between fetch and push, so we ought to use the same code in both cases, even though it's short. Signed-off-by: Daniel Barkalow <> Signed-off-by: Junio C Hamano <>
2009-02-11remote prune: warn dangling symrefsJunio C Hamano
If you prune from the remote "frotz" that deleted the ref your tracking branch remotes/frotz/HEAD points at, the symbolic ref will become dangling. We used to detect this as an error condition and issued a message every time refs are enumerated. This stops the error message, but moves the warning to "remote prune". Signed-off-by: Junio C Hamano <>
2009-01-20Introduce for_each_recent_reflog_ent().Junio C Hamano
This can be used to scan only the last few kilobytes of a reflog, as a cheap optimization when the data you are looking for is likely to be found near the end of it. The caller is expected to fall back to the full scan if that is not the case. Signed-off-by: Junio C Hamano <>
2008-05-05Allow for having for_each_ref() list extra refsDaniel Barkalow
These refs can be anything, but they are most likely useful as pointing to objects that you know are in the object database but don't have any regular refs for. For example, when cloning with --reference, the refs in this repository should be listed as objects that we have, even though we don't have refs in our newly-created repository for them yet. Signed-off-by: Daniel Barkalow <> Signed-off-by: Junio C Hamano <>
2008-02-23refs.c: make close_ref() and commit_ref() non-staticBrandon Casey
This is in preparation to the reflog-expire changes which will allow updating the ref after expiring the reflog. Signed-off-by: Brandon Casey <> Signed-off-by: Junio C Hamano <>
2008-01-02lock_any_ref_for_update(): reject wildcard return from check_ref_formatJunio C Hamano
Recent check_ref_format() returns -3 as well as -1 (general error) and -2 (less than two levels). The caller was explicitly checking for -1, to allow "HEAD" but still needed to disallow bogus refs. This introduces symbolic constants for the return values from check_ref_format() to make them read better and more meaningful. Normal ref creation codepath can still treat non-zero return values as errors. Signed-off-by: Junio C Hamano <>
2007-11-16refs.c: Remove unused get_ref_sha1()Johannes Sixt
Signed-off-by: Johannes Sixt <> Signed-off-by: Junio C Hamano <>
2007-09-05Function for updating refs.Carlos Rica
A function intended to be called from builtins updating refs by locking them before write, specially those that came from scripts using "git update-ref". [jc: with minor fixups] Signed-off-by: Carlos Rica <> Signed-off-by: Junio C Hamano <>
2007-05-10git-update-ref: add --no-deref option for overwriting/detaching refSven Verdoolaege
git-checkout is also adapted to make use of this new option instead of the handcrafted command sequence. Signed-off-by: Sven Verdoolaege <> Signed-off-by: Junio C Hamano <>
2007-04-10Add 'resolve_gitlink_ref()' helper functionLinus Torvalds
This new function resolves a ref in *another* git repository. It's named for its intended use: to look up the git link to a subproject. It's not actually wired up to anything yet, but we're getting closer to having fundamental plumbing support for "links" from one git directory to another, which is the basis of subproject support. [jc: amended a FILE* leak] Signed-off-by: Linus Torvalds <> Signed-off-by: Junio C Hamano <>
2007-02-03scan reflogs independently from refsNicolas Pitre
Currently, the search for all reflogs depends on the existence of corresponding refs under the .git/refs/ directory. Let's scan the .git/logs/ directory directly instead. Signed-off-by: Nicolas Pitre <> Signed-off-by: Junio C Hamano <>
2007-01-28lock_ref_sha1_basic(): remember the original name of a ref when resolving itNicolas Pitre
A ref might be pointing to another ref but only the name of the last ref is remembered. Let's remember about the first name as well. Signed-off-by: Nicolas Pitre <> Signed-off-by: Junio C Hamano <>
2007-01-28make reflog filename independent from struct ref_lockNicolas Pitre
This allows for ref_log_write() to be used in a more flexible way, and is needed for future changes. This is only code reorg with no behavior change. Signed-off-by: Nicolas Pitre <> Signed-off-by: Junio C Hamano <>
2007-01-20Extend read_ref_at() to be usable from places other than sha1_name.Junio C Hamano
You can pass an extra argument to the function to receive the reflog message information. Also when the log does not go back beyond the point the user asked, the cut-off time and count are given back to the caller for emitting the error messages as appropriately. We could later add configuration for get_sha1_basic() to make it an error instead of it being just a warning. Signed-off-by: Junio C Hamano <>
2007-01-09Sanitize for_each_reflog_ent()Johannes Schindelin
It used to ignore the return value of the helper function; now, it expects it to return 0, and stops iteration upon non-zero return values; this value is then passed on as the return value of for_each_reflog_ent(). Further, it makes no sense to force the parsing upon the helper functions; for_each_reflog_ent() now calls the helper function with old and new sha1, the email, the timestamp & timezone, and the message. Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
2006-12-21add for_each_reflog_ent() iteratorJunio C Hamano
Signed-off-by: Junio C Hamano <>
2006-12-06git-branch: let caller specify logmsgLars Hjemli
This changes the signature of rename_ref() in refs.[hc] to include a logmessage for the reflogs. Also, builtin-branch.c is modified to provide a proper logmessage + call setup_ident() before any logmessages are written. Signed-off-by: Lars Hjemli <> Signed-off-by: Junio C Hamano <>
2006-12-06git-branch: add options and tests for branch renamingLars Hjemli
Extend git-branch with the following options: git-branch -m|-M [<oldbranch>] newbranch The -M variation is required to force renaming over an exsisting branchname. This also indroduces $GIT_DIR/RENAME_REF which is a "metabranch" used when renaming branches. It will always hold the original sha1 for the latest renamed branch. Additionally, if $GIT_DIR/logs/RENAME_REF exists, all branch rename events are logged there. Finally, some testcases are added to verify the new options. Signed-off-by: Lars Hjemli <> Signed-off-by: Junio C Hamano <>
2006-11-22Store peeled refs in packed-refs (take 2).Junio C Hamano
This fixes the previous implementation which failed to optimize repositories with tons of lightweight tags. The updated packed-refs format begins with "# packed-refs with:" line that lists the kind of extended data the file records. Currently, there is only one such extension defined, "peeled". This stores the "peeled tag" on a line that immediately follows a line for a tag object itself in the format "^<sha-1>". The header line itself and any extended data are ignored by older implementation, so packed-refs file generated with this version can still be used by older git. packed-refs made by older git can of course be used with this version. Signed-off-by: Junio C Hamano <>