Commit Graph

2112 Commits

Author SHA1 Message Date
Brandon Casey
54ccc71786 examples/general.c: update for recent API renaming of git_config_get_int
git_config_get_int --> git_config_get_int32
2011-11-05 18:01:32 -05:00
schu
ec9079443c test_helpers: do not rely on assert
The functions loose_object_mode and loose_object_dir_mode call stat
inside an assert statement which isn't evaluated when compiling in
Release mode (NDEBUG) and leads to failing tests. Replace it.

Signed-off-by: schu <schu-github@schulog.org>
2011-10-30 13:48:00 +01:00
Vicent Martí
d3104fa0a3 Merge pull request #468 from nulltoken/ntk/fix/issue-465
Status: fix segfault (#465) and order issues
2011-10-29 14:06:36 -07:00
nulltoken
e3baa3ccf3 status: Fix a sorting issue in the treewalker
This ensures that entries from the working directory are retrieved according to the following rules:

 - The file "subdir" should appear before the file "subdir.txt"
 - The folder "subdir" should appear after the file "subdir.txt"
2011-10-29 22:42:37 +02:00
nulltoken
a1bd78ea29 status: Add a file in the test repository to cover the correct sorting of entries when the working folder is being read
In this case, "subdir.txt" should be listed before the "subdir" directory.
2011-10-29 22:05:56 +02:00
nulltoken
d1db74bf57 status: Prevent segfaulting when determining the status of a repository
Fixes #465
2011-10-29 22:05:56 +02:00
Vicent Martí
89fb8f025a Merge pull request #456 from brodie/perm-fixes
Create objects, indexes, and directories with the right file permissions
2011-10-28 19:04:23 -07:00
Vicent Marti
3286c408ec global: Properly use git__ memory wrappers
Ensure that all memory related functions (malloc, calloc, strdup, free,
etc) are using their respective `git__` wrappers.
2011-10-28 19:02:36 -07:00
Vicent Marti
da37654d04 tree: Add traversal in post-order 2011-10-27 22:33:31 -07:00
Vicent Marti
4849dbb8b9 Merge branch 'status' of https://github.com/carlosmn/libgit2 into development 2011-10-27 17:54:17 -07:00
Carlos Martín Nieto
1ca715e07a status: move GIT_STATUS_PATH_* into an enum
Their actual values have no meaning, so pack them in an enum.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-27 16:13:09 -07:00
Carlos Martín Nieto
68a26dfa7c status: reorder retrieve_head_tree error checks
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-27 16:13:09 -07:00
Carlos Martín Nieto
c2892d61ac status: remove git_tree_entry_bypos
The only caller has been changed to treat a NULL tree as a special
case and use the existing git_tree_entry_byindex.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-27 16:13:09 -07:00
Carlos Martín Nieto
899cb7a876 status: remove git_index_entry_bypos
This function is already implemented (better) as git_index_get. Change
the only caller to use that function.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-27 16:13:09 -07:00
Vicent Martí
a2366c949d Merge pull request #467 from oleganza/oa-config-parse-fix
Fixed crash in config parser when empty value is encountered.
2011-10-27 15:33:53 -07:00
Oleg Andreev
9f861826be Fixed crash in config parser when empty value is encountered.
Example:

key1 = value1
key2 =

In this config the value will be a bad pointer which config object will attempt to free() causing a crash.
2011-10-27 16:45:44 +02:00
Vicent Martí
d533c8885b Merge pull request #463 from schu/tests-clay-object-raw
tests-clay: move t01-rawobj.c to clay
2011-10-26 19:25:18 -07:00
Vicent Marti
11d51ca631 windows: Add support for non-UTF codepages
Our previous assumption that all paths in Windows are encoded in UTF-8
is rather weak, specially when considering that Git is
encoding-agnostic.

These set of functions allow the user to change the library's active
codepage globally, so it is possible to access paths and files on all
international versions of Windows.

Note that the default encoding here is UTF-8 because we assume that 99%
of all Git repositories will be in UTF-8.

Also, if you use non-ascii characters in paths, anywhere, please burn on
a fire.
2011-10-26 17:43:44 -07:00
schu
9ff46db911 tests-clay: move t01-rawobj.c to clay
Signed-off-by: schu <schu-github@schulog.org>
2011-10-24 23:51:28 +02:00
Vicent Martí
c2fbe42346 Merge pull request #464 from rtyley/development
Tolerate zlib deflation with window size < 32Kb
2011-10-24 14:43:18 -07:00
Roberto Tyley
c51065e3e9 Tolerate zlib deflation with window size < 32Kb
libgit2 currently identifies loose objects as corrupt if they've been
deflated using a window size less than 32Kb, because the
is_zlib_compressed_data() function doesn't recognise the header
byte as a zlib header. This patch makes the method tolerant of
all valid window sizes (15-bit to 8-bit) - but doesn't sacrifice
it's accuracy in distingushing the standard loose-object format
from the experimental (now abandoned) format. It's based on a patch
which has been merged into C-Git master branch:

https://github.com/git/git/commit/7f684a2aff636f44a506

On memory constrained systems zlib may use a much smaller window
size - working on Agit, I found that Android uses a 4KB window;
giving a header byte of 0x48, not 0x78. Consequently all loose
objects generated by the Android platform appear 'corrupt' :(

It might appear that this patch changes isStandardFormat() to the
point where it could incorrectly identify the experimental format as
the standard one, but the two criteria (bitmask & checksum) can only
give a false result for an experimental object where both of the
following are true:

1) object size is exactly 8 bytes when uncompressed (bitmask)
2) [single-byte in-pack git type&size header] * 256
   + [1st byte of the following zlib header] % 31 = 0 (checksum)

As it happens, for all possible combinations of valid object type
(1-4) and window bits (0-7), the only time when the checksum will be
divisible by 31 is for 0x1838 - ie object type *1*, a Commit - which,
due the fields all Commit objects must contain, could never be as
small as 8 bytes in size.

Given this, the combination of the two criteria (bitmask & checksum)
always correctly determines the buffer format, and is more tolerant
than the previous version.

References:

Android uses a 4KB window for deflation:
http://android.git.kernel.org/?p=platform/libcore.git;a=blob;f=luni/src/main/native/java_util_zip_Deflater.cpp;h=c0b2feff196e63a7b85d97cf9ae5bb258

Code snippet searching for false positives with the zlib checksum:
https://gist.github.com/1118177

Change-Id: Ifd84cd2bd6b46f087c9984fb4cbd8309f483dec0
2011-10-24 14:39:03 -07:00
Carlos Martín Nieto
4ce16ed82f CMake: use -O0 in debug mode
Otherwise, GCC optimizes variables away and gdb can't tell us what's
in them.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-22 12:26:56 +02:00
Vicent Marti
28c1451a7c tree: Fix name lookups once and for all
Double-pass binary search. Jeez.
2011-10-20 02:40:14 +02:00
Vicent Marti
8cf2de078d tree: Fix lookups by entry name 2011-10-19 01:34:42 +02:00
Carlos Martín Nieto
5fa1bed0f7 mwindow: close LRU window properly
Remove a wrong call to git_mwindow_close which caused a segfault if it
ever did run. In that same piece of code, if the LRU was from the
first wiindow in the list in a different file, we didn't update that
list, so the first element had been freed.

Fix these two issues.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-15 23:25:48 +02:00
Vicent Martí
a014a083d9 Merge pull request #459 from brodie/test-improvements
tests: propagate errors from open_temp_repo() instead of exiting
2011-10-14 16:32:00 -07:00
Brodie Rao
252840a59f tests: propagate errors from open_temp_repo() instead of exiting
This makes it slightly easier to debug test failures when one test
opens a repo, has a failure, and doesn't get a chance to close it for
the next test. Now, instead of getting no feedback, we at least see
test failure information.
2011-10-14 16:20:23 -07:00
Brodie Rao
01ad7b3a9e *: correct and codify various file permissions
The following files now have 0444 permissions:

- loose objects
- pack indexes
- pack files
- packs downloaded by fetch
- packs downloaded by the HTTP transport

And the following files now have 0666 permissions:

- config files
- repository indexes
- reflogs
- refs

This brings libgit2 more in line with Git.

Note that git_filebuf_commit() and git_filebuf_commit_at() have both
gained a new mode parameter.

The latter change fixes an important issue where filebufs created with
GIT_FILEBUF_TEMPORARY received 0600 permissions (due to mkstemp(3)
usage). Now we chmod() the file before renaming it into place.

Tests have been added to confirm that new commit, tag, and tree
objects are created with the right permissions. I don't have access to
Windows, so for now I've guarded the tests with "#ifndef GIT_WIN32".
2011-10-14 16:07:47 -07:00
Brodie Rao
ce8cd006ce fileops/repository: create (most) directories with 0777 permissions
To further match how Git behaves, this change makes most of the
directories libgit2 creates in a git repo have a file mode of
0777. Specifically:

- Intermediate directories created with git_futils_mkpath2file() have
  0777 permissions. This affects odb_loose, reflog, and refs.

- The top level folder for bare repos is created with 0777
  permissions.

- The top level folder for non-bare repos is created with 0755
  permissions.

- /objects/info/, /objects/pack/, /refs/heads/, and /refs/tags/ are
  created with 0777 permissions.

Additionally, the following changes have been made:

- fileops functions that create intermediate directories have grown a
  new dirmode parameter. The only exception to this is filebuf's
  lock_file(), which unconditionally creates intermediate directories
  with 0777 permissions when GIT_FILEBUF_FORCE is set.

- The test runner now sets the umask to 0 before running any
  tests. This ensurses all file mode checks are consistent across
  systems.

- t09-tree.c now does a directory permissions check. I've avoided
  adding this check to other tests that might reuse existing
  directories from the prefabricated test repos. Because they're
  checked into the repo, they have 0755 permissions.

- Other assorted directories created by tests have 0777 permissions.
2011-10-14 16:04:34 -07:00
Brodie Rao
33127043b3 fileops/posix: replace usage of "int mode" with "mode_t mode"
Note: Functions exported from fileops take const mode_t, while the
underlying POSIX wrappers take mode_t.
2011-10-14 15:57:15 -07:00
Vicent Martí
1776f5ab49 Merge pull request #457 from khalsah/makefile-fix
Update Makefile.embed with http-parser dependency
2011-10-13 18:08:19 -07:00
Hargobind S. Khalsa
d42eff0344 Add src/transports to Makefile sources 2011-10-13 19:05:03 -06:00
Hargobind S. Khalsa
7fcddeb68b Update Makefile.embed with http-parser dependency 2011-10-13 18:44:14 -06:00
Vicent Martí
b7e1dd1603 Merge pull request #448 from nulltoken/ntk/topic/treeentry-random-access
Add git_tree_frompath()
2011-10-13 14:54:12 -07:00
nulltoken
3fa735ca3b tree: Add git_tree_frompath() which, given a relative path to a tree entry, retrieves the tree object containing this tree entry 2011-10-13 23:30:07 +02:00
nulltoken
34aff01002 oid: Add git_oid_streq() which checks if an oid and an hex formatted string are equal 2011-10-13 23:15:11 +02:00
nulltoken
a6c0e4d202 Fix minor indentation issues 2011-10-13 22:49:05 +02:00
nulltoken
b3f993e287 Add test commit containing subtrees and files 2011-10-13 22:48:58 +02:00
nulltoken
a41e9f131e Fix compilation error on Windows 2011-10-13 22:48:07 +02:00
Vicent Martí
5c3d5fb018 Merge pull request #454 from brodie/parsing-fixes
Improvements to tag, commit, and signature parsing
2011-10-13 12:16:07 -07:00
Vicent Martí
a3e23a7c0a Merge pull request #455 from brodie/pack-fixes
odb_pack: don't do ambiguity checks for fully qualified SHA1 hashes
2011-10-13 12:01:06 -07:00
Brodie Rao
b2a2702da2 odb_pack: don't do ambiguity checks for fully qualified SHA1 hashes
This makes libgit2 more closely match Git, which only checks for
ambiguous pack entries when given short hashes.

Note that the only time this is ever relevant is when a pack has the
same object more than once (it's happened in the wild, I promise).
2011-10-12 17:34:04 -07:00
Brodie Rao
6f2856f308 signature: don't blow up trying to parse names containing '>'
When trying to find the end of an email, instead of starting at the
beginning of the signature, we start at the end of the name (after the
first '<').

This brings libgit2 more in line with Git's behavior when reading out
existing signatures.

However, note that Git does not allow names like these through the
usual porcelain; instead, it silently strips any '>' characters it
sees.
2011-10-12 16:19:46 -07:00
Brodie Rao
15b0bed2ba tag: allow the tagger field to be missing when parsing tags
Instead of bailing out with an error, this sets tagger to NULL when
the field is missing from the object.

This makes it possible to inspect tags like this one:

http://git.kernel.org/?p=git/git.git;a=tag;h=f25a265a342aed6041ab0cc484224d9ca54b6f41
2011-10-12 16:09:16 -07:00
Brodie Rao
cf7b13f3c3 tag: avoid a double-free when parsing tags without a tagger field
The v0.99 tag in the Git repo triggers this behavior:

http://git.kernel.org/?p=git/git.git;a=tag;h=d6602ec5194c87b0fc87103ca4d67251c76f233a

Ideally, we'd allow the tag to be instantiated even though the tagger
field is missing, but this at the very least prevents libgit2 from
crashing.

To test this bug, a new repository has been added based on the test
branch in testrepo.git. It contains a "e90810b" tag that looks like
this:

    object e90810b8df3e80c413d903f631643c716887138d
    type commit
    tag e90810b

    This is a very simple tag.
2011-10-12 16:06:25 -07:00
Brodie Rao
04f788023f commit: properly parse empty commit messages
This ensures commit->message is always non-NULL, even if the commit
message is empty or consists of only a newline.

One such commit can be found in the wild in the jQuery repository:

25b424134f
2011-10-12 15:14:25 -07:00
Carlos Martín Nieto
3707b331e2 pkt: move the protocol strings to the top of the file
Put them all together so we know where to find them.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-12 21:34:25 +02:00
Carlos Martín Nieto
dfafb03bdc Move the transports to their own directory 2011-10-12 21:34:25 +02:00
Carlos Martín Nieto
8c2528748d net: plug a few memory leaks
Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-12 21:33:19 +02:00
Carlos Martín Nieto
546a3c8f9e http: download pack when fetching
Unfortunately, we can't use the function in fetch.c due to chunked
encoding and keep-alive connections.

Signed-off-by: Carlos Martín Nieto <carlos@cmartin.tk>
2011-10-12 21:33:19 +02:00