Skip to content

Commit

Permalink
Merge branch 'master' into ph/strbuf
Browse files Browse the repository at this point in the history
* master:
  archive - leakfix for format_subst()
  Make --no-thin the default in git-push to save server resources
  fix doc for --compression argument to pack-objects
  git-tag -s must fail if gpg cannot sign the tag.
  git-svn: understand grafts when doing dcommit
  git-diff: don't squelch the new SHA1 in submodule diffs
  Define NO_MEMMEM on Darwin as it lacks the function
  git-svn: fix "Malformed network data" with svn:// servers
  (cvs|svn)import: Ask git-tag to overwrite old tags.
  git-rebase: fix -C option
  git-rebase: support --whitespace=<option>
  Documentation / grammer nit
  archive: rename attribute specfile to export-subst
  archive: specfile syntax change: "$Format:%PLCHLDR$" instead of just "%PLCHLDR" (take 2)
  add memmem()
  Remove unused function convert_sha1_file()
  archive: specfile support (--pretty=format: in archive files)
  Export format_commit_message()
  • Loading branch information
Junio C Hamano committed Sep 10, 2007
2 parents 5242bcb + 6972ab7 commit ddb95de
Show file tree
Hide file tree
Showing 25 changed files with 272 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Documentation/git-clone.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ OPTIONS
automatically setup .git/objects/info/alternates to
obtain objects from the reference repository. Using
an already existing repository as an alternate will
require less objects to be copied from the repository
require fewer objects to be copied from the repository
being cloned, reducing network and local storage costs.

--quiet::
Expand Down
8 changes: 2 additions & 6 deletions Documentation/git-pack-objects.txt
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,8 @@ base-name::
generated pack. If not specified, pack compression level is
determined first by pack.compression, then by core.compression,
and defaults to -1, the zlib default, if neither is set.
Data copied from loose objects will be recompressed
if core.legacyheaders was true when they were created or if
the loose compression level (see core.loosecompression and
core.compression) is now a different value than the pack
compression level. Add --no-reuse-object if you want to force
a uniform compression level on all data no matter the source.
Add \--no-reuse-object if you want to force a uniform compression
level on all data no matter the source.

--delta-base-offset::
A packed archive can express base object of a delta as
Expand Down
9 changes: 7 additions & 2 deletions Documentation/git-rebase.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ git-rebase - Forward-port local commits to the updated upstream head
SYNOPSIS
--------
[verse]
'git-rebase' [-i | --interactive] [-v | --verbose] [-m | --merge] [-C<n>]
[-p | --preserve-merges] [--onto <newbase>] <upstream> [<branch>]
'git-rebase' [-i | --interactive] [-v | --verbose] [-m | --merge]
[-C<n>] [ --whitespace=<option>] [-p | --preserve-merges]
[--onto <newbase>] <upstream> [<branch>]
'git-rebase' --continue | --skip | --abort

DESCRIPTION
Expand Down Expand Up @@ -209,6 +210,10 @@ OPTIONS
context exist they all must match. By default no context is
ever ignored.

--whitespace=<nowarn|warn|error|error-all|strip>::
This flag is passed to the `git-apply` program
(see gitlink:git-apply[1]) that applies the patch.

-i, \--interactive::
Make a list of the commits which are about to be rebased. Let the
user edit that list before rebasing. This mode can also be used to
Expand Down
17 changes: 17 additions & 0 deletions Documentation/gitattributes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,23 @@ frotz unspecified
----------------------------------------------------------------


Creating an archive
~~~~~~~~~~~~~~~~~~~

`export-subst`
^^^^^^^^^^^^^^

If the attribute `export-subst` is set for a file then git will expand
several placeholders when adding this file to an archive. The
expansion depends on the availability of a commit ID, i.e. if
gitlink:git-archive[1] has been given a tree instead of a commit or a
tag then no replacement will be done. The placeholders are the same
as those for the option `--pretty=format:` of gitlink:git-log[1],
except that they need to be wrapped like this: `$Format:PLACEHOLDERS$`
in the file. E.g. the string `$Format:%H$` will be replaced by the
commit hash.


GIT
---
Part of the gitlink:git[7] suite
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ all::
#
# Define NO_STRCASESTR if you don't have strcasestr.
#
# Define NO_MEMMEM if you don't have memmem.
#
# Define NO_STRLCPY if you don't have strlcpy.
#
# Define NO_STRTOUMAX if you don't have strtoumax in the C library.
Expand Down Expand Up @@ -396,12 +398,14 @@ ifeq ($(uname_S),Darwin)
NEEDS_LIBICONV = YesPlease
OLD_ICONV = UnfortunatelyYes
NO_STRLCPY = YesPlease
NO_MEMMEM = YesPlease
endif
ifeq ($(uname_S),SunOS)
NEEDS_SOCKET = YesPlease
NEEDS_NSL = YesPlease
SHELL_PATH = /bin/bash
NO_STRCASESTR = YesPlease
NO_MEMMEM = YesPlease
NO_HSTRERROR = YesPlease
ifeq ($(uname_R),5.8)
NEEDS_LIBICONV = YesPlease
Expand All @@ -424,6 +428,7 @@ ifeq ($(uname_O),Cygwin)
NO_D_TYPE_IN_DIRENT = YesPlease
NO_D_INO_IN_DIRENT = YesPlease
NO_STRCASESTR = YesPlease
NO_MEMMEM = YesPlease
NO_SYMLINK_HEAD = YesPlease
NEEDS_LIBICONV = YesPlease
NO_FAST_WORKING_DIRECTORY = UnfortunatelyYes
Expand All @@ -442,6 +447,7 @@ ifeq ($(uname_S),FreeBSD)
endif
ifeq ($(uname_S),OpenBSD)
NO_STRCASESTR = YesPlease
NO_MEMMEM = YesPlease
NEEDS_LIBICONV = YesPlease
BASIC_CFLAGS += -I/usr/local/include
BASIC_LDFLAGS += -L/usr/local/lib
Expand All @@ -456,6 +462,7 @@ ifeq ($(uname_S),NetBSD)
endif
ifeq ($(uname_S),AIX)
NO_STRCASESTR=YesPlease
NO_MEMMEM = YesPlease
NO_STRLCPY = YesPlease
NEEDS_LIBICONV=YesPlease
endif
Expand All @@ -467,6 +474,7 @@ ifeq ($(uname_S),IRIX64)
NO_IPV6=YesPlease
NO_SETENV=YesPlease
NO_STRCASESTR=YesPlease
NO_MEMMEM = YesPlease
NO_STRLCPY = YesPlease
NO_SOCKADDR_STORAGE=YesPlease
SHELL_PATH=/usr/gnu/bin/bash
Expand Down Expand Up @@ -661,6 +669,10 @@ ifdef NO_HSTRERROR
COMPAT_CFLAGS += -DNO_HSTRERROR
COMPAT_OBJS += compat/hstrerror.o
endif
ifdef NO_MEMMEM
COMPAT_CFLAGS += -DNO_MEMMEM
COMPAT_OBJS += compat/memmem.o
endif

ifeq ($(TCLTK_PATH),)
NO_TCLTK=NoThanks
Expand Down
5 changes: 4 additions & 1 deletion archive-tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ static unsigned long offset;
static time_t archive_time;
static int tar_umask = 002;
static int verbose;
static const struct commit *commit;

/* writes out the whole block, but only if it is full */
static void write_if_needed(void)
Expand Down Expand Up @@ -252,7 +253,8 @@ static int write_tar_entry(const unsigned char *sha1,
buffer = NULL;
size = 0;
} else {
buffer = convert_sha1_file(path.buf, sha1, mode, &type, &size);
buffer = sha1_file_to_archive(path.buf, sha1, mode, &type,
&size, commit);
if (!buffer)
die("cannot read %s", sha1_to_hex(sha1));
}
Expand All @@ -271,6 +273,7 @@ int write_tar_archive(struct archiver_args *args)

archive_time = args->time;
verbose = args->verbose;
commit = args->commit;

if (args->commit_sha1)
write_global_extended_header(args->commit_sha1);
Expand Down
5 changes: 4 additions & 1 deletion archive-zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
static int verbose;
static int zip_date;
static int zip_time;
static const struct commit *commit;

static unsigned char *zip_dir;
static unsigned int zip_dir_size;
Expand Down Expand Up @@ -195,7 +196,8 @@ static int write_zip_entry(const unsigned char *sha1,
if (S_ISREG(mode) && zlib_compression_level != 0)
method = 8;
result = 0;
buffer = convert_sha1_file(path, sha1, mode, &type, &size);
buffer = sha1_file_to_archive(path, sha1, mode, &type, &size,
commit);
if (!buffer)
die("cannot read %s", sha1_to_hex(sha1));
crc = crc32(crc, buffer, size);
Expand Down Expand Up @@ -316,6 +318,7 @@ int write_zip_archive(struct archiver_args *args)
zip_dir = xmalloc(ZIP_DIRECTORY_MIN_SIZE);
zip_dir_size = ZIP_DIRECTORY_MIN_SIZE;
verbose = args->verbose;
commit = args->commit;

if (args->base && plen > 0 && args->base[plen - 1] == '/') {
char *base = xstrdup(args->base);
Expand Down
3 changes: 3 additions & 0 deletions archive.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ struct archiver_args {
const char *base;
struct tree *tree;
const unsigned char *commit_sha1;
const struct commit *commit;
time_t time;
const char **pathspec;
unsigned int verbose : 1;
Expand Down Expand Up @@ -42,4 +43,6 @@ extern int write_tar_archive(struct archiver_args *);
extern int write_zip_archive(struct archiver_args *);
extern void *parse_extra_zip_args(int argc, const char **argv);

extern void *sha1_file_to_archive(const char *path, const unsigned char *sha1, unsigned int mode, enum object_type *type, unsigned long *size, const struct commit *commit);

#endif /* ARCHIVE_H */
98 changes: 97 additions & 1 deletion builtin-archive.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "exec_cmd.h"
#include "pkt-line.h"
#include "sideband.h"
#include "attr.h"

static const char archive_usage[] = \
"git-archive --format=<fmt> [--prefix=<prefix>/] [--verbose] [<extra>] <tree-ish> [path...]";
Expand Down Expand Up @@ -80,6 +81,100 @@ static int run_remote_archiver(const char *remote, int argc,
return !!rv;
}

static void *format_subst(const struct commit *commit, const char *format,
unsigned long *sizep)
{
unsigned long len = *sizep, result_len = 0;
const char *a = format;
char *result = NULL;

for (;;) {
const char *b, *c;
char *fmt, *formatted = NULL;
unsigned long a_len, fmt_len, formatted_len, allocated = 0;

b = memmem(a, len, "$Format:", 8);
if (!b || a + len < b + 9)
break;
c = memchr(b + 8, '$', len - 8);
if (!c)
break;

a_len = b - a;
fmt_len = c - b - 8;
fmt = xmalloc(fmt_len + 1);
memcpy(fmt, b + 8, fmt_len);
fmt[fmt_len] = '\0';

formatted_len = format_commit_message(commit, fmt, &formatted,
&allocated);
free(fmt);
result = xrealloc(result, result_len + a_len + formatted_len);
memcpy(result + result_len, a, a_len);
memcpy(result + result_len + a_len, formatted, formatted_len);
result_len += a_len + formatted_len;
len -= c + 1 - a;
a = c + 1;
}

if (result && len) {
result = xrealloc(result, result_len + len);
memcpy(result + result_len, a, len);
result_len += len;
}

*sizep = result_len;

return result;
}

static void *convert_to_archive(const char *path,
const void *src, unsigned long *sizep,
const struct commit *commit)
{
static struct git_attr *attr_export_subst;
struct git_attr_check check[1];

if (!commit)
return NULL;

if (!attr_export_subst)
attr_export_subst = git_attr("export-subst", 12);

check[0].attr = attr_export_subst;
if (git_checkattr(path, ARRAY_SIZE(check), check))
return NULL;
if (!ATTR_TRUE(check[0].value))
return NULL;

return format_subst(commit, src, sizep);
}

void *sha1_file_to_archive(const char *path, const unsigned char *sha1,
unsigned int mode, enum object_type *type,
unsigned long *size,
const struct commit *commit)
{
void *buffer, *converted;

buffer = read_sha1_file(sha1, type, size);
if (buffer && S_ISREG(mode)) {
converted = convert_to_working_tree(path, buffer, size);
if (converted) {
free(buffer);
buffer = converted;
}

converted = convert_to_archive(path, buffer, size, commit);
if (converted) {
free(buffer);
buffer = converted;
}
}

return buffer;
}

static int init_archiver(const char *name, struct archiver *ar)
{
int rv = -1, i;
Expand Down Expand Up @@ -109,7 +204,7 @@ void parse_treeish_arg(const char **argv, struct archiver_args *ar_args,
const unsigned char *commit_sha1;
time_t archive_time;
struct tree *tree;
struct commit *commit;
const struct commit *commit;
unsigned char sha1[20];

if (get_sha1(name, sha1))
Expand Down Expand Up @@ -142,6 +237,7 @@ void parse_treeish_arg(const char **argv, struct archiver_args *ar_args,
}
ar_args->tree = tree;
ar_args->commit_sha1 = commit_sha1;
ar_args->commit = commit;
ar_args->time = archive_time;
}

Expand Down
2 changes: 1 addition & 1 deletion builtin-push.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

static const char push_usage[] = "git-push [--all] [--tags] [--receive-pack=<git-receive-pack>] [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]";

static int all, force, thin = 1, verbose;
static int all, force, thin, verbose;
static const char *receivepack;

static const char **refspec;
Expand Down
18 changes: 14 additions & 4 deletions builtin-tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ static ssize_t do_sign(char *buffer, size_t size, size_t max)
bracket[1] = '\0';
}

/* When the username signingkey is bad, program could be terminated
* because gpg exits without reading and then write gets SIGPIPE. */
signal(SIGPIPE, SIG_IGN);

memset(&gpg, 0, sizeof(gpg));
gpg.argv = args;
gpg.in = -1;
Expand All @@ -212,12 +216,17 @@ static ssize_t do_sign(char *buffer, size_t size, size_t max)
if (start_command(&gpg))
return error("could not run gpg.");

write_or_die(gpg.in, buffer, size);
if (write_in_full(gpg.in, buffer, size) != size) {
close(gpg.in);
finish_command(&gpg);
return error("gpg did not accept the tag data");
}
close(gpg.in);
gpg.close_in = 0;
len = read_in_full(gpg.out, buffer + size, max - size);

finish_command(&gpg);
if (finish_command(&gpg) || !len || len < 0)
return error("gpg failed to sign the tag");

if (len == max - size)
return error("could not read the entire signature from gpg.");
Expand Down Expand Up @@ -310,9 +319,10 @@ static void create_tag(const unsigned char *object, const char *tag,
size += header_len;

if (sign) {
size = do_sign(buffer, size, max_size);
if (size < 0)
ssize_t r = do_sign(buffer, size, max_size);
if (r < 0)
die("unable to sign the tag");
size = r;
}

if (write_sha1_file(buffer, size, tag_type, result) < 0)
Expand Down
1 change: 0 additions & 1 deletion cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,6 @@ extern void trace_argv_printf(const char **argv, int count, const char *format,
/* convert.c */
extern char *convert_to_git(const char *path, const char *src, unsigned long *sizep);
extern char *convert_to_working_tree(const char *path, const char *src, unsigned long *sizep);
extern void *convert_sha1_file(const char *path, const unsigned char *sha1, unsigned int mode, enum object_type *type, unsigned long *size);

/* diff.c */
extern int diff_auto_refresh_index;
Expand Down
Loading

0 comments on commit ddb95de

Please sign in to comment.