summaryrefslogtreecommitdiff
path: root/sha1_file.c
AgeCommit message (Collapse)Author
2005-08-15Alternate object pool mechanism updates.Junio C Hamano
It was a mistake to use GIT_ALTERNATE_OBJECT_DIRECTORIES environment variable to specify what alternate object pools to look for missing objects when working with an object database. It is not a property of the process running the git commands, but a property of the object database that is partial and needs other object pools to complete the set of objects it lacks. This patch allows you to have $GIT_OBJECT_DIRECTORY/info/alternates whose contents is in exactly the same format as the environment variable, to let an object database name alternate object pools it depends on. Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-10[PATCH] Warning fix for gcc 4Pavel Roskin
This patch fixes the only warning reported by gcc 4.0.1 on Fedora Core 4 for x86_64: sha1_file.c:1391: warning: pointer targets in assignment differ in signedness Signed-off-by: Pavel Roskin <proski@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-09[PATCH] Plug memory leak in write_sha1_to_fd()Sergey Vlasov
If the object to write was packed, both its uncompressed and compressed data were leaked. If the object was not packed, its file was not unmapped. [jc: I think it still leaks on the write error path of write_sha1_to_fd(), but that should be fixable in a small separate patch.] Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-09[PATCH] Plug memory leak in read_object_with_reference()Sergey Vlasov
When following a reference, read_object_with_reference() did not free the intermediate object data. Signed-off-by: Sergey Vlasov <vsu@altlinux.ru> Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-05Update get_sha1() to grok extended format.Junio C Hamano
Everybody envies rev-parse, who is the only one that can grok the extended sha1 format. Move the get_extended_sha1() out of rev-parse, rename it to get_sha1() and make it available to everybody else. The one I posted earlier to the list had one bug where it did not handle a name that ends with a digit correctly (it incorrectly tried the "Nth parent" path). This commit fixes it. Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-03[PATCH] Parallelize pulling by sshbarkalow@iabervon.org
This causes ssh-pull to request objects in prefetch() and read then in fetch(), such that it reduces the unpipelined round-trip time. This also makes sha1_write_from_fd() support having a buffer of data which it accidentally read from the fd after the object; this was formerly not a problem, because it would always get a short read at the end of an object, because the next object had not been requested. This is no longer true. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-08-01[PATCH] Functions for managing the set of packs the library is using ↵barkalow@iabervon.org
(whitespace fixed) This adds support for reading an uninstalled index, and installing a pack file that was added while the program was running, as well as functions for determining where to put the file. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-07-31Teach parse_commit_buffer about grafting.Junio C Hamano
Introduce a new file $GIT_DIR/info/grafts (or $GIT_GRAFT_FILE) which is a list of "fake commit parent records". Each line of this file is a commit ID, followed by parent commit IDs, all 40-byte hex SHA1 separated by a single SP in between. The records override the parent information we would normally read from the commit objects, allowing both adding "fake" parents (i.e. grafting), and pretending as if a commit is not a child of some of its real parents (i.e. cauterizing). Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-07-30[PATCH] mmap error handlingPavel Roskin
I have reviewed all occurrences of mmap() in git and fixed three types of errors/defects: 1) The result is not checked. 2) The file descriptor is closed if mmap() succeeds, but not when it fails. 3) Various casts applied to -1 are used instead of MAP_FAILED, which is specifically defined to check mmap() return value. [jc: This is a second round of Pavel's patch. He fixed up the problem that close() potentially clobbering the errno from mmap, which the first round had.] Signed-off-by: Pavel Roskin <proski@gnu.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-07-11[PATCH] Check packs and then files.Junio C Hamano
This reverses the order of object lookup, to check pack index first and then go to the filesystem to find .git/objects/??/ hierarchy. When most of the objects are packed, this saves quite many stat() calls and negative dcache entries; while the price this approach has to pay is negligible, even when most of the objects are outside pack, because checking pack index file is quite cheap. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-10Avoid signedness warnings in sha1_file.cLinus Torvalds
Very irritating. But "snprintf()" wants "char *", and zlib wants "unsigned char *".
2005-07-10[PATCH] Remove map_sha1_fileDaniel Barkalow
Remove map_sha1_file(), now unused. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-10[PATCH] write_sha1_to_fd()Daniel Barkalow
Add write_sha1_to_fd(), which writes an object to a file descriptor. This includes support for unpacking it and recompressing it. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-09[PATCH] Expose object ID computation functions.Bryan Larsen
This patch makes the first half of write_sha1_file() and index_fd() externally visible, to allow callers to compute the object ID without actually storing it in the object database. [JC demangled the whitespaces himself because he liked the patch so much, and reworked the interface to index_fd() slightly, taking suggestion from Linus and of his own.] Signed-off-by: Bryan Larsen <bryan.larsen@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-08Add "mkpath()" helper functionLinus Torvalds
I'm bored with doing it by hand all the time.
2005-07-06[PATCH] clone-pack.c:write_one_ref() - Create leading directories.Junio C Hamano
The function write_one_ref() is passed the list of refs received from the other end, which was obtained by directory traversal under $GIT_DIR/refs; this can contain paths other than what git-init-db prepares and would fail to clone when there is such. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-06[PATCH] sha1_file.c;prepare_packed_git_one() - fix DIR leakJunio C Hamano
The function calls opendir() without a matching closedir(). Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-06Fix up path-cleanup in git_path() properlyLinus Torvalds
GIT_DIR=. ends up being what some of the pack senders use, and we sometimes messed up when cleaning up the path, ie a ".//HEAD" was cleaned up into "/HEAD", not "HEAD" like it should be. We should do some other cleanup, and probably also verify that symlinks don't point to outside the git area.
2005-07-05Add "git_path()" and "head_ref()" helper functions.Linus Torvalds
"git_path()" returns a static pathname pointer into the git directory using a printf-like format specifier. "head_ref()" works like "for_each_ref()", except for just the HEAD.
2005-07-03Add "has_sha1_pack()" function to query whether the object is available in a ↵Linus Torvalds
pack We'll want this for incremental packing.
2005-07-03Fix sparse warnings.Linus Torvalds
Mainly making a lot of local functions and variables be marked "static", but there was a "zero as NULL" warning in there too.
2005-07-03Avoid gcc warnings in sha1_file.cLinus Torvalds
A couple of bogus "might be used undefined" warnings are avoided by moving the initializations unnecessarily early.
2005-07-01[PATCH] Show more details of packfile with verify-pack -v.Junio C Hamano
This implements show_pack_info() function used in verify-pack command when -v flag is used to obtain something like unpack-objects used to give when it was first written. It shows the following for each non-deltified object found in the pack: SHA1 type size offset For deltified objects, it shows this instead: SHA1 type size offset depth base_sha1 In order to get the output in the order that appear in the pack file for debugging purposes, you can do this: $ git-verify-pack -v packfile | sort -n -k 4,4 Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-01[PATCH] verify-pack updates.Junio C Hamano
Nico pointed out that having verify_pack.c and verify-pack.c was confusing. Rename verify_pack.c to pack-check.c as suggested, and enhances the verification done quite a bit. - Built-in sha1_file unpacking knows that a base object of a deltified object _must_ be in the same pack, and takes advantage of that fact. - Earlier verify-pack command only checked the SHA1 sum for the entire pack file and did not look into its contents. It now checks everything idx file claims to have unpacks correctly. - It now has a hook to give more detailed information for objects contained in the pack under -v flag. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-07-01[PATCH] Avoid unnecessarily inflating and interpreting deltaJunio C Hamano
This teaches packed_delta_info() that it only needs to look at the type of the base object to figure out both type and size of a deltified object. This saves quite a many calls to inflate() when dealing with a deep delta chain. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-29[PATCH] Add git-verify-pack command.Junio C Hamano
Given a list of <pack>.idx files, this command validates the index file and the corresponding .pack file for consistency. This patch also uses the same validation mechanism in fsck-cache when the --full flag is used. During normal operation, sha1_file.c verifies that a given .idx file matches the .pack file by comparing the SHA1 checksum stored in .idx file and .pack file as a minimum sanity check. We may further want to check the pack signature and version when we map the pack, but that would be a separate patch. Earlier, errors to map a pack file was not flagged fatal but led to a random fatal error later. This version explicitly die()s when such an error is detected. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-29[PATCH] Fixlets on top of Nico's clean-up.Junio C Hamano
If we prefer 0 as maxsize for diff_delta() to say "unlimited", let's be consistent about it. This patch also fixes type mismatch in a call to get_delta_hdr_size() from packed_delta_info(). Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-29[PATCH] assorted delta code cleanupNicolas Pitre
This is a wrap-up patch including all the cleanups I've done to the delta code and its usage. The most important change is the factorization of the delta header handling code. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-29Fix packed_delta_info() that was broken by the delta header packing changeLinus Torvalds
Pointed out by Junio.
2005-06-29Make git pack files use little-endian size encodingLinus Torvalds
This makes it match the new delta encoding, and admittedly makes the code easier to follow. This also updates the PACK file version to 2, since this (and the delta encoding change in the previous commit) are incompatible with the old format.
2005-06-28Merge fighting fsck-cache updates from JunioLinus Torvalds
It's just easier to let git help out with the merge than it is to try to fix up the diffs.
2005-06-28[PATCH] Expose packed_git and alt_odb.Junio C Hamano
The commands git-fsck-cache and probably git-*-pull needs to have a way to enumerate objects contained in packed GIT archives and alternate object pools. This commit exposes the data structure used to keep track of them from sha1_file.c, and adds a couple of accessor interface functions for use by the enhanced git-fsck-cache command. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-28[PATCH] Bugfix: initialize pack_base to NULL.Junio C Hamano
This was causing random segfaults, because use_packed_git() got confused by random garbage there. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-28Change pack file format. Hopefully for the last time.Linus Torvalds
This also adds a header with a signature, version info, and the number of objects to the pack file. It also encodes the file length and type more efficiently.
2005-06-28Teach packing about "tag" objectsLinus Torvalds
(And teach sha1_file and unpack-object know how to unpack them too, of course)
2005-06-28[PATCH] Obtain sha1_file_info() for deltified pack entry properly.Junio C Hamano
The initial one was not doing enough to figure things out without uncompressing too much. It also fixes a potential segfault resulting from missing use_packed_git() call. We would need to introduce unuse_packed_git() call and do proper use counting to figure out when it is safe to unmap, but currently we do not unmap packed file yet. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-28[PATCH] Skip writing out sha1 files for objects in packed git.Junio C Hamano
Now, there's still a misfeature there, which is that when you create a new object, it doesn't check whether that object already exists in the pack-file, so you'll end up with a few recent objects that you really don't need (notably tree objects), and this patch fixes it. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-27[PATCH] Teach read_sha1_file() and friends about packed git object store.Junio C Hamano
GIT_OBJECT_DIRECTORY and GIT_ALTERNATE_OBJECT_DIRECTORIES can have the "pack" subdirectory that houses "packed GIT" files produced by git-pack-objects (e.g. .git/objects/pack/foo.pack and .git/objects/pack/foo.idx; always store them as pairs). The following functions in sha1_file.c can then read object contents from such packed file: - sha1_object_info() - has_sha1_file() - read_sha1_file() Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-27[PATCH] Enhance sha1_file_size() into sha1_object_info()Junio C Hamano
This lets us eliminate one use of map_sha1_file() outside sha1_file.c, to bring us one step closer to the packed GIT. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-27[PATCH] Remove "delta" object representation.Junio C Hamano
Packed delta files created by git-pack-objects seems to be the way to go, and existing "delta" object handling code has exposed the object representation details to too many places. Remove it while we refactor code to come up with a proper interface in sha1_file.c. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-21[PATCH] Fix several gcc4 signedness warningsMika Kukkonen
Here is a patch that fixes several gcc4 warnings about different signedness, all between char and unsigned char. I tried to keep the patch minimal so resertod to casts in three places. Signed-off-by: Mika Kukkonen <mikukkon@iki.fi> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-08[PATCH] Anal retentive 'const unsigned char *sha1'Jason McMullan
Make 'sha1' parameters const where possible Signed-off-by: Jason McMullan <jason.mcmullan@timesys.com> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-07[PATCH] Operations on refsDaniel Barkalow
This patch adds code to read a hash out of a specified file under {GIT_DIR}/refs/, and to write such files atomically and optionally with an compare and lock. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-02[PATCH] Find size of SHA1 object without inflating everything.Junio C Hamano
This adds sha1_file_size() helper function and uses it in the rename/copy similarity estimator. The helper function handles deltified object as well. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-02[PATCH] Handle deltified object correctly in git-*-pull family.Junio C Hamano
When a remote repository is deltified, we need to get the objects that a deltified object we want to obtain is based upon. The initial parts of each retrieved SHA1 file is inflated and inspected to see if it is deltified, and its base object is asked from the remote side when it is. Since this partial inflation and inspection has a small performance hit, it can optionally be skipped by giving -d flag to git-*-pull commands. This flag should be used only when the remote repository is known to have no deltified objects. Rsync transport does not have this problem since it fetches everything the remote side has. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-06-02Split up unpack_sha1_file() some moreLinus Torvalds
Make a separate helper for parsing the header of an object file (really carefully) and for unpacking the rest. This means that anybody who uses the "unpack_sha1_header()" interface can easily look at the header and decide to unpack the rest too, without doing any extra work.
2005-06-02Add "unpack_sha1_header()" helper functionLinus Torvalds
It's for people who aren't necessarily interested in the whole unpacked file, but do want to know the header information (size, type, etc..) For example, the delta code can use this to figure out whether an object is already a delta object, and what it is a delta against, without actually bothering to unpack all of the actual data in the delta.
2005-05-26unpack_sha1_file: zero-pad the unpacked object.Linus Torvalds
This makes them easier to parse without having to worry about running off the end, and allows us to treat commits as normal strings.
2005-05-22Include file cleanups..Linus Torvalds
Add <limits.h> to the include files handled by "cache.h", and remove extraneous #include directives from various .c files. The rule is that "cache.h" gets all the basic stuff, so that we'll have as few system dependencies as possible.
2005-05-20[PATCH] delta readNicolas Pitre
This makes the core code aware of delta objects and undeltafy them as needed. The convention is to use read_sha1_file() to have undeltafication done automatically (most users do that already so this is transparent). If the delta object itself has to be accessed then it must be done through map_sha1_file() and unpack_sha1_file(). In that context mktag.c has been switched to read_sha1_file() as there is no reason to do the full map+unpack manually. Signed-off-by: Nicolas Pitre <nico@cam.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>