Commit Graph

5935 Commits

Author SHA1 Message Date
Carlos Martín Nieto
21b1e015a3 Merge pull request #3539 from libgit2/typedef-submodule-cb
Use a typedef for the submodule_foreach callback.
2015-12-08 21:11:58 +01:00
joshaber
eda726cfb5 Use a typedef for the submodule_foreach callback.
This fits with the style for the rest of the project, but more
importantly, makes life easier for bindings authors who auto-generate
code.
2015-12-08 11:34:00 -05:00
Patrick Steinhardt
b057fdef69 index: always queue remove_entry for removal
When replacing an index with a new one, we need to iterate
through all index entries in order to determine which entries are
equal. When it is not possible to re-use old entries for the new
index, we move it into a list of entries that are to be removed
and thus free'd.

When we encounter a non-zero error code, though, we skip adding
the current index entry to the remove-queue. `INSERT_MAP_EX`,
which is the function last run before adding to the remove-queue,
may return a positive non-zero code that indicates what exactly
happened while inserting the element. In this case we skip adding
the entry to the remove-queue but still continue the current
operation, leading to a leak of the current entry.

Fix this by checking for a negative return value instead of a
non-zero one when we want to add the current index entry to the
remove-queue.
2015-12-08 16:29:08 +01:00
Carlos Martín Nieto
fc43646965 tree: mark a tree as already sorted
The trees are sorted on-disk, so we don't have to go over them
again. This cuts almost a fifth of time spent parsing trees.
2015-12-06 23:17:19 +01:00
Edward Thomson
5d1f31c6e6 Merge pull request #3530 from libgit2/cmn/parse-mode
tree: use a specialised mode parse function
2015-12-03 17:42:52 -05:00
Edward Thomson
626f9e243e index: canonicalize inserted paths safely
When adding to the index, we look to see if a portion of the given
path matches a portion of a path in the index.  If so, we will use
the existing path information.  For example, when adding `foo/bar.c`,
if there is an index entry to `FOO/other` and the filesystem is case
insensitive, then we will put `bar.c` into the existing tree instead
of creating a new one with a different case.

Use `strncmp` to do that instead of `memcmp`.  When we `bsearch`
into the index, we locate the position where the new entry would
go.  The index entry at that position does not necessarily have
a relation to the entry we're adding, so we cannot make assumptions
and use `memcmp`.  Instead, compare them as strings.

When canonicalizing paths, we look for the first index entry that
matches a given substring.
2015-12-03 16:27:15 -05:00
Carlos Martín Nieto
0174f21b0a tree: use a specialised mode parse function
Instead of going out to strtol, which is made to parse generic numbers,
copy a parse function from git which is specialised for file modes.
2015-12-02 18:59:58 +01:00
Chris Hescock
efd9ab568b Treat GIT_PASSTHROUGH as though git_cred_acquire_cb isn't set. 2015-12-01 10:54:20 -05:00
Patrick Steinhardt
9487585ddc tree: mark cloned tree entries as un-pooled
When duplicating a `struct git_tree_entry` with
`git_tree_entry_dup` the resulting structure is not allocated
inside a memory pool. As we do a 1:1 copy of the original struct,
though, we also copy the `pooled` field, which is set to `true`
for pooled entries. This results in a huge memory leak as we
never free tree entries that were duplicated from a pooled
tree entry.

Fix this by marking the newly duplicated entry as un-pooled.
2015-12-01 14:25:15 +01:00
Patrick Steinhardt
254e0a33ee diff: include commit message when formatting patch
When formatting a patch as email we do not include the commit's
message in the formatted patch output. Implement this and add a
test that verifies behavior.
2015-12-01 10:12:53 +01:00
Patrick Steinhardt
7f8fe1d45e commit: introduce git_commit_body
It is already possible to get a commit's summary with the
`git_commit_summary` function. It is not possible to get the
remaining part of the commit message, that is the commit
message's body.

Fix this by introducing a new function `git_commit_body`.
2015-12-01 10:07:00 +01:00
Patrick Steinhardt
944dbd1259 blame: use size_t for line counts in git_blame__entry
The `git_blame__entry` struct keeps track of line counts with
`int` fields. Since `int` is only guaranteed to be at least 16
bits we may overflow on certain platforms when line counts exceed
2^15.

Fix this by instead storing line counts in `size_t`.
2015-12-01 09:02:47 +01:00
Patrick Steinhardt
cb1cb24ca9 blame: use size_t for line counts in git_blame_hunk
It is not unreasonable to have versioned files with a line count
exceeding 2^16. Upon blaming such files we fail to correctly keep
track of the lines as `git_blame_hunk` stores them in `uint16_t`
fields.

Fix this by converting the line fields of `git_blame_hunk` to
`size_t`. Add test to verify behavior.
2015-12-01 09:02:47 +01:00
Edward Thomson
337b2b08f4 Merge pull request #3508 from libgit2/cmn/tree-parse-speed
Improvements to tree parsing speed
2015-11-30 20:53:54 -05:00
Patrick Steinhardt
bbd2fa4e70 object: remove unused constant OBJECT_BASE_SIZE 2015-11-30 18:05:27 +01:00
Carlos Martín Nieto
95ae3520c5 tree: ensure the entry filename fits in 16 bits
Return an error in case the length is too big. Also take this
opportunity to have a single allocating function for the size and
overflow logic.
2015-11-30 17:32:18 +01:00
Carlos Martín Nieto
a27f31d8f5 Merge pull request #3513 from ethomson/merge_recursive
Recursive Merge
2015-11-30 04:49:31 +01:00
Carlos Martín Nieto
ee42bb0e3d tree: make path len uint16_t and avoid holes
This reduces the size of the struct from 32 to 26 bytes, and leaves a
single padding byte at the end of the struct (which comes from the
zero-length array).
2015-11-28 19:21:52 +01:00
Carlos Martín Nieto
2580077fc2 tree: calculate the filename length once
We already know the size due to the `memchr()` so use that information
instead of calling `strlen()` on it.
2015-11-28 19:21:52 +01:00
Carlos Martín Nieto
ed970748b6 tree: pool the entry memory allocations
These are rather small allocations, so we end up spending a non-trivial
amount of time asking the OS for memory. Since these entries are tied to
the lifetime of their tree, we can give the tree a pool so we speed up
the allocations.
2015-11-28 19:21:51 +01:00
Carlos Martín Nieto
7132150ddf tree: avoid advancing over the filename multiple times
We've already looked at the filename with `memchr()` and then used
`strlen()` to allocate the entry. We already know how much we have to
advance to get to the object id, so add the filename length instead of
looking at each byte again.
2015-11-28 19:21:51 +01:00
Edward Thomson
5b9c63c3f6 recursive merge: add a recursion limit 2015-11-25 16:25:47 -05:00
Edward Thomson
78859c6344 merge: handle conflicts in recursive base building
When building a recursive merge base, allow conflicts to occur.
Use the file (with conflict markers) as the common ancestor.

The user has already seen and dealt with this conflict by virtue
of having a criss-cross merge.  If they resolved this conflict
identically in both branches, then there will be no conflict in the
result.  This is the best case scenario.

If they did not resolve the conflict identically in the two branches,
then we will generate a new conflict.  If the user is simply using
standard conflict output then the results will be fairly sensible.
But if the user is using a mergetool or using diff3 output, then the
common ancestor will be a conflict file (itself with diff3 output,
haha!).  This is quite terrible, but it matches git's behavior.
2015-11-25 15:38:39 -05:00
Edward Thomson
76ade3a0b8 merge: use annotated commits for recursion
Use annotated commits to act as our virtual bases, instead of regular
commits, to avoid polluting the odb with virtual base commits and
trees.  Instead, build an annotated commit with an index and pointers
to the commits that it was merged from.
2015-11-25 15:38:16 -05:00
Edward Thomson
7730fe8e9c merge: merge annotated commits instead of regular commits 2015-11-25 15:38:03 -05:00
Edward Thomson
3f2bb387a4 merge: octopus merge common ancestors when >2
When there are more than two common ancestors, continue merging the
virtual base with the additional common ancestors, effectively
octopus merging a new virtual base.
2015-11-25 15:37:57 -05:00
Edward Thomson
1b82f7b6a2 merge: compute octopus merge bases 2015-11-25 15:37:45 -05:00
Edward Thomson
75dee59c94 merge: build virtual base of multiple merge bases
When the commits to merge have multiple common ancestors, build a
"virtual" base tree by merging the common ancestors.
2015-11-25 15:37:17 -05:00
Edward Thomson
fa78782f67 merge: rename git_merge_tree_flags_t -> git_merge_flags_t 2015-11-25 15:37:05 -05:00
Edward Thomson
25e84f959a checkout: only consider nsecs when built that way
When examining the working directory and determining whether it's
up-to-date, only consider the nanoseconds in the index entry when
built with `GIT_USE_NSEC`.  This prevents us from believing that
the working directory is always dirty when the index was originally
written with a git client that uinderstands nsecs (like git 2.x).
2015-11-23 15:49:54 -05:00
Edward Thomson
66e4e6da59 Merge pull request #3515 from jacquesg/unsigned-signed
Fix <0 unsigned comparison (stat.st_size should be an off_t)
2015-11-21 11:26:18 -05:00
Jacques Germishuys
e78e8fae5c Make stat.st_size a __int64 not a uint64_t 2015-11-21 14:41:15 +02:00
Edward Thomson
7a612b53cf Merge pull request #3514 from jacquesg/stat-fixes
Stat fixes
2015-11-20 17:52:00 -05:00
Jacques Germishuys
eb11fac629 Detect stat's structure 2015-11-20 21:05:38 +02:00
Carlos Martín Nieto
2ea40fdaac repository: distinguish sequencer cherry-pick and revert
These are not quite like their plain counterparts and require special handling.
2015-11-20 13:19:23 -05:00
Carlos Martín Nieto
69d1494873 Merge pull request #3511 from ethomson/racy_fixes_2
Racy fixes for writing new indexes
2015-11-17 13:21:18 -05:00
Edward Thomson
3eac1037d6 settings: allow users to set PROGRAMDATA
Allow users to set the `git_libgit2_opts` search path for the
`GIT_CONFIG_LEVEL_PROGRAMDATA`.  Convert `GIT_CONFIG_LEVEL_PROGRAMDATA`
to `GIT_SYSDIR_PROGRAMDATA` for setting the configuration.
2015-11-16 23:31:19 -05:00
Edward Thomson
5f32c50683 racy: make git_index_read_index handle raciness
Ensure that `git_index_read_index` clears the uptodate bit on
files that it modifies.

Further, do not propagate the cache from an on-disk index into
another on-disk index.  Although this should not be done, as
`git_index_read_index` is used to bring an in-memory index into
another index (that may or may not be on-disk), ensure that we do
not accidentally bring in these bits when misused.
2015-11-16 22:59:02 -05:00
Edward Thomson
27bc41cf17 index: clear uptodate bit on save
The uptodate bit should have a lifecycle of a single read->write
on the index.  Once the index is written, the files within it should
be scanned for racy timestamps against the new index timestamp.
2015-11-16 22:59:01 -05:00
Edward Thomson
d1101263f7 index: don't detect raciness in uptodate entries
Keep track of entries that we believe are up-to-date, because we
added the index entries since the index was loaded.  This prevents
us from unnecessarily examining files that we wrote during the
cleanup of racy entries (when we smudge racily clean files that have
a timestamp newer than or equal to the index's timestamp when we
read it).  Without keeping track of this, we would examine every
file that we just checked out for raciness, since all their timestamps
would be newer than the index's timestamp.
2015-11-16 22:58:58 -05:00
Edward Thomson
cb0ff012d3 racy-git: do a single index->workdir diff
When examining paths that are racily clean, do a single index->workdir
diff over the entirety of the racily clean files, instead of a diff
per file.
2015-11-16 22:58:57 -05:00
Vicent Marti
7ff7ca623e pool: Never return unaligned buffers 2015-11-13 04:57:19 +01:00
Carlos Martín Nieto
75a0ccf52f Merge pull request #3170 from CmdrMoozy/nsec_fix
git_index_entry__init_from_stat: set nsec fields in entry stats
2015-11-12 19:53:09 +01:00
Carlos Martín Nieto
2c26c8679f Merge pull request #3499 from ethomson/ref_dir_errmsgs
Improve error messages when dirs prevent ref/reflog creation
2015-11-12 19:22:31 +01:00
Carlos Martín Nieto
ecdc04287a Merge pull request #3448 from libgit2/cmn/custom-agent
Support setting custom user-agent
2015-11-12 19:20:36 +01:00
Carlos Martín Nieto
1411cb9eb5 winhttp: use a custom user-agent if the user has set it
We also keep the "git/1.0" prefix in order to maintain compatibility
with hosters.
2015-11-12 17:18:42 +01:00
Carlos Martín Nieto
94bac76c3f http: use a custom user-agent if the user has set it
We still prefix it with "git/1.0" since that's required in many
situations, but we replace the area which mentions libgit2.
2015-11-12 17:18:42 +01:00
Carlos Martín Nieto
de870533e0 settings: add a setter for a custom user-agent 2015-11-12 17:18:42 +01:00
Edward Thomson
0a700ee368 reflog: error when a directory is at reflog path
When a non-empty directory exists and prevents the creation of a
reflog, provide a more informative error message.
2015-11-12 09:39:29 -05:00
Edward Thomson
b46c7ee5e2 refs: complain when a directory exists at ref
When a (non-empty) directory exists at the reference target
location, complain with a more actionable error message.
2015-11-12 09:35:51 -05:00
Carlos Martín Nieto
ad8509ef9f index: overwrite the path when inserting conflicts
When we insert a conflict in a case-insensitive index, accept the
new entry's path as the correct case instead of leaving the path we
already had.

This puts `git_index_conflict_add()` on the same level as
`git_index_add()` in this respect.
2015-11-12 12:11:45 +01:00
Carlos Martín Nieto
16604d7469 index: correctly report which conflict stage has a wrong filemode
When we're at offset 'i', we're dealing with the 'i+1' stage, since
conflicts start at 1.
2015-11-12 12:11:45 +01:00
Carlos Martín Nieto
1c34b717e0 Merge pull request #3498 from ethomson/windows_symlinks
Diff: Honor `core.symlinks=false` and fake symlinks
2015-11-08 05:10:18 +01:00
Carlos Martín Nieto
619488948b Merge pull request #3500 from ethomson/submodules_with_path
Handle submodules with paths in `git_submodule_update`
2015-11-08 04:54:55 +01:00
Edward Thomson
f4b0267122 submodule: reload HEAD/index after reading config
Reload the HEAD and index data for a submodule after reading the
configuration.  The configuration may specify a `path`, so we must
update HEAD and index data with that path in mind.
2015-11-04 16:53:41 -05:00
Edward Thomson
5aa28a8f2d Merge pull request #3465 from libgit2/cmn/tls-register
stream: allow registering a user-provided TLS constructor
2015-11-04 14:16:24 -05:00
Stjepan Rajko
f5f96a23ee Fix git_commit_summary to convert newlines to spaces even after
whitespace.  Collapse spaces around newlines for the summary.
2015-11-03 17:50:55 -05:00
Edward Thomson
ec50b23acc filebuf: detect directories in our way
When creating a filebuf, detect a directory that exists in our
target file location.  This prevents a failure later, when we try
to move the lock file to the destination.
2015-11-03 17:16:51 -05:00
Edward Thomson
6b0fc6abc1 diff: on win32, treat fake "symlinks" specially
On platforms that lack `core.symlinks`, we should not go looking for
symbolic links and `p_readlink` their target.  Instead, we should
examine the file's contents.
2015-11-03 12:06:49 -05:00
Carlos Martín Nieto
7fafde6325 stream: allow registering a user-provided TLS constructor
This allows the application to use their own TLS stream, regardless of
the capabilities of libgit2 itself.
2015-11-03 08:10:29 -08:00
Carlos Martín Nieto
d39f643a0a stream: accept NULL in the free function 2015-11-03 08:10:14 -08:00
Jason Haslam
3138ad9366 Add diff progress callback. 2015-11-02 16:33:58 -05:00
Edward Thomson
db1edf91e9 Merge pull request #3491 from libgit2/cmn/config-checksum
Use checksums to detect config file changes
2015-11-02 15:09:19 -05:00
Vicent Marti
1d0bed9de1 merge-base: Style 2015-11-02 13:47:04 +01:00
Vicent Marti
4cacf5b594 merge-base: Do not read parents from the root 2015-11-02 13:47:04 +01:00
Vicent Marti
136a71f4ee merge-base: Remove redundant merge bases 2015-11-02 13:47:04 +01:00
Carlos Martín Nieto
3547b122b5 filebuf: use an internal buffer
This reduces the chances of a crash in the thread tests. This shouldn't
affect general usage too much, since the main usage of these functions
are to read into an empty buffer.
2015-10-30 21:36:51 +01:00
Carlos Martín Nieto
eb5977991a filebuf: use a checksum to detect file changes
Instead of relying on the size and timestamp, which can hide changes
performed in the same second, hash the file content's when we care about
detecting changes.
2015-10-30 19:49:35 +01:00
Carlos Martín Nieto
d571a54e60 Merge pull request #3493 from ethomson/read_index
index: read_index must update hashes
2015-10-30 19:36:16 +01:00
Carlos Martín Nieto
e0be1d605f git: put NULL check at the top 2015-10-30 18:23:17 +01:00
Edward Thomson
0bf77e3283 index: read_index must update hashes 2015-10-30 13:07:51 -04:00
Carlos Martín Nieto
45d295e08c git: accept NULL as argument to its stream free 2015-10-30 17:51:50 +01:00
Carlos Martín Nieto
fd74bd0842 Merge pull request #3486 from srajko/reflog-segfault-fix
Fix segfault when reading reflog with extra newlines
2015-10-29 20:37:48 +01:00
Stjepan Rajko
335c9e2f45 Prevent segfault when parsing a reflog with oid parse error
Using calloc instead of malloc because the parse error will lead to an immediate free of committer (and its properties, which can segfault on free if undefined - test_refs_reflog_reflog__reading_a_reflog_with_invalid_format_returns_error segfaulted before the fix).

#3458
2015-10-29 11:15:37 -07:00
Edward Thomson
1b4449b40d pool: fix documentation 2015-10-28 10:53:03 -04:00
Vicent Marti
d845abe639 merge: Do not mallocz unecessary entries 2015-10-28 14:49:28 +01:00
Vicent Marti
340b15b71c pool: update comment 2015-10-28 14:31:09 +01:00
Vicent Marti
d3416dfe29 pool: Dot not assume mallocs are zeroed out 2015-10-28 10:50:25 +01:00
Vicent Marti
410efda80b pool: Take into account malloc overhead & pool page size 2015-10-28 10:28:43 +01:00
Vicent Marti
4f971852d5 repository: plug memory leak
cc @carlosmn
2015-10-28 10:15:24 +01:00
Vicent Marti
1e5e02b4f4 pool: Simplify implementation 2015-10-28 10:13:13 +01:00
Vicent Marti
7a02e93e02 merge: Plug memory leak 2015-10-27 22:44:26 +01:00
Vicent Marti
a1f5d691a2 merge: Implement GIT_MERGE_TREE_SKIP_REUC 2015-10-27 22:44:26 +01:00
Vicent Marti
d307a0134b reuc: Be smarter when inserting new REUC entries
Inserting new REUC entries can quickly become pathological given that
each insert unsorts the REUC vector, and both subsequent lookups *and*
insertions will require sorting it again before being successful.

To avoid this, we're switching to `git_vector_insert_sorted`: this keeps
the REUC vector constantly sorted and lets us use the `on_dup` callback
to skip an extra binary search on each insertion.
2015-10-27 22:44:13 +01:00
Carlos Martín Nieto
e324005e8b Merge pull request #3481 from ethomson/xdiff_include
xdiff: reference util.h in parent directory
2015-10-23 15:13:38 +02:00
Edward Thomson
8683d31f08 merge: add GIT_MERGE_TREE_FAIL_ON_CONFLICT
Provide a new merge option, GIT_MERGE_TREE_FAIL_ON_CONFLICT, which
will stop on the first conflict and fail the merge operation with
GIT_EMERGECONFLICT.
2015-10-22 14:55:17 -04:00
Carlos Martín Nieto
dc2cf3eb1a Merge pull request #3480 from ethomson/nsecs
Nanoseconds in the index: ignore for diffing
2015-10-22 18:35:43 +02:00
Edward Thomson
c7b336b084 xdiff: reference util.h in parent directory
Although CMake will correctly configure include directories for us,
some people may use their own build system, and we should reference
`util.h` based on where it actually lives.
2015-10-22 10:29:51 -04:00
Edward Thomson
7499eae98a diff: ignore nsecs when diffing
Although our index contains the literal time present in the index,
we do not read nanoseconds from disk, and thus we should not use
them in any comparisons, lest we always think our working directory
is dirty.

Guard this behind a `GIT_USE_NSECS` for future improvement.
2015-10-22 09:35:47 -04:00
Edward Thomson
44b1e3e390 Merge pull request #3475 from libgit2/cmn/programdata-config
config: add a ProgramData level
2015-10-21 13:43:22 -07:00
Carlos Martín Nieto
8c7c5fa585 config: add a ProgramData level
This is where portable git stores the global configuration which we can
use to adhere to it even though git isn't quite installed on the system.
2015-10-21 15:11:18 +02:00
Vicent Marti
128e94bbbb index: Remove unneeded consts 2015-10-21 12:04:53 +02:00
Vicent Marti
307c4a2b6d signature: Strip crud just like Git does 2015-10-21 11:58:44 +02:00
Edward Thomson
4280fabb9f Merge pull request #3466 from libgit2/cmn/quick-parse-64
revwalk: make commit list use 64 bits for time
2015-10-15 07:10:48 -07:00
Carlos Martín Nieto
8321596a49 Merge pull request #3444 from ethomson/add_preserves_conflict_mode
Preserve modes from a conflict in `git_index_insert`
2015-10-15 12:22:10 +02:00
Vicent Marti
a0a1b19ab0 odb: Prioritize alternate backends
For most real use cases, repositories with alternates use them as main
object storage. Checking the alternate for objects before the main
repository should result in measurable speedups.

Because of this, we're changing the sorting algorithm to prioritize
alternates *in cases where two backends have the same priority*. This
means that the pack backend for the alternate will be checked before the
pack backend for the main repository *but* both of them will be checked
before any loose backends.
2015-10-14 20:53:01 +02:00
Vicent Marti
43820f204e odb: Be smarter when refreshing backends
In the current implementation of ODB backends, each backend is tasked
with refreshing itself after a failed lookup. This is standard Git
behavior: we want to e.g. reload the packfiles on disk in case they have
changed and that's the reason we can't find the object we're looking
for.

This behavior, however, becomes pathological in repositories where
multiple alternates have been loaded. Given that each alternate counts
as a separate backend, a miss in the main repository (which can
potentially be very frequent in cases where object storage comes from
the alternate) will result in refreshing all its packfiles before we
move on to the alternate backend where the object will most likely be
found.

To fix this, the code in `odb.c` has been refactored as to perform the
refresh of all the backends externally, once we've verified that the
object is nowhere to be found.

If the refresh is successful, we then perform the lookup sequentially
through all the backends, skipping the ones that we know for sure
weren't refreshed (because they have no refresh API).

The on-disk pack backend has been adjusted accordingly: it no longer
performs refreshes internally.
2015-10-14 19:24:07 +02:00
Carlos Martín Nieto
5ffdea6f65 revwalk: make commit list use 64 bits for time
We moved the "main" parsing to use 64 bits for the timestamp, but the
quick parsing for the revwalk did not. This means that for large
timestamps we fail to parse the time and thus the walk.

Move this parser to use 64 bits as well.
2015-10-14 16:54:13 +02:00
Edward Thomson
ae195a71ae blame: guard xdiff calls for large files 2015-10-05 22:59:53 +02:00
Edward Thomson
6c014bcc54 diff: don't feed large files to xdiff 2015-10-05 22:59:50 +02:00
Edward Thomson
e43520660c merge_file: treat large files as binary
xdiff craps the bed on large files.  Treat very large files as binary,
so that it doesn't even have to try.

Refactor our merge binary handling to better match git.git, which
looks for a NUL in the first 8000 bytes.
2015-10-05 22:59:46 +02:00
Edward Thomson
46c0e6e3c1 xdiff: convert size variables to size_t 2015-10-05 22:59:41 +02:00
Edward Thomson
4bc9b74c14 GITERR_CHECK_ALLOC_ADDn: multi-arg adders 2015-10-05 22:59:36 +02:00
Axel Rasmussen
28659e50d5 diff: refactor complex timestamp check into its own function 2015-10-01 18:36:10 -07:00
Axel Rasmussen
973a09a4ca index: don't populate nsec values if GIT_USE_NSEC is off 2015-10-01 18:35:21 -07:00
Axel Rasmussen
c7b17fb5cd Merge branch 'master' into nsec_fix_next 2015-10-01 18:01:32 -07:00
Arthur Schreiber
d3b29fb94b refdb and odb backends must provide free function
As refdb and odb backends can be allocated by client code, libgit2
can’t know whether an alternative memory allocator was used, and thus
should not try to call `git__free` on those objects.

Instead, odb and refdb backend implementations must always provide
their own `free` functions to ensure memory gets freed correctly.
2015-10-01 00:50:37 +02:00
Carlos Martín Nieto
ba1a5553e4 Merge pull request #3446 from ethomson/portability
portability: use `CHECK_FUNCTION_EXISTS` for checking whether functions exist...
2015-09-30 17:44:10 +02:00
Edward Thomson
21515f228b index: also try conflict mode when inserting
When we do not trust the on-disk mode, we use the mode of an existing
index entry.  This allows us to preserve executable bits on platforms
that do not honor them on the filesystem.

If there is no stage 0 index entry, also look at conflicts to attempt
to answer this question:  prefer the data from the 'ours' side, then
the 'theirs' side before falling back to the common ancestor.
2015-09-30 09:06:09 -04:00
Edward Thomson
e683d15247 qsort_r/qsort_s: detect their support 2015-09-30 05:49:04 -04:00
Edward Thomson
8649dfd8df p_futimes: support using futimens when available 2015-09-30 05:37:20 -04:00
Carlos Martín Nieto
146a96de82 openssl: don't try to teardown an unconnected SSL context
SSL_shutdown() does not like it when we pass an unitialized ssl context
to it. This means that when we fail to connect to a host, we hide the
error message saying so with OpenSSL's indecipherable error message.
2015-09-30 09:41:25 +02:00
Carlos Martín Nieto
72b7c57093 Merge pull request #3411 from spraints/custom-push-headers
Include custom HTTP headers
2015-09-30 09:17:18 +02:00
Carlos Martín Nieto
5c5df666b0 Plug some leaks 2015-09-27 23:32:20 +02:00
Guille -bisho-
e4b2b919bb Fix binary diffs
git expects an empty line after the binary data:

literal X
...binary data...
<empty_line>

The last literal block of the generated patches were not containing the required empty line. Example:

	diff --git a/binary_file b/binary_file
	index 3f1b3f9098131cfecea4a50ff8afab349ea66d22..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644
	GIT binary patch
	literal 8
	Pc${NM&PdElPvrst3ey5{

	literal 6
	Nc${NM%g@i}0ssZ|0lokL
	diff --git a/binary_file2 b/binary_file2
	index 31be99be19470da4af5b28b21e27896a2f2f9ee2..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644
	GIT binary patch
	literal 8
	Pc${NM&PdElPvrst3ey5{

	literal 13
	Sc${NMEKbZyOexL+Qd|HZV+4u-

git apply of that diff results in:

	error: corrupt binary patch at line 9: diff --git a/binary_file2 b/binary_file2
	fatal: patch with only garbage at line 10

The proper formating is:

	diff --git a/binary_file b/binary_file
	index 3f1b3f9098131cfecea4a50ff8afab349ea66d22..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644
	GIT binary patch
	literal 8
	Pc${NM&PdElPvrst3ey5{

	literal 6
	Nc${NM%g@i}0ssZ|0lokL
	diff --git a/binary_file2 b/binary_file2
	index 31be99be19470da4af5b28b21e27896a2f2f9ee2..86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6 100644
	GIT binary patch
	literal 8
	Pc${NM&PdElPvrst3ey5{

	literal 13
	Sc${NMEKbZyOexL+Qd|HZV+4u-
2015-09-25 10:37:41 -07:00
Matt Burke
d7375662e7 Copy custom_headers insteach of referencing the caller's copy 2015-09-25 10:16:30 -04:00
Matt Burke
d16c1b978f These can be static 2015-09-24 10:32:29 -04:00
Matt Burke
e60db3c79a Revise custom header error messages
If the header doesn't look like a header (e.g. if it doesn't have a ":"
or if it has newlines), report "custom HTTP header '%s' is malformed".

If the header has the same name as a header already set by libgit2 (e.g.
"Host"), report "HTTP header '%s' is already set by libgit2".
2015-09-24 09:24:10 -04:00
Matt Burke
63cc57232c Don't null-check 2015-09-24 09:13:05 -04:00
Matt Burke
098f1e6e25 Use an array of forbidden custom headers 2015-09-24 09:09:48 -04:00
Carlos Martín Nieto
588e28ebfd Merge pull request #3437 from libgit2/cmn/plug-sm
submodule: plug a few leaks
2015-09-24 13:20:48 +02:00
Carlos Martín Nieto
ab8f2c669a submodule: plug a few leaks 2015-09-24 11:37:31 +02:00
Edward Thomson
92a47824d8 win32: propogate filename too long errors 2015-09-22 23:10:56 -04:00
Carlos Martín Nieto
aebddbe736 Merge pull request #3434 from ethomson/reservednames
Win32 Reserved names: don't reserve names outside the working directory
2015-09-21 06:01:03 +02:00
Axel Rasmussen
28cdb3153c apple: work around non-POSIX struct stat on OS X. 2015-09-18 23:56:19 -07:00
Axel Rasmussen
0226f7dd36 diff/index: respect USE_NSEC for racily clean file detection 2015-09-18 23:33:56 -07:00
Axel Rasmussen
360dd4dafd win32: define our own POSIX struct stat, and support USE_NSEC 2015-09-18 23:33:56 -07:00
Axel Rasmussen
e9e6df2c8f cmake: Only provide USE_NSEC if struct stat members are avilable.
This allows us to remove OS checks from source code, instead relying
on CMake to detect whether or not `struct stat` has the nanoseconds
members we rely on.
2015-09-18 23:33:56 -07:00
Axel Rasmussen
0269833f92 settings: expose GIT_USE_NSEC flag in git_libgit2_features 2015-09-18 23:33:56 -07:00
Axel Rasmussen
e7de893ef8 cmake: add USE_NSEC, and only check nanosec m/ctime if enabled 2015-09-18 23:33:55 -07:00
Edward Thomson
538dfc8816 repository: only reserve repo dirs in the workdir
Check that the repository directory is beneath the workdir before
adding it to the list of reserved paths.  If it is not, then there
is no possibility of checking out files into it, and it should not
be a reserved word.

This is a particular problem with submodules where the repo directory
may be in the super's .git directory.
2015-09-18 12:17:57 -04:00
Carlos Martín Nieto
cd677b8fe0 config: buffer comments to match git's variable-adding
When there is a comment at the end of a section, git keeps it there,
while we write the new variable right at the end.

Keep comments buffered and dump them when we're going to output a
variable or section, or reach EOF. This puts us in line with the config
files which git produces.
2015-09-18 12:28:05 +02:00
Edward Thomson
9ce2e7b317 mkdir: cope with root path on win32 2015-09-17 12:48:37 -04:00
Edward Thomson
e164ddb11d win32: return EACCES in p_lstat
Don't coalesce all errors into ENOENT.  At least identify EACCES.
All callers should be handling this case already, as the POSIX
`lstat` will return this.
2015-09-17 12:23:19 -04:00
Edward Thomson
81aaf3704a mkdir: chmod existing paths with GIT_MKDIR_CHMOD 2015-09-17 11:26:38 -04:00
Edward Thomson
e24c60dba4 mkdir: find component paths for mkdir_relative
`git_futils_mkdir` does not blindly call `git_futils_mkdir_relative`.

`git_futils_mkdir_relative` is used when you have some base directory
and want to create some path inside of it, potentially removing blocking
symlinks and files in the process.  This is not suitable for a general
recursive mkdir within the filesystem.

Instead, when `mkdir` is being recursive, locate the first existent
parent directory and use that as the base for `mkdir_relative`.
2015-09-17 10:11:56 -04:00
Edward Thomson
0862ec2eb9 core::mkdir tests: ensure we don't stomp symlinks in mkdir
In `mkdir` and `mkdir_r`, ensure that we don't try to remove symlinks
that are in our way.
2015-09-17 10:11:38 -04:00
Edward Thomson
ac2fba0ecd git_futils_mkdir_*: make a relative-to-base mkdir
Untangle git_futils_mkdir from git_futils_mkdir_ext - the latter
assumes that we own everything beneath the base, as if it were
being called with a base of the repository or working directory,
and is tailored towards checkout and ensuring that there is no
bogosity beneath the base that must be cleaned up.

This is (at best) slow and (at worst) unsafe in the larger context
of a filesystem where we do not own things and cannot do things like
unlink symlinks that are in our way.
2015-09-17 10:00:35 -04:00
Edward Thomson
eea7c85024 checkout: overwrite files with differing modes
When a file exists on disk and we're checking out a file that differs
in executableness, remove the old file.  This allows us to recreate the
new file with p_open, which will take the new mode into account and
handle setting the umask properly.

Remove any notion of chmod'ing existing files, since it is now handled
by the aforementioned removal and was incorrect, as it did not take
umask into account.
2015-09-16 10:33:59 -04:00
Carlos Martín Nieto
b0885675f7 Merge pull request #3425 from ethomson/diriter_root
Handle `git_path_diriter` instances at the drive root on Windows
2015-09-13 23:21:14 +02:00
Edward Thomson
9d905541bf diriter: don't double '/' on posix
The canonical directory path of the root directory of a volume on
POSIX already ends in a slash (eg, `/`).  This is true only at the
root.  Do not add a slash to paths in this case.
2015-09-13 14:18:08 -04:00
Edward Thomson
26d7cf6e57 iterator: loop fs_iterator advance (don't recurse) 2015-09-13 14:07:54 -04:00
Edward Thomson
5a466befaf diriter: don't double '/' on Windows
The canonical directory path of the root directory of a volume on
windows already ends in a slash (eg, `c:/`).  This is true only
at the volume root.  Do not add a slash to paths in this case.
2015-09-13 13:59:41 -04:00
Carlos Martín Nieto
e78aeefa18 Merge pull request #3420 from ethomson/iterator
iterator: advance the tree iterator smartly
2015-09-13 19:43:39 +02:00
Arthur Schreiber
548cb33434 Don't free config in git_transaction_commit.
The config is not owned by the transaction, so please don’t free it.
2015-09-13 16:32:24 +02:00
Carlos Martín Nieto
1e80bf27ea Merge branch 'cmn/ignore-dir-check' 2015-09-13 06:21:18 +02:00
Carlos Martín Nieto
657afd359e ignore: add test and adjust style and comment for dir with wildmatch
The previous commit left the comment referencing the earlier state of
the code, change it to explain the current logic. While here, change the
logic to avoid repeating the copy of the base pattern.
2015-09-13 06:18:49 +02:00
Carlos Martín Nieto
305407e1bb Merge pull request #3370 from libgit2/cmn/submodule-refactor
submodule: refactor to be more explicit in the search
2015-09-13 06:03:12 +02:00
Edward Thomson
8ab4d0e1e1 diff: check pathspec on non-files
When we're not doing pathspec matching, we let the iterator handle
file matching for us.  However, we can only trust the iterator to
return *files* that match the pattern, because the iterator must
return directories that are not strictly in the pathlist, but that
are the parents of files that match the pattern, so that diff can
later recurse into them.

Thus, diff must examine non-files explicitly before including them
in the delta list.
2015-09-12 15:32:18 -04:00
Edward Thomson
220d6f8a10 mempack: expose clear function 2015-09-11 20:06:14 -04:00
Bryan Woods
707f65372b Removing memory leak in mempack's free
It calls git_mempack_reset which reallocates the object array. git_oidmap_free is now called on it explicitly.
2015-09-11 16:35:14 -07:00
Edward Thomson
a1859e21f3 iterator: advance the tree iterator smartly
While advancing the tree iterator, if we advance over things that
we aren't interested in, then call `current`.  Which may *itself*
call advance.

While advancing the tree iterator, if we advance over things that
we aren't interested in, then call `current`.  Which may *itself*
call advance.

While advancing the tree iterator, if we advance over things that
we aren't interested in, then call `current`.  Which may *itself*
call advance.

While advancing the tree iterator, if we advance over things that
we aren't interested in, then call `current`.  Which may *itself*
call advance.

While advancing the tree iterator, if we advance over things that
we aren't interested in, then call `current`.  Which may *itself*
call advance.

Error: stack overflow.
2015-09-11 17:38:28 -04:00
Bryan Woods
8e177b2bb8 Fixing dangling pointers in git_mempack_reset
git_mempack_reset was leaving free'd pointers in the oidmap.
2015-09-10 14:44:52 -07:00
Carlos Martín Nieto
f17525b0ff submodule: refactor to be more explicit in the search
When searching for information about a submdoule, let's be more explicit
in what we expect to find. We currently insert a submodule into the map
and change certain parameters when the config callback gets called.

Switch to asking for the configuration we're interested in, rather than
taking it in an arbitrary order.
2015-09-10 20:36:02 +02:00
Matt Burke
d29c5412aa Avoid segfault when opts == NULL 2015-09-10 14:16:39 -04:00
Matt Burke
3245896bb7 Add a test for custom header validation
Also, *some* custom headers actually are valid.
2015-09-10 13:18:26 -04:00
Matt Burke
66d90e7098 More specific names 2015-09-10 09:14:20 -04:00
Matt Burke
8c876fa91d Validate custom http headers 2015-09-10 09:11:16 -04:00
Matt Burke
35969c6839 Ignore NULL headers 2015-09-10 08:58:23 -04:00
Matt Burke
c49126c87f Accept custom headers for fetch too 2015-09-10 08:34:35 -04:00
Carlos Martín Nieto
6c21211c38 Merge pull request #3379 from theseion/additional_libssh2_error_reporting
report libssh2 error if list of authentication methods can't be retrieved
2015-09-09 13:59:38 +02:00
Matt Burke
c82c2ba60f o i 2015-09-08 14:17:59 -04:00
Matt Burke
80ee25434d Teach winhttp about the extra headers 2015-09-08 14:04:59 -04:00
Matt Burke
276f6aa08d Hook up the custom_headers to the http transport 2015-09-08 14:02:47 -04:00
Matt Burke
4f2b6093a6 Tell the git_transport about the custom_headers 2015-09-08 14:02:33 -04:00
Matt Burke
24f5b4e155 Drop extra_http_headers from git_remote 2015-09-08 14:01:57 -04:00
Carlos Martín Nieto
6d6020defc Merge pull request #3353 from ethomson/wrongcase_add
index: canonicalize directory case when adding
2015-09-08 18:34:51 +02:00
Edward Thomson
2964cbeae1 Merge pull request #3381 from leoyanggit/index_directory_iterator
New feature: add the ablility to iterate through a directory in index
2015-09-08 11:50:08 -04:00
Edward Thomson
a32bc85e84 git_index_add: allow case changing renames
On case insensitive platforms, allow `git_index_add` to provide a new
path for an existing index entry.  Previously, we would maintain the
case in an index entry without the ability to change it (except by
removing an entry and re-adding it.)

Higher-level functions (like `git_index_add_bypath` and
`git_index_add_frombuffers`) continue to keep the old path for easier
usage.
2015-09-08 11:34:00 -04:00
Edward Thomson
280adb3f94 index: canonicalize directory case when adding
On case insensitive systems, when given a user-provided path in the
higher-level index addition functions (eg `git_index_add_bypath` /
`git_index_add_frombuffer`), examine the index to try to match the
given path to an existing directory.

Various mechanisms can cause the on-disk representation of a folder
to not match the representation in HEAD or the index - for example,
a case changing rename of some file `a/file.txt` to `A/file.txt`
will update the paths in the index, but not rename the folder on
disk.

If a user subsequently adds `a/other.txt`, then this should be stored
in the index as `A/other.txt`.
2015-09-08 11:32:40 -04:00
Edward Thomson
e1d27bcaaf Merge pull request #3413 from libgit2/cmn/follow-symlink
filebuf: follow symlinks when creating a lock file
2015-09-06 10:51:29 -04:00
Edward Thomson
9fd4c9c867 Merge pull request #3366 from libgit2/cmn/index-hashmap
Use a hashmap for path-based lookups in the index
2015-09-06 10:50:22 -04:00
Carlos Martín Nieto
d83b2e9f51 filebuf: follow symlinks when creating a lock file
We create a lockfile to update files under GIT_DIR. Sometimes these
files are actually located elsewhere and a symlink takes their place. In
that case we should lock and update the file at its final location
rather than overwrite the symlink.
2015-09-05 16:43:49 +02:00
Leo Yang
c097f7173d New API: git_index_find_prefix
Find the first index entry matching a prefix.
2015-09-04 12:24:36 -04:00
Matt Burke
59d6128e27 Allow the world to set HTTP headers for remotes 2015-09-04 09:36:50 -04:00
Matt Burke
ac9b512789 Pull extra_http_headers from the git_remote 2015-09-04 09:20:45 -04:00
Matt Burke
6af6e69009 Put the extra headers on the connection_data instead 2015-09-04 09:18:32 -04:00
Matt Burke
c3733e5641 Add more headers to HTTP requests 2015-09-04 09:01:30 -04:00
Carlos Martín Nieto
81b7636757 index: put the icase insert choice in macros
This should let us see more clearly what we're doing and avoid the ugly
'if' we need every time we want to interact with the map.
2015-09-04 13:50:25 +02:00
Carlos Martín Nieto
21e7015ca3 Merge pull request #3402 from ethomson/faster_diff
Provide path matching in the iterators (for faster diffs)
2015-09-01 02:26:11 +02:00
Edward Thomson
d53c888069 iterator: saner pathlist matching for idx iterator
Some nicer refactoring for index iteration walks.

The index iterator doesn't binary search through the pathlist space,
since it lacks directory entries, and would have to binary search
each index entry and all its parents (eg, when presented with an index
entry of `foo/bar/file.c`, you would have to look in the pathlist for
`foo/bar/file.c`, `foo/bar` and `foo`).  Since the index entries and the
pathlist are both nicely sorted, we walk the index entries in lockstep
with the pathlist like we do for other iteration/diff/merge walks.
2015-08-31 11:48:06 -04:00
Edward Thomson
56ed415a24 diff: drop FILELIST_MATCH
Now that non-pathspec matching diffs are implemented at the iterator
level, drop `FILELIST_MATCH`ing.
2015-08-30 19:11:31 -04:00
Edward Thomson
7b73739fdd checkout: use pathlist-based iterators 2015-08-30 18:56:39 -04:00
Edward Thomson
1af84271dd tree_iterator: use a pathlist 2015-08-30 18:55:18 -04:00
Edward Thomson
4a0dbeb0d3 diff: use new iterator pathlist handling
When using literal pathspecs in diff with `GIT_DIFF_DISABLE_PATHSPEC_MATCH`
turn on the faster iterator pathlist handling.

Updates iterator pathspecs to include directory prefixes (eg, `foo/`)
for compatibility with `GIT_DIFF_DISABLE_PATHSPEC_MATCH`.
2015-08-30 17:06:26 -04:00
Edward Thomson
aa06ecaf5b Merge pull request #3352 from ethomson/hidden
win32: ensure hidden files can be staged
2015-08-28 19:30:08 -04:00
Edward Thomson
6c9352bf30 iterator: sort subdirs properly with pathlist
When given a pathlist, don't assume that directories sort before
files.  Walk through any list of entries sorting before us to make
sure that we've exhausted all entries that *aren't* directories.

Eg, if we're searching for 'foo/bar', and we have a 'foo.c', keep
advancing the pathlist to keep looking for an entry prefixed with
'foo/'.
2015-08-28 18:40:02 -04:00
Edward Thomson
810cabb9df racy-git: TODO to use improved diffing 2015-08-28 18:39:57 -04:00
Edward Thomson
ef206124de Move filelist into the iterator handling itself. 2015-08-28 18:39:52 -04:00
Edward Thomson
ed1c64464a iterator: use an options struct instead of args 2015-08-28 18:39:47 -04:00
Carlos Martín Nieto
1947592461 Merge pull request #3355 from palmin/palmin/fix-2830
Include the 4 characters not recognised as hex-number in parse_len
2015-08-25 00:39:58 +02:00
Vsevolod Parfenov
6d0defe31c Fix 'If we're dealing with a directory' check 2015-08-24 18:47:48 +03:00
Carlos Martín Nieto
57af0b928e cred: add a free function wrapper 2015-08-19 02:23:18 +02:00
Carlos Martín Nieto
47ed7e5acd transport: provide a way to get the callbacks
libgit2 implementations of smart subtransports can simply reach through
the structure, but external implementors cannot.

Add these two functions as a way for the smart subtransports to get the
callbacks as set by the user.
2015-08-19 02:23:18 +02:00
Leo Yang
26ea28f32b Fix build warning: implicit declaration of function ‘git_transaction_config_new’ 2015-08-17 15:18:47 -04:00
Anders Borum
2d1d2bb59f Include the 4 characters not recognised as hex-number when setting error in parse_len 2015-08-17 07:58:31 +02:00
Edward Thomson
252f86e1be Merge pull request #3377 from dleehr/fix-push-cb
Fix bug in git_smart__push: push_transfer_progress cb is only called at end
2015-08-15 13:46:32 -07:00
Edward Thomson
0ba62ba526 Merge pull request #3384 from libgit2/cmn/regex-nofail
diff: don't error out on an invalid regex
2015-08-15 13:43:46 -07:00
Carlos Martín Nieto
e451cd5c03 diff: don't error out on an invalid regex
When parsing user-provided regex patterns for functions, we must not
fail to provide a diff just because a pattern is not well
formed. Ignore it instead.
2015-08-15 18:46:38 +02:00
Carlos Martín Nieto
11bca2d265 http: propagate the credentials callback's error code
When we ask for credentials, the user may choose to return EUSER to
indicate that an error has happened on its end and it wants to be given
back control.

We must therefore pass that back to the user instead of mentioning that
it was on_headers_complete() that returned an error code. Since we can,
we return the exact error code from the user (other than PASSTHROUGH)
since it doesn't cost anything, though using other error codes aren't
recommended.
2015-08-15 18:15:23 +02:00
Carlos Martín Nieto
755004eaed Merge pull request #3362 from libgit2/cmn/curl-proxyauth-any
curl: use the most secure auth method for the proxy
2015-08-14 22:12:59 +02:00
Carlos Martín Nieto
af1d5239a1 index: keep a hash table as well as a vector of entries
The hash table allows quick lookup of specific paths, while we use the
vector for enumeration.
2015-08-14 21:10:12 +02:00
Carlos Martín Nieto
ac02a69470 Add a hashmap for index entries
They are hashed case-insensitively and take the stage into account.
2015-08-14 21:06:09 +02:00
Max Leske
241414ee33 added a single line of additional error reporting from libssh2 when failing to retrieve the list of authentication methods 2015-08-14 15:42:59 +02:00
Dan Leehr
b0b2c72274 Fix bug in git_smart__push: push_transfer_progress cb is never called
The conditional checked cbs->transfer_progress then used the value in cbs->push_transfer_progress. In both cases it should be push_transfer_progress
2015-08-13 22:52:52 -04:00
Edward Thomson
9f1af7f279 Merge pull request #3168 from libgit2/cmn/config-tx
Locking and transactional/atomic updates for config
2015-08-13 10:22:50 -07:00
Carlos Martín Nieto
5340d63d38 config: perform unlocking via git_transaction
This makes the API for commiting or discarding changes the same as for
references.
2015-08-12 04:09:38 +02:00
Carlos Martín Nieto
36f784b538 config: expose locking via the main API
This lock/unlock pair allows for the cller to lock a configuration file
to avoid concurrent operations.

It also allows for a transactional approach to updating a configuration
file. If multiple updates must be made atomically, they can be done
while the config is locked.
2015-08-12 04:09:38 +02:00
Carlos Martín Nieto
b166703964 config: implement basic transactional support
When a configuration file is locked, any updates made to it will be done
to the in-memory copy of the file. This allows for multiple updates to
happen while we hold the lock, preventing races during complex
config-file manipulation.
2015-08-12 04:09:09 +02:00
Carlos Martín Nieto
3ce9e4d235 config: write the modified file to memory
Instead of writing into the filebuf directly, make the functions to
write the modified config file write into a buffer which can then be
dumped into the lockfile for committing.

This allows us to re-use the same code for modifying a locked
configuration, as we can simply skip the last step of dumping the data
to disk.
2015-08-12 04:09:08 +02:00
Carlos Martín Nieto
e3e017d483 remote: don't confuse tag auto-follow rules with refspec matching
When we're looking to update a tag, we can't stop if the tag auto-follow
rules don't say to update it. The tag might still match the refspec we
were given.
2015-08-11 22:51:53 +02:00
Carlos Martín Nieto
dc0351893a curl: use the most secure auth method for the proxy
When curl uses a proxy, it will only use Basic unless we prompt it to
try to use the most secure on it has available.

This is something which git did recently, and it seems like a good idea.
2015-08-06 13:02:35 +02:00
John Haley
eba784d24d Fix duplicate basenames to support older VS
With Visual Studio versions 2008 and older they ignore the full path to files and only check
the basename of the file to find a collision. Additionally, having duplicate basenames can break
other build tools like GYP.

This fixes https://github.com/libgit2/libgit2/issues/3356
2015-08-05 13:02:58 -07:00
Edward Thomson
ef4857c2b3 errors: tighten up git_error_state OOMs a bit more
When an error state is an OOM, make sure that we treat is specially
and do not try to free it.
2015-08-03 19:44:51 -04:00
Edward Thomson
bdec336301 win32: ensure hidden files can be staged 2015-08-03 18:33:15 -05:00
Edward Thomson
854b701c8a Merge remote-tracking branches 'upstream/pr/3323' and 'upstream/pr/3329' 2015-08-03 15:02:02 -05:00
Michael Procter
0fcfb60dc4 Make giterr_restore aware of g_git_oom_error
Allow restoring a previously captured oom error, by
detecting when the captured message pointer points to the
static oom error message.  This means there is no need
to strdup the message in giterr_detach.
2015-08-03 15:23:17 +01:00
Michael Procter
25dbcf3499 Make giterr_detach no longer public 2015-08-03 15:23:17 +01:00
Michael Procter
c2f17bda07 Ensure static oom error message not detached
Error messages that are detached are assumed to be dynamically
allocated.  Passing a pointer to the static oom error message
can cause an attempt to free the static buffer later.  This change
checks if the oom error message is about to be detached and detaches
a copy instead.
2015-08-03 15:23:17 +01:00
Edward Thomson
69adb781e1 Merge pull request #3325 from libgit2/cmn/filebuf-rename-error
filebuf: remove lockfile upon rename errors
2015-08-03 08:33:53 -05:00
Edward Thomson
0dd8daeada Merge pull request #3344 from libgit2/cmn/add-unreg-submodule
index: stage an unregistered submodule as well
2015-08-03 08:17:47 -05:00
Simon
ac728c2483 Handle ssh:// and git:// urls containing a '~' character.
For such a path '/~/...' the leading '/' is stripped so the server will
get a path starting with '~' and correctly handle it.
2015-08-03 07:38:07 +01:00
Carlos Martín Nieto
ea961abf24 index: stage an unregistered submodule as well
We previously added logic to `_add_bypath()` to update a submodule. Go
further and stage the submodule even if it's not registered to behave
like git.
2015-08-01 20:01:11 +02:00
Carlos Martín Nieto
c400bac4db Merge pull request #3332 from phatblat/ben/doc-warnings
Resolve documentation warnings
2015-08-01 15:38:04 +02:00
Stefan Widgren
c369b37919 Remove extra semicolon outside of a function
Without this change, compiling with gcc and pedantic generates warning:
ISO C does not allow extra ‘;’ outside of a function.
2015-07-31 16:23:11 +02:00
Edward Thomson
9d4b7d2524 Merge pull request #3328 from libgit2/cmn/iterator-skip-diriter
iterator: skip over errors in diriter init
2015-07-29 16:46:47 -05:00
Anders Borum
31a76374a9 case-insensitive check for WWW-Authenticate header
Fixes issue #3338
2015-07-29 22:23:00 +02:00
Ben Chatelain
6d8f3a5162 Better param docs 2015-07-28 08:28:33 -06:00
Carlos Martín Nieto
f85fc367e0 error: store the error messages in a reusable buffer
Instead of allocating a brand new buffer for each error string we want
to store, we can use a per-thread buffer to store the error string and
re-use the underlying storage. We already use the buffer to format the
string, so this mostly makes that more direct.
2015-07-28 09:31:00 +02:00
Ben Chatelain
08afd227df Fix remaining documentation warnings 2015-07-27 18:32:55 -06:00
Carlos Martín Nieto
12786e0f7c iterator: skip over errors in diriter init
An error here will typically mean that the directory was removed between
the time we iterated the parent and the time we wanted to visit it in
which case we should ignore it.

Other kinds of errors such as permissions (or transient errors) also
better dealt with by pretending we didn't see it.
2015-07-26 17:19:22 +02:00
Carlos Martín Nieto
19d9beb7ff filebuf: remove lockfile upon rename errors
When we have an error renaming the lockfile, we need to make sure
that we remove it upon cleanup. For this, we need to keep track of
whether we opened the file and whether the rename succeeded.

If we did create the lockfile but the rename did not succeed, we
remove the lockfile. This won't protect against all errors, but
the most common ones (target file is open) does get handled.
2015-07-24 23:02:11 +02:00
Edward Thomson
2dfd5eae33 Merge pull request #3307 from libgit2/cmn/submodule-backslash
Normalize submodule urls before looking at them
2015-07-24 15:05:16 -05:00
Edward Thomson
759b2230a5 Merge pull request #3303 from libgit2/cmn/index-add-submodule
Allow adding a submodule through git_index_add_bypath
2015-07-24 15:04:20 -05:00
Edward Thomson
91dad18143 Merge pull request #3305 from libgit2/cmn/reflog-del-backend
refdb: delete a ref's reflog upon deletion
2015-07-24 15:01:04 -05:00
Edward Thomson
14e805a2ce Merge pull request #3304 from libgit2/cmn/checkout-free-stream
filter: make sure to close the stream even on error
2015-07-24 14:59:38 -05:00
Edward Thomson
4e0421fdbd Merge pull request #3317 from csware/fix-vista
Make libgit2 work on Windows Vista again
2015-07-23 10:00:55 -05:00
joshaber
9830fbba05 Merge branch 'master' into fix-init-ordering 2015-07-22 11:33:18 -04:00
joshaber
cf198fdf2a Increment git__n_inits before doing init_once.
Fixes #3318.
2015-07-22 10:51:38 -04:00
Sven Strickroth
318bb763e9 Make libgit2 work on Windows Vista again
(fixes issue #3316)

Signed-off-by: Sven Strickroth <email@cs-ware.de>
2015-07-22 12:52:24 +02:00
Edward Thomson
274f0b9371 Merge pull request #3311 from Fallso/MacroRedefinition
Fix macro redefinition warning
2015-07-15 09:17:35 -05:00
Fallso
cec3569f25 Fix macro redefinition warning 2015-07-15 11:40:06 +01:00
Carlos Martín Nieto
ceb5873913 Merge pull request #3302 from libgit2/cmn/submodule-foreach-diff-path
List a submodule only once when the path matches a submodule in the index
2015-07-13 18:50:39 +02:00
Carlos Martín Nieto
a58854a031 submodule, path: extract slash conversion
Extract the backslash-to-slash conversion into a helper function.
2015-07-13 17:11:19 +02:00
Carlos Martín Nieto
f00f005bad submodule: normalize slashes in resolve_url
Our path functions expect to work with slashes, so convert a
path with backslashes into one with slashes at the top of
the function.
2015-07-13 09:08:32 +02:00
Carlos Martín Nieto
f861abadfe Merge branch 'portable-zu' 2015-07-12 19:56:19 +02:00
Matthew Plough
768f8be31c Fix #3094 - improve use of portable size_t/ssize_t format specifiers.
The header src/cc-compat.h defines portable format specifiers PRIuZ, PRIdZ, and PRIxZ. The original report highlighted the need to use these specifiers in examples/network/fetch.c.  For this commit, I checked all C source and header files not in deps/ and transitioned to the appropriate format specifier where appropriate.
2015-07-12 19:55:19 +02:00
Carlos Martín Nieto
01d0c02dba refdb: delete a ref's reflog upon deletion
Removing a reflog upon ref deletion is something which only some
backends might wish to do. Backends which are database-backed may wish
to archive a reflog, log-based ones may not need to do anything.
2015-07-12 19:08:06 +02:00
Carlos Martín Nieto
4de7f3bfc3 filter: make sure to close the stream even on error
When the stream list init or write fail, we must also make sure to close
the stream, as that's the function contract.
2015-07-12 13:28:03 +02:00
Carlos Martín Nieto
247d27c2c6 index: allow add_bypath to update submodules
Similarly to how git itself does it, allow the index update operation to
stage a change in a submodule's HEAD.
2015-07-12 12:11:22 +02:00
Carlos Martín Nieto
0d98af0911 blob: fail to create a blob from a dir with EDIRECTORY
This also affects `git_index_add_bypath()` by providing a better error
message and a specific error code when a directory is passed.
2015-07-12 12:11:22 +02:00
Carlos Martín Nieto
08c2d3e97c submodule: lookup the submodule by path if available
If we get the path from the gitmodules file, look up the submodule we're
interested in by path, rather then by name. Otherwise we might get
duplicate results.
2015-07-11 18:31:28 +02:00
Carlos Martín Nieto
1cd9601616 Merge pull request #3301 from ethomson/warnings
Clean up some warnings
2015-07-10 19:32:04 +02:00
Carlos Martín Nieto
a1687f7855 Merge pull request #3297 from tkelman/patch-2
Fix undefined reference with old versions of openssl
2015-07-10 19:07:41 +02:00
Edward Thomson
9c0331026b khash: add eol so picky compilers stop warning 2015-07-10 09:53:31 -05:00
Edward Thomson
a3c00cd8e3 xdiff: cleanup some warnings 2015-07-10 09:41:56 -05:00
Edward Thomson
79698030b0 git_cert: child types use proper base type 2015-07-10 09:28:33 -05:00
Carlos Martín Nieto
9847d80ddc Merge pull request #3281 from ethomson/wildcard_filters
filters: custom filters with wildcard attributes
2015-07-09 18:21:31 +02:00
Edward Thomson
234ca40a89 xdiff: upgrade to core git 2.4.5
Upgrade xdiff to version used in core git 2.4.5 (0df0541).

Corrects an issue where an LF is added at EOF while applying
an unrelated change (ba31180), cleans up some unused code (be89977 and
e5b0662), and provides an improved callback to avoid leaking internal
(to xdiff) structures (467d348).

This also adds some additional functionality that we do not yet take
advantage of, namely the ability to ignore changes whose lines are
all blank (36617af).
2015-07-07 17:01:49 -05:00
Tony Kelman
febc8c4612 Fix undefined reference with old versions of openssl
Versions prior to 0.9.8f  did not have this function, rhel/centos5 are still on a
heavily backported version of 0.9.8e and theoretically supported until March 2017

Without this ifdef, I get the following link failure:
```
CMakeFiles/libgit2_clar.dir/src/openssl_stream.c.o: In function `openssl_connect':
openssl_stream.c:(.text+0x45a): undefined reference to `SSL_set_tlsext_host_name'
collect2: error: ld returned 1 exit status
make[6]: *** [libgit2_clar] Error 1
```
2015-07-07 06:55:05 -04:00
Carlos Martín Nieto
3704ac35d3 Merge pull request #3277 from git-up/git_diff_index_to_index
Added git_diff_index_to_index()
2015-07-07 12:38:47 +02:00
Carlos Martín Nieto
ea445e0602 Merge pull request #3288 from ethomson/getenv
git__getenv: utf-8 aware env reader
2015-07-07 00:48:17 +02:00
Carlos Martín Nieto
3c831113ca Merge pull request #3202 from jeffhostetler/windows_stack_trace
Stacktraces with CRTDBG memory leaks on Windows
2015-07-06 19:04:48 +02:00
Edward Thomson
e069c621bd git__getenv: utf-8 aware env reader
Introduce `git__getenv` which is a UTF-8 aware `getenv` everywhere.
Make `cl_getenv` use this to keep consistent memory handling around
return values (free everywhere, as opposed to only some platforms).
2015-07-02 16:35:43 +00:00
Edward Thomson
dd6b24b19a iterator_walk: cast away constness for free 2015-07-02 10:36:15 -05:00
Carlos Martín Nieto
e0af3cb30c submodule: correctly delimit the keys to use for lookup
The regex we use to look at the gitmodules file does not correctly
delimit the name of submodule which we want to look up and puts '.*'
straight after the name, maching on any submodule which has the seeked
submodule as a prefix of its name.

Add the missing '\.' in the regex so we want a full stop to exist both
before and after the submodule name.
2015-07-01 21:15:06 +02:00
Edward Thomson
63924435a1 filters: custom filters with wildcard attributes
Allow custom filters with wildcard attributes, so that clients
can support some random `filter=foo` in a .gitattributes and look
up the corresponding smudge/clean commands in the configuration file.
2015-07-01 09:40:11 -05:00
Linquize
526f91f552 Fix 8.3 filename tests failure when 8.3 is disabled 2015-07-01 14:58:13 +08:00
Matthew Plough
9126ccac96 Fix #3093 - remove declaration of unused function git_fetch__download_pack
Function was added in commit 2c982daa2e on October 5, 2011,
and removed in commit 41fb1ca0ec on October 29, 2012.
Given the length of time it's gone unused, it's safe to remove now.
2015-06-30 16:48:47 -04:00
Carlos Martín Nieto
2f60073dc5 Merge pull request #3273 from ethomson/warnings3
More warnings
2015-06-30 21:40:20 +02:00
Pierre-Olivier Latour
ccef5adb63 Added git_diff_index_to_index() 2015-06-30 10:03:32 -07:00
Pierre-Olivier Latour
1630981e6b http: fixed leak when asking for credentials again
t->cred might have been allocated the previous time and needs to be
freed before asking caller for credentials again.
2015-06-30 09:03:23 -07:00
Edward Thomson
0305721c10 winhttp: remove unused var 2015-06-30 14:31:07 +00:00
Edward Thomson
69c8bf7e0d posix compat: include sys/stat.h for mingw 2015-06-30 14:31:07 +00:00
Edward Thomson
49840056da diff: use size_t format 2015-06-30 14:31:07 +00:00
Edward Thomson
3451c871cb Merge pull request #3271 from jeffhostetler/more_leaks
memory leak refspec.c
2015-06-30 09:29:41 -05:00
Jeff Hostetler
64e6b5b035 fix memory leak in refspec.c on errors. 2015-06-30 09:41:17 -04:00
Carlos Martín Nieto
7bfdd1c2d2 Merge pull request #3270 from ethomson/warnings2
Remove some warnings
2015-06-30 10:21:06 +02:00
Edward Thomson
e5f9df7b0f odb: cast to long long for printf 2015-06-29 21:45:04 +00:00
Edward Thomson
6065505667 submodule: cast enum to int for compare 2015-06-29 21:37:07 +00:00
Edward Thomson
3ca84ac0ed openssl: free hostname 2015-06-29 21:23:09 +00:00
Edward Thomson
149d5d8a50 stash: drop unused variable 2015-06-29 21:23:09 +00:00
Edward Thomson
ded4ccab01 iterator_walk: drop unused variable 2015-06-29 21:23:09 +00:00
Jeff Hostetler
827b954ef4 Reserve aux_id 0; sort leaks by aux_id. Fix cmp. 2015-06-29 16:39:14 -04:00
Jeff Hostetler
93b4272895 Include stacktrace summary in memory leak output. 2015-06-29 16:39:11 -04:00
Carlos Martín Nieto
8b38006018 http: don't give up on auth on the first try
When the server rejects an authentication request, ask the caller for
the credentials again, instead of giving up on the first try.
2015-06-29 21:26:40 +02:00
Carlos Martín Nieto
c28a5c972d submodule: remove trailing slashes from submodule paths
We allow looking up a submodule by path, but we lost the path
normalisation during the recent changes. Bring it back.
2015-06-29 21:10:47 +02:00
Carlos Martín Nieto
cf4030b04b submodule: remove some obsolete logic
Remove some of the logic that was left-over from the time we had a cache
of submodules, plugging a leak of the submodule object in certain cases.
2015-06-29 20:54:17 +02:00
Carlos Martín Nieto
fa399750c6 Merge pull request #3265 from libgit2/leaks
Plug a bunch of leaks
2015-06-27 21:26:27 +02:00
Carlos Martín Nieto
24fa21f38e index, iterator, fetchhead: plug leaks 2015-06-26 19:00:33 +02:00
Carlos Martín Nieto
9568660f62 diff: fix leaks in diff printing 2015-06-26 18:31:39 +02:00
Carlos Martín Nieto
cfafeb843d Merge pull request #3263 from git-up/fixes
Fixes
2015-06-26 18:11:05 +02:00
Carlos Martín Nieto
354268ca48 Merge pull request #3259 from ethomson/stash_apply_argh
Stash apply: stage new files even when not updating the index
2015-06-26 17:46:35 +02:00
Pierre-Olivier Latour
cae2a55552 Fixed build failure if GIT_CURL is not defined 2015-06-26 08:17:56 -07:00
Vicent Marti
3d9ef2dc1b Revert "object: correct the expected ID size in prefix lookup"
This reverts commit 969d4b703c.

This was a fluke from Coverity. The length to all the APIs in the
library is supposed to be passed in as nibbles, not bytes. Passing it as
bytes would prevent us from parsing uneven-sized SHA1 strings.

Also, the rest of the library was still using nibbles (including
revparse and the odb_prefix APIs), so this change was seriously breaking
things in unexpected ways. ^^
2015-06-26 16:45:42 +02:00
Pierre-Olivier Latour
c2e1b0581a Only write index if updated when passing GIT_DIFF_UPDATE_INDEX
When diffing the index with the workdir and GIT_DIFF_UPDATE_INDEX has been passed,
the previous implementation was always writing the index to disk even if it wasn't
modified.
2015-06-26 02:00:21 -04:00
Edward Thomson
c0280bdd15 Merge pull request #3255 from libgit2/cmn/rename-unspecified
Rename FALLBACK to UNSPECIFIED
2015-06-25 18:55:48 -04:00
Edward Thomson
b7f5cb8dd7 stash: stage new files when unstashing them
Files that were new (staged additions) in the stash tree should
be staged when unstashing, even when not applying the index.
2015-06-25 18:34:38 -04:00
Edward Thomson
8960dc1ec6 iterator: provide git_iterator_walk
Provide `git_iterator_walk` to walk each iterator in lockstep,
returning each iterator's idea of the contents of the next path.
2015-06-25 18:34:37 -04:00
Edward Thomson
82b1c93d08 stash: don't allow apply with staged changes 2015-06-25 18:34:36 -04:00