summaryrefslogtreecommitdiff
path: root/builtin-pack-refs.c
Commit message (Collapse)AuthorAgeFilesLines
* parse-opts: prepare for OPT_FILENAMEStephen Boyd2009-05-251-1/+1
| | | | | | | | | | To give OPT_FILENAME the prefix, we pass the prefix to parse_options() which passes the prefix to parse_options_start() which sets the prefix member of parse_opts_ctx accordingly. If there isn't a prefix in the calling context, passing NULL will suffice. Signed-off-by: Stephen Boyd <bebarino@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Make usage strings dash-lessStephan Beyer2008-07-131-1/+1
| | | | | | | | | | | | | | | When you misuse a git command, you are shown the usage string. But this is currently shown in the dashed form. So if you just copy what you see, it will not work, when the dashed form is no longer supported. This patch makes git commands show the dash-less version. For shell scripts that do not specify OPTIONS_SPEC, git-sh-setup.sh generates a dash-less usage string now. Signed-off-by: Stephan Beyer <s-beyer@gmx.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Move pack_refs() and friends into libgitJohan Herland2008-06-191-120/+1
| | | | | | | | | | | | | | | This moves pack_refs() and underlying functionality into the library, to make pack-refs functionality easily available to all git programs. Most of builtin-pack-refs.c has been moved verbatim into a new file pack-refs.c that is compiled into libgit.a. A corresponding header file, pack-refs.h, has also been added, declaring pack_refs() and the #defines associated with the flags parameter to pack_refs(). This patch introduces no other changes in functionality. Signed-off-by: Johan Herland <johan@herland.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Improve use of lockfile APIBrandon Casey2008-01-161-0/+6
| | | | | | | Remove remaining double close(2)'s. i.e. close() before commit_locked_index() or commit_lock_file(). Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Use OPT_BIT in builtin-pack-refsPierre Habouzit2007-11-111-9/+3
| | | | Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Make builtin-pack-refs.c use parse_options.Pierre Habouzit2007-10-291-27/+20
| | | | | Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
* Make every builtin-*.c file #include "builtin.h"Peter Hagervall2007-07-141-0/+1
| | | | | | | | | Make every builtin-*.c file #include "builtin.h". Also takes care of some declaration/definition mismatches. Signed-off-by: Peter Hagervall <hager@cs.umu.se> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Don't ignore a pack-refs write failureJim Meyering2007-06-261-0/+2
| | | | | | | | | | | | | Without this, if the size of refs_file at that point is ever an exact multiple of BUFSIZ, then an EIO or ENOSPC error on the final write would not be diagnosed. It's not worth worrying about EPIPE here. Although theoretically possible that someone kill this process with a manual SIGPIPE, it's not at all likely. Signed-off-by: Jim Meyering <jim@meyering.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Make the pack-refs interfaces usable from outsideLinus Torvalds2007-05-261-28/+38
| | | | | | | | | | | | | | | | | | | This just basically creates a "pack_refs()" function that could be used by anybody. You pass it in the flags you want as a bitmask (PACK_REFS_ALL and PACK_REFS_PRUNE), and it will do all the heavy lifting. Of course, it's still static, and it's all in the builtin-pack-refs.c file, so it's not actually visible to the outside, but the next step would be to just move it all to a library file (probably refs.c) and expose it. Then we could easily make "git gc" do this too. While I did it, I also made it check the return value of the fflush and fsync stage, to make sure that we don't overwrite the old packed-refs file with something that got truncated due to write errors! Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Mechanical conversion to use prefixcmp()Junio C Hamano2007-02-201-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This mechanically converts strncmp() to use prefixcmp(), but only when the parameters match specific patterns, so that they can be verified easily. Leftover from this will be fixed in a separate step, including idiotic conversions like if (!strncmp("foo", arg, 3)) => if (!(-prefixcmp(arg, "foo"))) This was done by using this script in px.perl #!/usr/bin/perl -i.bak -p if (/strncmp\(([^,]+), "([^\\"]*)", (\d+)\)/ && (length($2) == $3)) { s|strncmp\(([^,]+), "([^\\"]*)", (\d+)\)|prefixcmp($1, "$2")|; } if (/strncmp\("([^\\"]*)", ([^,]+), (\d+)\)/ && (length($1) == $3)) { s|strncmp\("([^\\"]*)", ([^,]+), (\d+)\)|(-prefixcmp($2, "$1"))|; } and running: $ git grep -l strncmp -- '*.c' | xargs perl px.perl Signed-off-by: Junio C Hamano <junkio@cox.net>
* Fix seriously broken "git pack-refs"Linus Torvalds2007-01-251-1/+3
| | | | | | | | | | | | | | | | | Do *NOT* try this on a repository you care about: git pack-refs --all --prune git pack-refs because while the first "pack-refs" does the right thing, the second pack-refs will totally screw you over. This is because the second one tries to pack only tags; we should also pack what are already packed -- otherwise we would lose them. [jc: with an additional test] Signed-off-by: Junio C Hamano <junkio@cox.net>
* --prune is now default for 'pack-refs'Junio C Hamano2007-01-081-2/+7
| | | | | | There is no reason not to, really. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Store peeled refs in packed-refs (take 2).Junio C Hamano2006-11-211-2/+6
| | | | | | | | | | | | | | | | | 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 <junkio@cox.net>
* Store peeled refs in packed-refs file.Junio C Hamano2006-11-191-4/+20
| | | | | | | This would speed up "show-ref -d" in a repository with mostly packed tags. Signed-off-by: Junio C Hamano <junkio@cox.net>
* pack-refs: Store the full name of the ref even when packing only tags.Alexandre Julliard2006-11-021-3/+5
| | | | | | | | | Using for_each_tag_ref() to enumerate tags is wrong since it removes the refs/tags/ prefix, we need to always use for_each_ref() and filter out non-tag references in the callback. Signed-off-by: Alexandre Julliard <julliard@winehq.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* git-pack-refs --allJunio C Hamano2006-10-081-2/+7
| | | | | | | | | | This changes 'git-pack-refs' to pack only tags by default. Branches are meant to be updated, either by committing onto it yourself or tracking remote branches, and packed entries can become stale easily, but tags are usually "create once and live forever" and benefit more from packing. Signed-off-by: Junio C Hamano <junkio@cox.net>
* pack-refs: call fflush before fsync.Junio C Hamano2006-10-041-0/+1
| | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
* pack-refs: use lockfile as everybody else does.Junio C Hamano2006-10-031-17/+4
| | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
* Clean-up lock-ref implementationJunio C Hamano2006-09-271-1/+1
| | | | | | | This drops "mustexist" parameter lock_ref_sha1() and lock_any_ref_forupdate() functions take. Signed-off-by: Junio C Hamano <junkio@cox.net>
* pack-refs: fix git_path() usage.Junio C Hamano2006-09-221-1/+1
| | | | Signed-off-by: Junio C Hamano <junkio@cox.net>
* git-pack-refs --pruneJunio C Hamano2006-09-211-9/+75
| | | | | | | | | | | | "git pack-refs --prune", after successfully packing the existing refs, removes the loose ref files. It tries to protect against race by doing the usual lock_ref_sha1() which makes sure the contents of the ref has not changed since we last looked at. Also we do not bother trying to prune what was already packed, and we do not try pruning symbolic refs. Signed-off-by: Junio C Hamano <junkio@cox.net>
* pack-refs: do not pack symbolic refs.Junio C Hamano2006-09-211-1/+3
| | | | | | | Now we can tell which one is symbolic and which one is not, it is easy to do so. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Tell between packed, unpacked and symbolic refs.Junio C Hamano2006-09-201-1/+2
| | | | | | | | | This adds a "int *flag" parameter to resolve_ref() and makes for_each_ref() family to call callback function with an extra "int flag" parameter. They are used to give two bits of information (REF_ISSYMREF and REF_ISPACKED) about the ref. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Add callback data to for_each_ref() family.Junio C Hamano2006-09-201-3/+5
| | | | | | | | | | | | | | | | | | | | This is a long overdue fix to the API for for_each_ref() family of functions. It allows the callers to specify a callback data pointer, so that the caller does not have to use static variables to communicate with the callback funciton. The updated for_each_ref() family takes a function of type int (*fn)(const char *, const unsigned char *, void *) and a void pointer as parameters, and calls the function with the name of the ref and its SHA-1 with the caller-supplied void pointer as parameters. The commit updates two callers, builtin-name-rev.c and builtin-pack-refs.c as an example. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Start handling references internally as a sorted in-memory listLinus Torvalds2006-09-171-0/+41
This also adds some very rudimentary support for the notion of packed refs. HOWEVER! At this point it isn't used to actually look up a ref yet, only for listing them (ie "for_each_ref()" and friends see the packed refs, but none of the other single-ref lookup routines). Note how we keep two separate lists: one for the loose refs, and one for the packed refs we read. That's so that we can easily keep the two apart, and read only one set or the other (and still always make sure that the loose refs take precedence). [ From this, it's not actually obvious why we'd keep the two separate lists, but it's important to have the packed refs on their own list later on, when I add support for looking up a single loose one. For that case, we will want to read _just_ the packed refs in case the single-ref lookup fails, yet we may end up needing the other list at some point in the future, so keeping them separated is important ] Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>