summaryrefslogtreecommitdiff
path: root/sha1_file.c
AgeCommit message (Collapse)AuthorFilesLines
2005-05-25unpack_sha1_file: zero-pad the unpacked object.Libravatar Linus Torvalds1-1/+2
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..Libravatar Linus Torvalds1-2/+0
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 readLibravatar Nicolas Pitre1-0/+14
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>
2005-05-20sparse cleanupLibravatar Linus Torvalds1-3/+3
Fix various things that sparse complains about: - use NULL instead of 0 - make sure we declare everything properly, or mark it static - use proper function declarations ("fn(void)" instead of "fn()") Sparse is always right.
2005-05-18[PATCH] Kill a bunch of pointer sign warnings for gcc4Libravatar Brian Gerst1-9/+9
- Raw hashes should be unsigned char. - String functions want signed char. - Hash and compress functions want unsigned char. Signed-off By: Brian Gerst <bgerst@didntduck.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-05-11Merge with http://members.cox.net/junkio/git-jc.gitLibravatar Petr Baudis1-22/+149
2005-05-09Introduce GIT_DIR environment variable.Libravatar Junio C Hamano1-3/+36
During the mailing list discussion on renaming GIT_ environment variables, people felt that having one environment that lets the user (or Porcelain) specify both SHA1_FILE_DIRECTORY (now GIT_OBJECT_DIRECTORY) and GIT_INDEX_FILE for the default layout would be handy. This change introduces GIT_DIR environment variable, from which the defaults for GIT_INDEX_FILE and GIT_OBJECT_DIRECTORY are derived. When GIT_DIR is not defined, it defaults to ".git". GIT_INDEX_FILE defaults to "$GIT_DIR/index" and GIT_OBJECT_DIRECTORY defaults to "$GIT_DIR/objects". Special thanks for ideas and discussions go to Petr Baudis and Daniel Barkalow. Bugs are mine ;-) Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-09Rename environment variables.Libravatar Junio C Hamano1-4/+4
H. Peter Anvin mentioned that using SHA1_whatever as an environment variable name is not nice and we should instead use names starting with "GIT_" prefix to avoid conflicts. Here is what this patch does: * Renames the following environment variables: New name Old Name GIT_AUTHOR_DATE AUTHOR_DATE GIT_AUTHOR_EMAIL AUTHOR_EMAIL GIT_AUTHOR_NAME AUTHOR_NAME GIT_COMMITTER_EMAIL COMMIT_AUTHOR_EMAIL GIT_COMMITTER_NAME COMMIT_AUTHOR_NAME GIT_ALTERNATE_OBJECT_DIRECTORIES SHA1_FILE_DIRECTORIES GIT_OBJECT_DIRECTORY SHA1_FILE_DIRECTORY * Introduces a compatibility macro, gitenv(), which does an getenv() and if it fails calls gitenv_bc(), which in turn picks up the value from old name while giving a warning about using an old name. * Changes all users of the environment variable to fetch environment variable with the new name using gitenv(). * Updates the documentation and scripts shipped with Linus GIT distribution. The transition plan is as follows: * We will keep the backward compatibility list used by gitenv() for now, so the current scripts and user environments continue to work as before. The users will get warnings when they have old name but not new name in their environment to the stderr. * The Porcelain layers should start using new names. However, just in case it ends up calling old Plumbing layer implementation, they should also export old names, taking values from the corresponding new names, during the transition period. * After a transition period, we would drop the compatibility support and drop gitenv(). Revert the callers to directly call getenv() but keep using the new names. The last part is probably optional and the transition duration needs to be set to a reasonable value. Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-08Stylistic fixes to sha1_file.cLibravatar Junio C Hamano1-4/+24
This fixes stylistic problems and one unused variable spotted by Petr Baudis. The buf variable unused in prepare_alt_odb() is gone and the "creepy" function is more heavily documented. Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-08[PATCH] Really *do* nothing in while loopLibravatar Thomas Glanzmann1-1/+1
A deflate loop in sha1_file.c would have /* nothing */ as its body, but the semicolon was missing, so the next command was run. Fortunately the loop went through exactly once so it didn't trigger an actual bug so far. Signed-Off-by: Thomas Glanzmann <sithglan@stud.uni-erlangen.de> Signed-off-by: Petr Baudis <pasky@ucw.cz>
2005-05-07[PATCH] Add #include <limits.h> so that git compiles under SolarisLibravatar Thomas Glanzmann1-0/+1
<JC> Editorial Note. We may want to include standard headers in one of those headers everybody includes, e.g. cache.h, to reduce clutters, but this commit is as Thomas posted to the GIT list. Date: Sat, 7 May 2005 10:41:41 +0200 Signed-off-by: Thomas Glanzmann <sithglan@stud.uni-erlangen.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-07Free compressed buffer after write_sha1_file() is done.Libravatar Junio C Hamano1-0/+1
This does not matter for commands that write just a handful SHA1 files, but is noticeable in git-convert-cache which essentially traverses the entire object database. Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-07Introduce SHA1_FILE_DIRECTORIES to support multiple object databases.Libravatar Junio C Hamano1-19/+91
SHA1_FILE_DIRECTORIES environment variable is a colon separated paths used when looking for SHA1 files not found in the usual place for reading. Creating a new SHA1 file does not use this alternate object database location mechanism. This is useful to archive older, rarely used objects into separate directories. Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-06[PATCH] Remove unused sha1_file_directory variable.Libravatar Junio C Hamano1-2/+0
Now all the users have gone. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-05-03sha1_file: make the new sha1 object writing be coda-friendly.Libravatar Linus Torvalds1-1/+14
Coda doesn't like cross-directory hardlinks. So try to fall back on a plain rename instead.
2005-05-03Improve sha1 object file writing.Libravatar Linus Torvalds1-93/+39
Make it much safer: we write to a temporary file, and then link that temporary file to the final destination. This avoids all the nasty races if several people write the same object at the same time. It should also result in nicer on-disk layout, since it means that objects all get created in the same subdirectory. That makes a lot of block allocation algorithms happier, since the objects will now be allocated from the same zone.
2005-05-01Add git-write-blob.Libravatar Junio C Hamano1-0/+51
A new command, git-write-blob, is introduced. This registers the contents of any file on the filesystem as a blob in the object database and reports its SHA1 to the standard output. To implement it, the patch promotes index_fd() from a static function in update-cache.c to extern and moves it to a library source, sha1_file.c. This command is used to update git-merge-one-file-script so that it does not smudge the work tree. Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-05-01Remove the ugly jit-style parent syntax.Libravatar Linus Torvalds1-44/+0
If somebody wants it later, we can re-do it, but for now we consider it an experiment that wasn't worth it. Git will still honor symbolic names, it just won't look up parents for you. Of course, you can always do it by hand if you want to.
2005-05-01Add "look up parent" logic for the simple names.Libravatar Linus Torvalds1-5/+62
It uses the jit syntax, at least for now. 0-xxxx is the first parent of xxxx, while 1-xxxx is the second, and so on. You can use just "-xxxx" for the first parent, but a lot of commands will think that the initial '-' implies a command line flag.
2005-05-01Add "get_sha1()" helper function.Libravatar Linus Torvalds1-0/+29
This allows the programs to use various simplified versions of the SHA1 names, eg just say "HEAD" for the SHA1 pointed to by the .git/HEAD file etc. For example, this commit has been done with git-commit-tree $(git-write-tree) -p HEAD instead of the traditional "$(cat .git/HEAD)" syntax.
2005-04-28[PATCH] Rename and extend read_tree_with_tree_or_commit_sha1Libravatar Junio C Hamano1-32/+37
This patch renames read_tree_with_tree_or_commit_sha1() to read_object_with_reference() and extends it to automatically dereference not just "commit" objects but "tag" objects. With this patch, you can say e.g.: ls-tree $tag read-tree -m $(merge-base $tag $HEAD) $tag $HEAD diff-cache $tag diff-tree $tag $HEAD Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-04-26[PATCH] introduce xmalloc and xreallocLibravatar Christopher Li1-5/+3
Introduce xmalloc and xrealloc to die gracefully with a descriptive message when out of memory, rather than taking a SIGSEGV. Signed-off-by: Christopher Li<chrislgit@chrisli.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-04-25Fix up the types in write_sha1_fileLibravatar Linus Torvalds1-2/+2
Use "unsigned long" for the size, like we do everywhere else.
2005-04-25Simplify "write_sha1_file()" interfacesLibravatar Linus Torvalds1-7/+20
The write function now adds the header to the file by itself, so there is no reason to duplicate it among all the users any more.
2005-04-24[PATCH] fix segfault in fsck-cacheLibravatar Andreas Gal1-0/+2
Here is how to trigger it: echo blob 100 > .git/objects/00/ae4e8d3208e09f2cf7a38202a126f728cadb49 Then run fsck-cache. It will try to unpack after the header to calculate the hash, inflate returns total_out == 0 and memcpy() dies. The patch below seems to work with ZLIB 1.1 and 1.2. Signed-off-by: Andreas Gal <gal@uci.edu> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-04-23[PATCH] Additional functions for the objects databaseLibravatar Daniel Barkalow1-0/+72
This adds two functions: one to check if an object is present in the local database, and one to add an object to the local database by reading it from a file descriptor and checking its hash. Signed-Off-By: Daniel Barkalow <barkalow@iabervon.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-04-23Use O_NOATIME when opening the sha1 files.Libravatar Linus Torvalds1-3/+26
We really don't care about atime, and it sucks to dirty the inode cache just for it. This is more than a one-liner only because we need to be able to clear the O_NOATIME flag in case some of the objects are owned by others (in which case open will return EPERM), and because not everybody has the O_NOATIME flag.
2005-04-20Fix up some problems from the commit->tree helper patchLibravatar Linus Torvalds1-2/+2
2005-04-20[PATCH] Accept commit in some places when tree is needed.Libravatar Junio C Hamano1-0/+40
This patch implements read_tree_with_tree_or_commit_sha1(), which can be used when you are interested in reading an unpacked raw tree data but you do not know nor care if the SHA1 you obtained your user is a tree ID or a commit ID. Before this function's introduction, you would have called read_sha1_file(), examined its type, parsed it to call read_sha1_file() again if it is a commit, and verified that the resulting object is a tree. Instead, this function does that for you. It returns NULL if the given SHA1 is not either a tree or a commit. Signed-off-by: Junio C Hamano <junkio@cox.net> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-04-20Make "write_sha1_file()" exit early if the file already exists.Libravatar Linus Torvalds1-4/+22
Avoid the compression.
2005-04-20Do SHA1 hash _before_ compression.Libravatar Linus Torvalds1-6/+8
And add a "convert-cache" program to convert from old-style to new-style.
2005-04-18Split up read-cache.c into more logical clumps.Libravatar Linus Torvalds1-0/+247
Do the usage and error reporting in "usage.c", and the sha1 file accesses in "sha1_file.c". Small, nice, easily separated parts. Good.