aboutsummaryrefslogtreecommitdiff
path: root/sha1_file.c
Commit message (Collapse)AuthorAge
* Create object subdirectories on demandLinus Torvalds2005-10-08
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This makes it possible to have a "sparse" git object subdirectory structure, something that has become much more attractive now that people use pack-files all the time. As a result of pack-files, a git object directory doesn't necessarily have any individual objects lying around, and in that case it's just wasting space to keep the empty first-level object directories around: on many filesystems the 256 empty directories will be aboue 1MB of diskspace. Even more importantly, after you re-pack a project that _used_ to be unpacked, you could be left with huge directories that no longer contain anything, but that waste space and take time to look through. With this change, "git prune-packed" can just do an rmdir() on the directories, and they'll get removed if empty, and re-created on demand. This patch also tries to fix up "write_sha1_from_fd()" to use the new common infrastructure for creating the object files, closing a hole where we might otherwise leave half-written objects in the object database. [jc: I unoptimized the part that really removes the fan-out directories to ease transition. init-db still wastes 1MB of diskspace to hold 256 empty fan-outs, and prune-packed rmdir()'s the grown but empty directories, but runs mkdir() immediately after that -- reducing the saving from 150KB to 146KB. These parts will be re-introduced when everybody has the on-demand capability.] Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Show original and resulting blob object info in diff output.Junio C Hamano2005-10-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds more cruft to diff --git header to record the blob SHA1 and the mode the patch/diff is intended to be applied against, to help the receiving end fall back on a three-way merge. The new header looks like this: diff --git a/apply.c b/apply.c index 7be5041..8366082 100644 --- a/apply.c +++ b/apply.c @@ -14,6 +14,7 @@ // files that are being modified, but doesn't apply the patch // --stat does just a diffstat, and doesn't actually apply +// --show-index-info shows the old and new index info for... ... Upon receiving such a patch, if the patch did not apply cleanly to the target tree, the recipient can try to find the matching old objects in her object database and create a temporary tree, apply the patch to that temporary tree, and attempt a 3-way merge between the patched temporary tree and the target tree using the original temporary tree as the common ancestor. The patch lifts the code to compute the hash for an on-filesystem object from update-index.c and makes it available to the diff output routine. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Consolidate null_sha1[].Junio C Hamano2005-09-30
| | | | Signed-off-by: Junio C Hamano <junio@twinsun.com>
* Tell which packfile is corrupt when we die.Junio C Hamano2005-09-30
| | | | | | | The core part detected and died upon seeing a corrupted packfile, but did not help the user by telling which packfile is corrupt and how. Signed-off-by: Junio C Hamano <junkio@cox.net>
* [PATCH] Provide access to git_dir through get_git_dir().Sven Verdoolaege2005-09-27
| | | | | Signed-off-by: Sven Verdoolaege <skimo@kotnet.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* [PATCH] Define relative .git/objects/info/alternates semantics.Junio C Hamano2005-09-13
| | | | | | | | | | | | | | | | | | | | | | | | | | An entry in the alternates file can name a directory relative to the object store it describes. A typical linux-2.6 maintainer repository would have "../../../torvalds/linux-2.6.git/objects" there, because the subsystem maintainer object store would live in /pub/scm/linux/kernel/git/$u/$system.git/objects/ and the object store of Linus tree is in /pub/scm/linux/kernel/git/torvalds/linux-2.6.git/objects/ This unfortunately is different from GIT_ALTERNATE_OBJECT_DIRECTORIES which is relative to the cwd of the running process, but there is no way to make it consistent with the behaviour of the environment variable. The process typically is run in $system.git/ directory for a naked repository, or one level up for a repository with a working tree, so we just define it to be relative to the objects/ directory to be different from either ;-). Later, the dumb transport could be updated to read from info/alternates and make requests for the repository the repository borrows from. Signed-off-by: Junio C Hamano <junkio@cox.net>
* Retire support for old environment variables.Junio C Hamano2005-09-09
| | | | | | | | | | We have deprecated the old environment variable names for quite a while and now it's time to remove them. Gone are: SHA1_FILE_DIRECTORIES AUTHOR_DATE AUTHOR_EMAIL AUTHOR_NAME COMMIT_AUTHOR_EMAIL COMMIT_AUTHOR_NAME SHA1_FILE_DIRECTORY Signed-off-by: Junio C Hamano <junkio@cox.net>
* [PATCH] Possible cleanups for local-pull.cPeter Hagervall2005-09-04
| | | | | | | | | | Hi. This patch contains the following possible cleanups: * Make some needlessly global functions in local-pull.c static * Change 'char *' to 'const char *' where appropriate Signed-off-by: Peter Hagervall <hager@cs.umu.se> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Fix ?: statements.Jason Riedy2005-08-23
| | | | | | | | | Omitting the first branch in ?: is a GNU extension. Cute, but not supported by other compilers. Replaced mostly by explicit tests. Calls to getenv() simply are repeated on non-GNU compilers. Signed-off-by: Jason Riedy <ejr@cs.berkeley.edu>
* Use LF and allow comments in objects/info/alternates file.Junio C Hamano2005-08-16
| | | | | | | | | Yes, using the same format for the file and the environment variable was a big mistake. This uses LF as the path separator, and allows lines that begin with '#' to be comments. ':' is no longer a separator in objects/info/alternates file. Signed-off-by: Junio C Hamano <junkio@cox.net>
* [PATCH] Add function to read an index file from an arbitrary filename.Daniel Barkalow2005-08-16
| | | | | | | | Note that the pack file has to be in the usual location if it gets installed later. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
* Alternate object pool mechanism updates.Junio C Hamano2005-08-15
| | | | | | | | | | | | | | | | 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>
* [PATCH] Warning fix for gcc 4Pavel Roskin2005-08-09
| | | | | | | | | | | 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>
* [PATCH] Plug memory leak in write_sha1_to_fd()Sergey Vlasov2005-08-08
| | | | | | | | | | | | 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>
* [PATCH] Plug memory leak in read_object_with_reference()Sergey Vlasov2005-08-08
| | | | | | | | 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>
* Update get_sha1() to grok extended format.Junio C Hamano2005-08-05
| | | | | | | | | | | | | 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>
* [PATCH] Parallelize pulling by sshbarkalow@iabervon.org2005-08-02
| | | | | | | | | | | | | | 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>
* [PATCH] Functions for managing the set of packs the library is using ↵barkalow@iabervon.org2005-07-31
| | | | | | | | | | | (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>
* Teach parse_commit_buffer about grafting.Junio C Hamano2005-07-31
| | | | | | | | | | | | | 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>
* [PATCH] mmap error handlingPavel Roskin2005-07-29
| | | | | | | | | | | | | | | | | | 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>
* [PATCH] Check packs and then files.Junio C Hamano2005-07-11
| | | | | | | | | | | | | 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>
* Avoid signedness warnings in sha1_file.cLinus Torvalds2005-07-10
| | | | | Very irritating. But "snprintf()" wants "char *", and zlib wants "unsigned char *".
* [PATCH] Remove map_sha1_fileDaniel Barkalow2005-07-10
| | | | | | | Remove map_sha1_file(), now unused. Signed-off-by: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
* [PATCH] write_sha1_to_fd()Daniel Barkalow2005-07-10
| | | | | | | | 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>
* [PATCH] Expose object ID computation functions.Bryan Larsen2005-07-08
| | | | | | | | | | | | | | 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>
* Add "mkpath()" helper functionLinus Torvalds2005-07-08
| | | | I'm bored with doing it by hand all the time.
* [PATCH] clone-pack.c:write_one_ref() - Create leading directories.Junio C Hamano2005-07-06
| | | | | | | | | | | 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>
* [PATCH] sha1_file.c;prepare_packed_git_one() - fix DIR leakJunio C Hamano2005-07-06
| | | | | | | 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>
* Fix up path-cleanup in git_path() properlyLinus Torvalds2005-07-05
| | | | | | | | | 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.
* Add "git_path()" and "head_ref()" helper functions.Linus Torvalds2005-07-05
| | | | | | | "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.
* Add "has_sha1_pack()" function to query whether the object is available in a ↵Linus Torvalds2005-07-03
| | | | | | pack We'll want this for incremental packing.
* Fix sparse warnings.Linus Torvalds2005-07-03
| | | | | Mainly making a lot of local functions and variables be marked "static", but there was a "zero as NULL" warning in there too.
* Avoid gcc warnings in sha1_file.cLinus Torvalds2005-07-03
| | | | | A couple of bogus "might be used undefined" warnings are avoided by moving the initializations unnecessarily early.
* [PATCH] Show more details of packfile with verify-pack -v.Junio C Hamano2005-06-30
| | | | | | | | | | | | | | | | | | | | | | | 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>
* [PATCH] verify-pack updates.Junio C Hamano2005-06-30
| | | | | | | | | | | | | | | | | | | | 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>
* [PATCH] Avoid unnecessarily inflating and interpreting deltaJunio C Hamano2005-06-30
| | | | | | | | | | 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>
* [PATCH] Add git-verify-pack command.Junio C Hamano2005-06-29
| | | | | | | | | | | | | | | | | | | | | 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>
* [PATCH] Fixlets on top of Nico's clean-up.Junio C Hamano2005-06-29
| | | | | | | | | | | 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>
* [PATCH] assorted delta code cleanupNicolas Pitre2005-06-29
| | | | | | | | | 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>
* Fix packed_delta_info() that was broken by the delta header packing changeLinus Torvalds2005-06-28
| | | | Pointed out by Junio.
* Make git pack files use little-endian size encodingLinus Torvalds2005-06-28
| | | | | | | | | 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.
* Merge fighting fsck-cache updates from JunioLinus Torvalds2005-06-28
|\ | | | | | | | | It's just easier to let git help out with the merge than it is to try to fix up the diffs.
| * [PATCH] Expose packed_git and alt_odb.Junio C Hamano2005-06-28
| | | | | | | | | | | | | | | | | | | | | | 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>
* | [PATCH] Bugfix: initialize pack_base to NULL.Junio C Hamano2005-06-28
| | | | | | | | | | | | | | | | 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>
* | Change pack file format. Hopefully for the last time.Linus Torvalds2005-06-28
|/ | | | | | 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.
* Teach packing about "tag" objectsLinus Torvalds2005-06-28
| | | | | (And teach sha1_file and unpack-object know how to unpack them too, of course)
* [PATCH] Obtain sha1_file_info() for deltified pack entry properly.Junio C Hamano2005-06-28
| | | | | | | | | | | | | 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>
* [PATCH] Skip writing out sha1 files for objects in packed git.Junio C Hamano2005-06-27
| | | | | | | | | | | 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>
* [PATCH] Teach read_sha1_file() and friends about packed git object store.Junio C Hamano2005-06-27
| | | | | | | | | | | | | | | | 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>
* [PATCH] Enhance sha1_file_size() into sha1_object_info()Junio C Hamano2005-06-27
| | | | | | | | 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>