Commit graph

104 commits

Author SHA1 Message Date
Janos Laube b130a72b27 MinGW: implement mmap
Add USE_WIN32_MMAP which triggers the use of windows' native
file memory mapping functionality in git_mmap()/git_munmap() functions.

As git functions currently use mmap with MAP_PRIVATE set only, this
implementation supports only that mode for now.

On Windows, offsets for memory mapped files need to match the allocation
granularity. Take this into account when calculating the packed git-
windowsize and file offsets. At the moment, the only function which makes
use of offsets in conjunction with mmap is use_pack() in sha1-file.c.

Git fast-import's code path tries to map a portion of the temporary
packfile that exceeds the current filesize, i.e. offset+length is
greater than the filesize. The NO_MMAP code worked with that since pread()
just reads the file content until EOF and returns gracefully, while
MapViewOfFile() aborts the mapping and returns 'Access Denied'.
Working around that by determining the filesize and adjusting the length
parameter.

Signed-off-by: Janos Laube <janos.dev@gmail.com>
Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-18 19:23:04 -07:00
Junio C Hamano a9bfe81309 Merge branch 'kb/checkout-optim'
* kb/checkout-optim:
  Revert "lstat_cache(): print a warning if doing ping-pong between cache types"
  checkout bugfix: use stat.mtime instead of stat.ctime in two places
  Makefile: Set compiler switch for USE_NSEC
  Create USE_ST_TIMESPEC and turn it on for Darwin
  Not all systems use st_[cm]tim field for ns resolution file timestamp
  Record ns-timestamps if possible, but do not use it without USE_NSEC
  write_index(): update index_state->timestamp after flushing to disk
  verify_uptodate(): add ce_uptodate(ce) test
  make USE_NSEC work as expected
  fix compile error when USE_NSEC is defined
  check_updates(): effective removal of cache entries marked CE_REMOVE
  lstat_cache(): print a warning if doing ping-pong between cache types
  show_patch_diff(): remove a call to fstat()
  write_entry(): use fstat() instead of lstat() when file is open
  write_entry(): cleanup of some duplicated code
  create_directories(): remove some memcpy() and strchr() calls
  unlink_entry(): introduce schedule_dir_for_removal()
  lstat_cache(): swap func(length, string) into func(string, length)
  lstat_cache(): generalise longest_match_lstat_cache()
  lstat_cache(): small cleanup and optimisation
2009-03-17 18:54:31 -07:00
Brian Gernhardt c567383b1e Create USE_ST_TIMESPEC and turn it on for Darwin
Not all OSes use st_ctim and st_mtim in their struct stat.  In
particular, it appears that OS X uses st_*timespec instead.  So add a
Makefile variable and #define called USE_ST_TIMESPEC to switch the
USE_NSEC defines to use st_*timespec.

This also turns it on by default for OS X (Darwin) machines.  Likely
this is a sane default for other BSD kernels as well, but I don't have
any to test that assumption on.

Signed-off-by: Brian Gernhardt <benji@silverinsanity.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-08 14:04:41 -07:00
Kjetil Barvik c06ff4908b Record ns-timestamps if possible, but do not use it without USE_NSEC
Traditionally, the lack of USE_NSEC meant "do not record nor use the
nanosecond resolution part of the file timestamps".  To avoid problems on
filesystems that lose the ns part when the metadata is flushed to the disk
and then later read back in, disabling USE_NSEC has been a good idea in
general.

If you are on a filesystem without such an issue, it does not hurt to read
and store them in the cached stat data in the index entries even if your
git is compiled without USE_NSEC.  The index left with such a version of
git can be read by git compiled with USE_NSEC and it can make use of the
nanosecond part to optimize the check to see if the path on the filesystem
hsa been modified since we last looked at.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-07 20:25:16 -08:00
René Scharfe c2e9364a06 cleanup: add isascii()
Add a standard definition of isascii() and use it to replace an open
coded high-bit test in pretty.c.  While we're there, write the ESC
char as the more commonly used '\033' instead of as 0x1b to enhance
its grepability.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-03-07 11:22:42 -08:00
Junio C Hamano bb0cebd7d0 Merge branch 'jc/maint-1.6.0-pack-directory'
* jc/maint-1.6.0-pack-directory:
  Make sure objects/pack exists before creating a new pack
2009-02-25 14:50:05 -08:00
Junio C Hamano 6e180cdcec Make sure objects/pack exists before creating a new pack
In a repository created with git older than f49fb35 (git-init-db: create
"pack" subdirectory under objects, 2005-06-27), objects/pack/ directory is
not created upon initialization.  It was Ok because subdirectories are
created as needed inside directories init-db creates, and back then,
packfiles were recent invention.

After the said commit, new codepaths started relying on the presense of
objects/pack/ directory in the repository.  This was exacerbated with
8b4eb6b (Do not perform cross-directory renames when creating packs,
2008-09-22) that moved the location temporary pack files are created from
objects/ directory to objects/pack/ directory, because moving temporary to
the final location was done carefully with lazy leading directory creation.

Many packfile related operations in such an old repository can fail
mysteriously because of this.

This commit introduces two helper functions to make things work better.

 - odb_mkstemp() is a specialized version of mkstemp() to refactor the
   code and teach it to create leading directories as needed;

 - odb_pack_keep() refactors the code to create a ".keep" file while
   create leading directories as needed.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-02-25 14:39:42 -08:00
René Scharfe f9b7cce61c Add is_regex_special()
Add is_regex_special(), a character class macro for chars that have a
special meaning in regular expressions.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-17 18:30:41 -08:00
René Scharfe 8cc3299262 Change NUL char handling of isspecial()
Replace isspecial() by the new macro is_glob_special(), which is more,
well, specialized.  The former included the NUL char in its character
class, while the letter only included characters that are special to
file name globbing.

The new name contains underscores because they enhance readability
considerably now that it's made up of three words.  Renaming the
function is necessary to document its changed scope.

The call sites of isspecial() are updated to check explicitly for NUL.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-17 18:30:37 -08:00
Dmitry Potapov adbc0b6b6e cygwin: Use native Win32 API for stat
lstat/stat functions in Cygwin are very slow, because they try to emulate
some *nix things that Git does not actually need. This patch adds Win32
specific implementation of these functions for Cygwin.

This implementation handles most situation directly but in some rare cases
it falls back on the implementation provided for Cygwin. This is necessary
for two reasons:

- Cygwin has its own file hierarchy, so absolute paths used in Cygwin is
  not suitable to be used Win32 API. cygwin_conv_to_win32_path can not be
  used because it automatically dereference Cygwin symbol links, also it
  causes extra syscall. Fortunately Git rarely use absolute paths, so we
  always use Cygwin implementation for absolute paths.

- Support of symbol links. Cygwin stores symbol links as ordinary using
  one of two possible formats. Therefore, the fast implementation falls
  back to Cygwin functions if it detects potential use of symbol links.

The speed of this implementation should be the same as mingw_lstat for
common cases, but it is considerable slower when the specified file name
does not exist.

Despite all efforts to make the fast implementation as robust as possible,
it may not work well for some very rare situations. I am aware only one
situation: use Cygwin mount to bind unrelated paths inside repository
together.  Therefore, the core.ignoreCygwinFSTricks configuration option is
provided, which controls whether native or Cygwin version of stat is used.

Signed-off-by: Dmitry Potapov <dpotapov@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-09-30 14:30:06 -07:00
Nanako Shiraishi 07ad5a157d usage.c: remove unused functions
This removes three functions that are not used anywhere.

Signed-off-by: Nanako Shiraishi <nanako3@lavabit.com>
Acked-by: Lars Hjemli <hjemli@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2008-09-29 07:30:16 -07:00
Brandon Casey 63e8aea74e dir.c: Avoid c99 array initialization
The following syntax:

        char foo[] = {
                [0] = 1,
                [7] = 2,
                [15] = 3
        };

is a c99 construct which some compilers do not support even though they
support other c99 constructs. This construct can be avoided by folding
these 'special' test cases into the sane_ctype array and making use of
the related infrastructure.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-08-28 21:49:51 -07:00
Junio C Hamano c8a4cbc239 Merge branch 'rs/imap'
* rs/imap:
  Documentation: Improve documentation for git-imap-send(1)
  imap-send.c: more style fixes
  imap-send.c: style fixes
  git-imap-send: Support SSL
  git-imap-send: Allow the program to be run from subdirectories of a git tree
2008-08-19 21:42:46 -07:00
Junio C Hamano fdb2a2a600 compat: introduce on_disk_bytes()
Some platforms do not have st_blocks member in "struct stat"; mingw
already emulates it by rounding it up to closest 512-byte blocks (even
though it could overcount when a file has holes).

The reason to use the member is only to figure out how many kilobytes the
files occupy on-disk, so give a helper function in git-compat-util.h to
compute this value.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Acked-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-08-18 22:37:55 -07:00
Robert Shearman 684ec6c63c git-imap-send: Support SSL
Allow SSL to be used when a imaps:// URL is used for the host name.

Also, automatically use TLS when not using imaps:// by using the IMAP
STARTTLS command, if the server supports it.

Tested with Courier and Gimap IMAP servers.

Signed-off-by: Robert Shearman <robertshearman@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-25 21:51:30 -07:00
Junio C Hamano fcab40a389 Merge branch 'mv/merge-in-c'
* mv/merge-in-c:
  reduce_heads(): protect from duplicate input
  reduce_heads(): thinkofix
  Add a new test for git-merge-resolve
  t6021: add a new test for git-merge-resolve
  Teach merge.log to "git-merge" again
  Build in merge
  Fix t7601-merge-pull-config.sh on AIX
  git-commit-tree: make it usable from other builtins
  Add new test case to ensure git-merge prepends the custom merge message
  Add new test case to ensure git-merge reduces octopus parents when possible
  Introduce reduce_heads()
  Introduce get_merge_bases_many()
  Add new test to ensure git-merge handles more than 25 refs.
  Introduce get_octopus_merge_bases() in commit.c
  git-fmt-merge-msg: make it usable from other builtins
  Move read_cache_unmerged() to read-cache.c
  Add new test to ensure git-merge handles pull.twohead and pull.octopus
  Move parse-options's skip_prefix() to git-compat-util.h
  Move commit_list_count() to commit.c
  Move split_cmdline() to alias.c

Conflicts:
	Makefile
	parse-options.c
2008-07-15 19:09:46 -07:00
Johannes Sixt 607bb3ff88 Provide fallback definitions of PRIu32 and PRIx32
Since 6e1c23442 we make use of these C99 constructs, but this commit did
not provide fallbacks for non-C99 systems.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-07-09 15:10:03 -07:00
Junio C Hamano bb1ab2db08 Merge branch 'j6t/mingw'
* j6t/mingw: (38 commits)
  compat/pread.c: Add a forward declaration to fix a warning
  Windows: Fix ntohl() related warnings about printf formatting
  Windows: TMP and TEMP environment variables specify a temporary directory.
  Windows: Make 'git help -a' work.
  Windows: Work around an oddity when a pipe with no reader is written to.
  Windows: Make the pager work.
  When installing, be prepared that template_dir may be relative.
  Windows: Use a relative default template_dir and ETC_GITCONFIG
  Windows: Compute the fallback for exec_path from the program invocation.
  Turn builtin_exec_path into a function.
  Windows: Use a customized struct stat that also has the st_blocks member.
  Windows: Add a custom implementation for utime().
  Windows: Add a new lstat and fstat implementation based on Win32 API.
  Windows: Implement a custom spawnve().
  Windows: Implement wrappers for gethostbyname(), socket(), and connect().
  Windows: Work around incompatible sort and find.
  Windows: Implement asynchronous functions as threads.
  Windows: Disambiguate DOS style paths from SSH URLs.
  Windows: A rudimentary poll() emulation.
  Windows: Implement start_command().
  ...
2008-07-02 21:57:52 -07:00
Miklos Vajna fbca583732 Move parse-options's skip_prefix() to git-compat-util.h
builtin-remote.c and parse-options.c both have a skip_prefix() function,
for the same purpose. Move parse-options's one to git-compat-util.h and
let builtin-remote use it as well.

Signed-off-by: Miklos Vajna <vmiklos@frugalware.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-30 22:45:50 -07:00
Steffen Prohaska 14086b0a13 compat/pread.c: Add a forward declaration to fix a warning
read_in_full()'s is used in compat/pread.c.  read_in_full() is
declared in cache.h. But we can't include cache.h because too
many macros are defined there.  Using read_in_full() without
including cache.h is dangerous because we wouldn't recognize if
its prototyp changed.  gcc issues a warning about that.

This commit adds a forward declaration to git-compat-util.h.
git-compat-util.h is included by compat/pread.c _and_ cache.h.
Hence, changes in cache.h would be detected.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-26 08:47:17 +02:00
Johannes Sixt bb5799d6ef Make my_mktime() public and rename it to tm_to_time_t()
We will use it from the MinGW port's gettimeofday() substitution.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23 13:40:29 +02:00
Johannes Sixt 23326d14ed Windows: Strip ".exe" from the program name.
Before we can successfully parse a builtin command from the program name
we must strip off unneeded parts, that is, the file extension.

Furthermore, we must take Windows style path names into account when we
parse the program name.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23 13:34:55 +02:00
Johannes Sixt 25fe217b86 Windows: Treat Windows style path names.
GIT's guts work with a forward slash as a path separators. We do not change
that. Rather we make sure that only "normalized" paths enter the depths
of the machinery.

We have to translate backslashes to forward slashes in the prefix and in
command line arguments. Fortunately, all of them are passed through
functions in setup.c.

A macro has_dos_drive_path() is defined that checks whether a path begins
with a drive letter+colon combination. This predicate is always false on
Unix. Another macro is_dir_sep() abstracts that a backslash is also a
directory separator on Windows.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-23 13:30:22 +02:00
Linus Torvalds 112db553b0 Shrink the git binary a bit by avoiding unnecessary inline functions
So I was looking at the disgusting size of the git binary, and even with
the debugging removed, and using -Os instead of -O2, the size of the text
section was pretty high. In this day and age I guess almost a megabyte of
text isn't really all that surprising, but it still doesn't exactly make
me think "lean and mean".

With -Os, a surprising amount of text space is wasted on inline functions
that end up just being replicated multiple times, and where performance
really isn't a valid reason to inline them. In particular, the trivial
wrapper functions like "xmalloc()" are used _everywhere_, and making them
inline just duplicates the text (and the string we use to 'die()' on
failure) unnecessarily.

So this just moves them into a "wrapper.c" file, getting rid of a tiny bit
of unnecessary bloat. The following numbers are both with "CFLAGS=-Os":

Before:
	[torvalds@woody git]$ size git
	   text	   data	    bss	    dec	    hex	filename
	 700460	  15160	 292184	1007804	  f60bc	git

After:
	[torvalds@woody git]$ size git
	   text	   data	    bss	    dec	    hex	filename
	 670540	  15160	 292184	 977884	  eebdc	git

so it saves almost 30k of text-space (it actually saves more than that
with the default -O2, but I don't think that's necessarily a very relevant
number from a "try to shrink git" standpoint).

It might conceivably have a performance impact, but none of this should be
_that_ performance critical. The real cost is not generally in the wrapper
anyway, but in the code it wraps (ie the cost of "xread()" is all in the
read itself, not in the trivial wrapping of it).

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-22 18:46:00 -07:00
Johannes Sixt 80ba074f41 Windows: Use the Windows style PATH separator ';'.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-22 11:32:45 +02:00
Johannes Sixt f4626df51f Add target architecture MinGW.
With this change GIT can be compiled and linked using MinGW. Builtins
that only read the repository such as the log family and grep already
work.

Simple stubs are provided for a number of functions that the Windows C
runtime does not offer. They will be completed in later patches.
However, a fix for the snprintf/vsnprintf replacement is applied here
to avoid buffer overflows.

Dmitry Kakurin pointed out that access(..., X_OK) would always fails on
Vista and suggested the -D__USE_MINGW_ACCESS workaround.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
2008-06-22 11:32:45 +02:00
Boyd Lynn Gerber 457bb45291 Port to 12 other Platforms.
This patch adds support to compile and run git on 12 additional platforms.
The platforms are based on UNIX Systems Labs (USL)/Novell/SYS V code base.
The most common are Novell UnixWare 2.X.X, SCO UnixWare 7.X.X,
OpenServer 5.0.X, OpenServer 6.0.X, and SCO pre OSR 5 platforms.

Looking at the the various platform headers, I find:

	#if defined(_KERNEL) || !defined(_POSIX_SOURCE) \
	     && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)

which hides u_short and other typedefs that other header files on these
platforms depend on.  WIth _XOPEN_SOURCE defined, sources that include
system header files that depend on the typedefs such as u_short cannot be
compiled on these platforms.

__USLC__ indicates UNIX System Labs Corperation (USLC), or a Novell-derived
compiler and/or some SysV based OS's.

__M_UNIX indicates XENIX/SCO UNIX/OpenServer 5.0.7 and prior releases
of the SCO OS's.  It is used just like Apple and BSD, both of these
shouldn't have _XOPEN_SOURCE defined.

This is with suggestions and modifications from

Daniel Barkalow, Junio C Hamano, Thomas Harning, and Jeremy Maitin-Shepard.

Signed-off-by: Boyd Lynn Gerber <gerberb@zenez.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-06-08 14:27:46 -07:00
Johannes Sixt c5445fe090 compat-util: avoid macro redefinition warning
Some systems define fopen as a macro based on compiler settings, and
unconditionally redefining it triggers a compilation warning.
2008-05-08 17:47:25 -07:00
Heikki Orsila e8729f5380 Document functions xmemdupz(), xread() and xwrite()
Signed-off-by: Heikki Orsila <heikki.orsila@iki.fi>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-04-27 22:22:14 -07:00
Nicolas Pitre f746bae84e pack-objects: proper pack time stamping with --max-pack-size
Runtime pack access is done in the pack file mtime order since recent
packs are more likely to contain frequently used objects than old packs.
However the --max-pack-size option can produce multiple packs with mtime
in the reversed order as newer objects are always written first.

Let's modify mtime of later pack files (when any) so they appear older
than preceding ones when a repack creates multiple packs.

Signed-off-by: Nicolas Pitre <nico@cam.org>
2008-03-13 22:51:30 -07:00
Junio C Hamano 6e79a88585 Merge branch 'mr/compat-snprintf'
* mr/compat-snprintf:
  Add compat/snprintf.c for systems that return bogus
2008-03-08 21:29:50 -08:00
Michal Rokos c4582f93a2 Add compat/snprintf.c for systems that return bogus
Some systems (namely HPUX and Windows) return -1 when maxsize in snprintf()
and in vsnprintf() is reached. So replace snprintf() and vsnprintf()
functions with our own ones that return correct value upon overflow.

[jc: verified that review comments by J6t have been incorporated, and
 tightened the check to verify the resulting buffer contents, suggested
 by Wayne Davison]

Signed-off-by: Michal Rokos <michal.rokos@nextsoft.cz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-05 13:12:07 -08:00
Alex Riesen 81a24b52c1 Do not use GUID on dir in git init --shared=all on FreeBSD
It does not allow changing the bit to a non-root user.
This fixes t1301-shared-repo.sh on the platform.

Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-03-05 12:22:26 -08:00
Junio C Hamano c0284cea31 Merge branch 'bc/fopen'
* bc/fopen:
  Add compat/fopen.c which returns NULL on attempt to open directory
2008-02-20 16:13:19 -08:00
Brandon Casey cba22528fa Add compat/fopen.c which returns NULL on attempt to open directory
Some systems do not fail as expected when fread et al. are called on
a directory stream. Replace fopen on such systems which will fail
when the supplied path is a directory.

Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-11 18:25:10 -08:00
Brian Downing 43fe901b71 compat: Add simplified merge sort implementation from glibc
qsort in Windows 2000 (and various other C libraries) is a Quicksort
with the usual O(n^2) worst case.  Unfortunately, sorting Git trees
seems to get very close to that worst case quite often:

    $ /git/gitbad runstatus
    # On branch master
    qsort, nmemb = 30842
    done, 237838087 comparisons.

This patch adds a simplified version of the merge sort that is glibc's
qsort(3).  As a merge sort, this needs a temporary array equal in size
to the array that is to be sorted, but has a worst-case performance of
O(n log n).

The complexity that was removed is:

* Doing direct stores for word-size and -aligned data.
* Falling back to quicksort if the allocation required to perform the
  merge sort would likely push the machine into swap.

Even with these simplifications, this seems to outperform the Windows
qsort(3) implementation, even in Windows XP (where it is "fixed" and
doesn't trigger O(n^2) complexity on trees).

[jes: moved into compat/qsort.c, as per Johannes Sixt's suggestion]
[bcd: removed gcc-ism, thanks to Edgar Toernig.  renamed make variable
      per Junio's comment.]

Signed-off-by: Brian Downing <bdowning@lavos.net>
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-02-06 22:35:28 -08:00
Robert Schiele 2600973f2c pre-POSIX.1-2001 systems do not have <sys/select.h>
POSIX.1-2001 has declaration of select(2) in <sys/select.h>, but
in the previous version of SUS, it was declared in <sys/time.h>
(which is already included in git-compat-util.h).

This introduces NO_SYS_SELECT_H macro in the Makefile to be set
on older systems, to skip inclusion of <sys/select.h> that does
not exist on them.

We could check _POSIX_VERSION with 200112L and do this
automatically, but earlier it was reported that the approach
does not work well on some vintage of HP-UX.  Other systems may
get _POSIX_VERSION itself wrong.  At least for now, this manual
configuration is safer.

Signed-off-by: Robert Schiele <rschiele@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-01-24 14:01:28 -08:00
Junio C Hamano 698a68be7b Uninline prefixcmp()
Now the routine is an open-coded loop that avoids an extra
strlen() in the previous implementation, it got a bit too big to
be inlined.  Uninlining it makes code footprint smaller but the
result still retains the avoidance of strlen() cost.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-01-03 01:23:12 -08:00
Johannes Schindelin 99a6a97b1b Optimize prefixcmp()
Certain codepaths (notably "git log --pretty=format...") use
prefixcmp() extensively, with very short prefixes.  In those cases,
calling strlen() is a wasteful operation, so avoid it.

Initial patch by Marco Costalba.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2008-01-02 02:28:54 -08:00
Junio C Hamano ab002e34e2 Merge branch 'js/mingw-fallouts'
* js/mingw-fallouts:
  fetch-pack: Prepare for a side-band demultiplexer in a thread.
  rehabilitate some t5302 tests on 32-bit off_t machines
  Allow ETC_GITCONFIG to be a relative path.
  Introduce git_etc_gitconfig() that encapsulates access of ETC_GITCONFIG.
  Allow a relative builtin template directory.
  Close files opened by lock_file() before unlinking.
  builtin run_command: do not exit with -1.
  Move #include <sys/select.h> and <sys/ioctl.h> to git-compat-util.h.
  Use is_absolute_path() in sha1_file.c.
  Skip t3902-quoted.sh if the file system does not support funny names.
  t5302-pack-index: Skip tests of 64-bit offsets if necessary.
  t7501-commit.sh: Not all seds understand option -i
  t5300-pack-object.sh: Split the big verify-pack test into smaller parts.
2007-11-24 16:31:25 -08:00
Junio C Hamano 8e97399149 git-compat-util.h: auto-adjust to compiler support of FLEX_ARRAY a bit better
When declaring a structure with a flexible array member, instead
of defaulting to the c99 syntax for non-gnu compilers (which
burned people with older compilers), default to the traditional
and more portable "member[1]; /* more */" syntax.

At the same time, other c99 compilers should be able to take
advantage of the modern syntax to flexible array members without
being gcc.  Check __STDC_VERSION__ for that.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-20 15:03:56 -08:00
Junio C Hamano e6cb314c08 Merge branch 'ph/diffopts'
* ph/diffopts:
  Reorder diff_opt_parse options more logically per topics.
  Make the diff_options bitfields be an unsigned with explicit masks.
  Use OPT_BIT in builtin-pack-refs
  Use OPT_BIT in builtin-for-each-ref
  Use OPT_SET_INT and OPT_BIT in builtin-branch
  parse-options new features.
2007-11-18 15:50:16 -08:00
Johannes Sixt 80bbe72b76 Move #include <sys/select.h> and <sys/ioctl.h> to git-compat-util.h.
... since all system headers are pulled in via git-compat-util.h

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-14 15:18:39 -08:00
Johannes Sixt 726c8ef5a5 Fix preprocessor logic that determines the availablity of strchrnul().
Apart from the error in the condition (&& should actually be ||), the
construct

    #if !defined(A) || !A

leads to a syntax error in the C preprocessor if A is indeed not defined.

Tested-by: David Symonds <dsymonds@gmail.com>
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-12 18:16:34 -08:00
Pierre Habouzit db7244bd5b parse-options new features.
options flags:
~~~~~~~~~~~~~
  PARSE_OPT_NONEG allow the caller to disallow the negated option to exists.

option types:
~~~~~~~~~~~~
  OPTION_BIT: ORs (or NANDs) a mask.
  OPTION_SET_INT: force the value to be set to this integer.
  OPTION_SET_PTR: force the value to be set to this pointer.

helper:
~~~~~~
  HAS_MULTI_BITS (in git-compat-util.h) is a bit-hack to check if an
  unsigned integer has more than one bit set, useful to check if conflicting
  options have been used.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-11 16:54:15 -08:00
Andreas Ericsson 9e79f00f06 Simplify strchrnul() compat code
strchrnul() was introduced in glibc in April 1999 and included in
glibc-2.1. Checking for that version means the majority of all git
users would get to use the optimized version in glibc. Of the
remaining few some might get to use a slightly slower version
than necessary but probably not slower than what we have today.

Unfortunately, __GLIBC_PREREQ() macro was not available in glibc 2.1.1
which was short lived but already supported strchrnul().  Odd minority
users of that library needs to live with our compatibility inline version.

Rediffed-against-next-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-11 12:10:35 -08:00
René Scharfe 659c69cfef Add strchrnul()
As suggested by Pierre Habouzit, add strchrnul().  It's a useful GNU
extension and can simplify string parser code.  There are several
places in git that can be converted to strchrnul(); as a trivial
example, this patch introduces its usage to builtin-fetch--tool.c.

Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-11-09 01:30:07 -08:00
Junio C Hamano 7791ecbc62 revert/cherry-pick: work on merge commits as well
Usually you cannot revert a merge because you do not know which
side of the merge should be considered the mainline (iow, what
change to reverse).

With this patch, cherry-pick and revert learn -m (--mainline)
option that lets you specify the parent number (starting from 1)
of the mainline, so that you can:

	git revert -m 1 $merge

to reverse the changes introduced by the $merge commit relative
to its first parent, and:

	git cherry-pick -m 2 $merge

to replay the changes introduced by the $merge commit relative
to its second parent.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-10-26 23:28:28 -07:00
Shawn O. Pearce ca5bb5d539 Define compat version of mkdtemp for systems lacking it
Solaris 9 doesn't have mkdtemp() so we need to emulate it for the
rsync transport implementation.  Since Solaris 9 is lacking this
function we can also reasonably assume it is not available on
Solaris 8 either.  The new Makfile definition NO_MKDTEMP can be
set to enable the git compat version.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
2007-10-20 22:52:21 -04:00
Pierre Habouzit 68d3025a80 Add xmemdupz() that duplicates a block of memory, and NUL terminates it.
A lot of places in git's code use code like:

  char *res;

  len = ... find length of an interesting segment in src ...;
  res = xmalloc(len + 1);
  memcpy(res, src, len);
  res[len] = '\0';
  return res;

A new function xmemdupz() captures the allocation, copy and NUL
termination.  Existing xstrndup() is reimplemented in terms of
this new function.

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2007-09-18 03:07:58 -07:00