path: root/archive.h
AgeCommit message (Collapse)Author
2020-03-16convert: provide additional metadata to filtersbrian m. carlson
Now that we have the codebase wired up to pass any additional metadata to filters, let's collect the additional metadata that we'd like to pass. The two main places we pass this metadata are checkouts and archives. In these two situations, reading HEAD isn't a valid option, since HEAD isn't updated for checkouts until after the working tree is written and archives can accept an arbitrary tree. In other situations, HEAD will usually reflect the refname of the branch in current use. We pass a smaller amount of data in other cases, such as git cat-file, where we can really only logically know about the blob. This commit updates only the parts of the checkout code where we don't use unpack_trees. That function and callers of it will be handled in a future commit. In the archive code, we leak a small amount of memory, since nothing we pass in the archiver argument structure is freed. Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2019-05-13Merge branch 'dl/no-extern-in-func-decl'Junio C Hamano
Mechanically and systematically drop "extern" from function declarlation. * dl/no-extern-in-func-decl: *.[ch]: manually align parameter lists *.[ch]: remove extern from function declarations using sed *.[ch]: remove extern from function declarations using spatch
2019-05-05*.[ch]: manually align parameter listsDenton Liu
In previous patches, extern was mechanically removed from function declarations without care to formatting, causing parameter lists to be misaligned. Manually format changed sections such that the parameter lists should be realigned. Viewing this patch with 'git diff -w' should produce no output. Signed-off-by: Denton Liu <> Signed-off-by: Junio C Hamano <>
2019-05-05*.[ch]: remove extern from function declarations using spatchDenton Liu
There has been a push to remove extern from function declarations. Remove some instances of "extern" for function declarations which are caught by Coccinelle. Note that Coccinelle has some difficulty with processing functions with `__attribute__` or varargs so some `extern` declarations are left behind to be dealt with in a future patch. This was the Coccinelle patch used: @@ type T; identifier f; @@ - extern T f(...); and it was run with: $ git ls-files \*.{c,h} | grep -v ^compat/ | xargs spatch --sp-file contrib/coccinelle/noextern.cocci --in-place Files under `compat/` are intentionally excluded as some are directly copied from external sources and we should avoid churning them as much as possible. Signed-off-by: Denton Liu <> Signed-off-by: Junio C Hamano <>
2019-04-01archive: convert struct archiver_args to object_idbrian m. carlson
Change the commit_sha1 member to be called "commit_oid" and change it to be a pointer to struct object_id. Additionally, update some uses of GIT_SHA1_HEXSZ and hard-coded values to use the_hash_algo instead. Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2018-10-26archive: initialize archivers earlierJosh Steadmon
Initialize archivers as soon as possible when running git-archive. Various non-obvious behavior depends on having the archivers initialized, such as determining the desired archival format from the provided filename. Since 08716b3c11 ("archive: refactor file extension format-guessing", 2011-06-21), archive_format_from_filename() has used the registered archivers to match filenames (provided via --output) to archival formats. However, when git-archive is executed with --remote, format detection happens before the archivers have been registered. This causes archives from remotes to always be generated as TAR files, regardless of the actual filename (unless an explicit --format is provided). This patch fixes that behavior; archival format is determined properly from the output filename, even when --remote is used. Helped-by: Jeff King <> Signed-off-by: Josh Steadmon <> Signed-off-by: Junio C Hamano <>
2018-08-20Merge branch 'en/incl-forward-decl'Junio C Hamano
Code hygiene improvement for the header files. * en/incl-forward-decl: Remove forward declaration of an enum compat/precompose_utf8.h: use more common include guard style urlmatch.h: fix include guard Move definition of enum branch_track from cache.h to branch.h alloc: make allocate_alloc_state and clear_alloc_state more consistent Add missing includes and forward declarations
2018-08-15Add missing includes and forward declarationsElijah Newren
I looped over the toplevel header files, creating a temporary two-line C program for each consisting of #include "git-compat-util.h" #include $HEADER This patch is the result of manually fixing errors in compiling those tiny programs. Signed-off-by: Elijah Newren <> Signed-off-by: Junio C Hamano <>
2018-08-13archive.c: avoid access to the_indexNguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <> Signed-off-by: Junio C Hamano <>
2018-03-14archive: convert sha1_file_to_archive to struct object_idbrian m. carlson
Convert this function to take a pointer to struct object_id and rename it object_file_to_archive. Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2018-03-14archive: convert write_archive_entry_fn_t to object_idbrian m. carlson
Convert the write_archive_entry_fn_t type to use a pointer to struct object_id. Convert various static functions in the tar and zip archivers also. Signed-off-by: brian m. carlson <> Signed-off-by: Junio C Hamano <>
2017-04-27timestamp_t: a new data type for timestampsJohannes Schindelin
Git's source code assumes that unsigned long is at least as precise as time_t. Which is incorrect, and causes a lot of problems, in particular where unsigned long is only 32-bit (notably on Windows, even in 64-bit versions). So let's just use a more appropriate data type instead. In preparation for this, we introduce the new `timestamp_t` data type. By necessity, this is a very, very large patch, as it has to replace all timestamps' data type in one go. As we will use a data type that is not necessarily identical to `time_t`, we need to be very careful to use `time_t` whenever we interact with the system functions, and `timestamp_t` everywhere else. Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
2016-11-22archive: read local configurationJunio C Hamano
Since b9605bc4f2 ("config: only read .git/config from configured repos", 2016-09-12), we do not read from ".git/config" unless we know we are in a repository. "git archive" however didn't do the repository discovery and instead relied on the old behaviour. Teach the command to run a "gentle" version of repository discovery so that local configuration variables are honoured. [jc: stole tests from peff] Signed-off-by: Junio C Hamano <>
2013-07-15archive: convert to use parse_pathspecNguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <> Signed-off-by: Junio C Hamano <>
2012-05-03archive: delegate blob reading to backendNguyễn Thái Ngọc Duy
archive-tar.c and archive-zip.c now perform conversion check, with help of sha1_file_to_archive() from archive.c This gives backends more freedom in dealing with (streaming) large blobs. Signed-off-by: Nguyễn Thái Ngọc Duy <> Signed-off-by: Junio C Hamano <>
2011-06-22upload-archive: allow user to turn off filtersJeff King
Some tar filters may be very expensive to run, so sites do not want to expose them via upload-archive. This patch lets users configure tar.<filter>.remote to turn them off. By default, gzip filters are left on, as they are about as expensive as creating zip archives. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2011-06-22archive: move file extension format-guessing lowerJeff King
The process for guessing an archive output format based on the filename is something like this: a. parse --output in cmd_archive; check the filename against a static set of mapping heuristics (right now it just matches ".zip" for zip files). b. if found, stick a fake "--format=zip" at the beginning of the arguments list (if the user did specify a --format manually, the later option will override our fake one) c. if it's a remote call, ship the arguments to the remote (including the fake), which will call write_archive on their end d. if it's local, ship the arguments to write_archive locally There are two problems: 1. The set of mappings is static and at too high a level. The write_archive level is going to check config for user-defined formats, some of which will specify extensions. We need to delay lookup until those are parsed, so we can match against them. 2. For a remote archive call, our set of mappings (or formats) may not match the remote side's. This is OK in practice right now, because all versions of git understand "zip" and "tar". But as new formats are added, there is going to be a mismatch between what the client can do and what the remote server can do. To fix (1), this patch refactors the location guessing to happen at the write_archive level, instead of the cmd_archive level. So instead of sticking a fake --format field in the argv list, we actually pass a "name hint" down the callchain; this hint is used at the appropriate time to guess the format (if one hasn't been given already). This patch leaves (2) unfixed. The name_hint is converted to a "--format" option as before, and passed to the remote. This means the local side's idea of how extensions map to formats will take precedence. Another option would be to pass the name hint to the remote side and let the remote choose. This isn't a good idea for two reasons: 1. There's no room in the protocol for passing that information. We can pass a new argument, but older versions of git on the server will choke on it. 2. Letting the remote side decide creates a silent inconsistency in user experience. Consider the case that the locally installed git knows about the "tar.gz" format, but a remote server doesn't. Running "git archive -o foo.tar.gz" will use the tar.gz format. If we use --remote, and the local side chooses the format, then we send "--format=tar.gz" to the remote, which will complain about the unknown format. But if we let the remote side choose the format, then it will realize that it doesn't know about "tar.gz" and output uncompressed tar without even issuing a warning. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2011-06-22archive: pass archiver struct to write_archive callbackJeff King
The current archivers are very static; when you are in the write_tar_archive function, you know you are writing a tar. However, to facilitate runtime-configurable archivers that will share a common write function we need to tell the function which archiver was used. As a convenience, we also provide an opaque data pointer in the archiver struct so that individual archivers can put something useful there when they register themselves. Technically they could just use the "name" field to look in an internal map of names to data, but this is much simpler. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2011-06-22archive: refactor list of archive formatsJeff King
Most of the tar and zip code was nicely split out into two abstracted files which knew only about their specific formats. The entry point to this code was a single "write archive" function. However, as these basic formats grow more complex (e.g., by handling multiple file extensions and format names), a static list of the entry point functions won't be enough. Instead, let's provide a way for the tar and zip code to tell the main archive code what they support by registering archiver names and functions. Signed-off-by: Jeff King <> Signed-off-by: Junio C Hamano <>
2009-04-18archive: do not read .gitattributes in working directoryNguyễn Thái Ngọc Duy
The old behaviour still remains with --worktree-attributes, and it is always on for the legacy "git tar-tree". Signed-off-by: Nguyễn Thái Ngọc Duy <> Signed-off-by: Junio C Hamano <>
2008-07-26archive: declare struct archiver where it's neededRene Scharfe
Move the declaration of struct archiver to archive.c, as this is the only file left where it is used. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-26archive: define MAX_ARGS where it's neededRene Scharfe
MAX_EXTRA_ARGS is not used anymore, so remove it. MAX_ARGS is used only in builtin-upload-archive.c, so define it there. Also report the actual value we're comparing against when the number of args is too big. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-26archive: move parameter parsing code to archive.cRene Scharfe
write_archive() in archive.c is the only callsite for the command line parsing functions located in builtin-archive.c. Move them to the place where they are used, un-export them and make them static, as hinted at by Stephan. Cc: Stephan Beyer <> Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-26archive: add write_archive()Rene Scharfe
Both archive and upload-archive have to parse command line arguments and then call the archiver specific write function. Move the duplicate code to a new function, write_archive(). Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-19archive: make zip compression level independent from core gitRené Scharfe
zlib_compression_level is the compression level used for git's object store. It's 1 by default, which is the fastest setting. This variable is also used as the default compression level for ZIP archives created by git archive. For archives, however, zlib's own default of 6 is more appropriate, as it's favouring small size over speed -- archive creation is not that performance critical most of the time. This patch makes git archive independent from git's internal compression level setting. It affects invocations of git archive without explicitly specified compression level option, only. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-15archive: remove extra arguments parsing codeRené Scharfe
Replace the code that calls backend specific argument parsers by a simple flag mechanism. This reduces code size and complexity. We can add back such a mechanism (based on incremental parse_opt(), perhaps) when we need it. The compression level parameter, though, is going to be shared by future compressing backends like tgz. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-15archive: unify file attribute handlingRené Scharfe
Now that all file attribute handling for git archive has moved to archive.c, we can unexport sha1_file_to_archive() and is_archive_path_ignored() even disappears. Add setup_archive_check(), modelled after similar functions used in the code of other commands that support multiple file attributes. Also remove convert_to_archive(), as it's only remaining function with attribute handling gone was to call format_subst() if commit was not NULL, which is now checked in sha1_file_to_archive(). Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-15archive: centralize archive entry writingRené Scharfe
Add the exported function write_archive_entries() to archive.c, which uses the new ability of read_tree_recursive() to pass a context pointer to its callback in order to centralize previously duplicated code. The new callback function write_archive_entry() does the work that every archiver backend needs to do: loading file contents, entering subdirectories, handling file attributes, constructing the full path of the entry. All that done, it calls the backend specific write_archive_entry_fn_t function. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-15archive: add baselen member to struct archiver_argsRené Scharfe
Calculate the length of base and save it in a new member of struct archiver_args. This way we don't have to compute it in each of the format backends. Note: parse_archive_args() guarantees that ->base won't ever be NULL. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-07-15archive: remove args member from struct archiverRené Scharfe
Pass struct archiver and struct archiver_args explicitly to parse_archive_args and remove the latter from the former. This allows us to get rid of struct archiver_desc and simplifies the code a bit. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2008-06-09Teach new attribute 'export-ignore' to git-archiveRené Scharfe
Paths marked with this attribute are not output to git-archive output. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2007-09-03archive: specfile support (--pretty=format: in archive files)René Scharfe
Add support for a new attribute, specfile. Files marked as being specfiles are expanded by git-archive when they are written to an archive. It has no effect on worktree files. The same placeholders as those for the option --pretty=format: of git-log et al. can be used. The attribute is useful for creating auto-updating specfiles. It is limited by the underlying function format_commit_message(), though. E.g. currently there is no placeholder for git-describe like output, and expanded specfiles can't contain NUL bytes. That can be fixed in format_commit_message() later and will then benefit users of git-log, too. Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2006-11-05Remove unsupported C99 style struct initializers in git-archive.v1.4.3.4Shawn O. Pearce
At least one older version of the Solaris C compiler doesn't support the newer C99 style struct initializers. To allow Git to compile on those systems use an archive description struct which is easier to initialize without the C99 struct initializer syntax. Also since the archives array is not used by anyone other than archive.c we can make it static. Signed-off-by: Shawn O. Pearce <> Signed-off-by: Junio C Hamano <>
2006-09-10Add --verbose to git-archiveJunio C Hamano
And teach backends about it. Signed-off-by: Junio C Hamano <> (cherry picked from 9e2c44a2893ae90944a0b7c9f40a9d22b759b5c0 commit)
2006-09-10archive: allow remote to have more formats than we understand.Junio C Hamano
This fixes git-archive --remote not to parse archiver arguments; otherwise if the remote end implements formats other than the one known locally we will not be able to access that format. Signed-off-by: Junio C Hamano <>
2006-09-09git-archive: make compression level of ZIP archives configurableRene Scharfe
Signed-off-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2006-09-09git-archive: wire up ZIP format.Franck Bui-Huu
Again, this is based on Rene Scharfe's earlier patch, but uses the archiver support introduced by the previous patch. Signed-off-by: Franck Bui-Huu <> Acked-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2006-09-09git-archive: wire up TAR format.Franck Bui-Huu
This is based on Rene Scharfe's earlier patch, but uses the archiver support introduced by the previous patch. Signed-off-by: Franck Bui-Huu <> Acked-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>
2006-09-09Add git-archiveFranck Bui-Huu
git-archive is a command to make TAR and ZIP archives of a git tree. It helps prevent a proliferation of git-{format}-tree commands. Instead of directly calling git-{tar,zip}-tree command, it defines a very simple API, that archiver should implement and register in "git-archive.c". This API is made up by 2 functions whose prototype is defined in "archive.h" file. - The first one is used to parse 'extra' parameters which have signification only for the specific archiver. That would allow different archive backends to have different kind of options. - The second one is used to ask to an archive backend to build the archive given some already resolved parameters. The main reason for making this API is to avoid using git-{tar,zip}-tree commands, hence making them useless. Maybe it's time for them to die ? It also implements remote operations by defining a very simple protocol: it first sends the name of the specific uploader followed the repository name (git-upload-tar git:// Then it sends options. It's done by sending a sequence of one argument per packet, with prefix "argument ", followed by a flush. The remote protocol is implemented in "git-archive.c" for client side and is triggered by "--remote=<repo>" option. For example, to fetch a TAR archive in a remote repo, you can issue: $ git archive --format=tar --remote=git://xxx/yyy/zzz.git HEAD We choose to not make a new command "git-fetch-archive" for example, avoind one more GIT command which should be nice for users (less commands to remember, keeps existing --remote option). Signed-off-by: Franck Bui-Huu <> Acked-by: Rene Scharfe <> Signed-off-by: Junio C Hamano <>