summaryrefslogtreecommitdiff
path: root/bundle.c
Commit message (Collapse)AuthorAgeFilesLines
* object_array_entry: fix memory handling of the name fieldMichael Haggerty2013-06-021-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Previously, the memory management of the object_array_entry::name field was inconsistent and undocumented. object_array_entries are ultimately created by a single function, add_object_array_with_mode(), which has an argument "const char *name". This function used to simply set the name field to reference the string pointed to by the name parameter, and nobody on the object_array side ever freed the memory. Thus, it assumed that the memory for the name field would be managed by the caller, and that the lifetime of that string would be at least as long as the lifetime of the object_array_entry. But callers were inconsistent: * Some passed pointers to constant strings or argv entries, which was OK. * Some passed pointers to newly-allocated memory, but didn't arrange for the memory ever to be freed. * Some passed the return value of sha1_to_hex(), which is a pointer to a statically-allocated buffer that can be overwritten at any time. * Some passed pointers to refnames that they received from a for_each_ref()-type iteration, but the lifetimes of such refnames is not guaranteed by the refs API. Bring consistency to this mess by changing object_array to make its own copy for the object_array_entry::name field and free this memory when an object_array_entry is deleted from the array. Many callers were passing the empty string as the name parameter, so as a performance optimization, treat the empty string specially. Instead of making a copy, store a pointer to a statically-allocated empty string to object_array_entry::name. When deleting such an entry, skip the free(). Change the callers that were already passing copies to add_object_array_with_mode() to either skip the copy, or (if the memory needed to be allocated anyway) freeing the memory itself. A part of this commit effectively reverts 70d26c6e76 read_revisions_from_stdin: make copies for handle_revision_arg because the copying introduced by that commit (which is still necessary) is now done at a deeper level. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* bundle: Accept prerequisites without commit messagesLukas Fleischer2013-04-071-1/+1
| | | | | | | | | | | | | | | While explicitly stating that the commit message in a prerequisite line is optional, we required all lines with 40 or more characters to contain a space after the object name, bailing out if a line consisted of an object name only. This was to allow bundling a history to a commit without an message, but the code forgot that it already called rtrim() to remove that whitespace. As a workaround, only check for SP when the line has more than 40 characters. Signed-off-by: Lukas Fleischer <git@cryptocrack.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'jk/fully-peeled-packed-ref' into maint-1.8.1Junio C Hamano2013-04-031-3/+3
|\ | | | | | | | | | | | | | | * jk/fully-peeled-packed-ref: pack-refs: add fully-peeled trait pack-refs: write peeled entry for non-tags use parse_object_or_die instead of die("bad object") avoid segfaults on parse_object failure
| * avoid segfaults on parse_object failureJeff King2013-03-171-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Many call-sites of parse_object assume that they will get a non-NULL return value; this is not the case if we encounter an error while parsing the object. This patch adds a wrapper function around parse_object that handles dying automatically, and uses it anywhere we immediately try to access the return value as a non-NULL pointer (i.e., anywhere that we would currently segfault). This wrapper may also be useful in other places. The most obvious one is code like: o = parse_object(sha1); if (!o) die(...); However, these should not be mechanically converted to parse_object_or_die, as the die message is sometimes customized. Later patches can address these sites on a case-by-case basis. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | bundle: Add colons to list headings in "verify"Lukas Fleischer2013-03-081-4/+4
| | | | | | | | | | | | | | | | | | | | | | These slightly improve the reading flow by making it obvious that a list follows. Also, make the wording of both headings consistent by changing "contains %d ref(s)" to "contains this ref"/"contains these %d refs". Signed-off-by: Lukas Fleischer <git@cryptocrack.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | bundle: Fix "verify" output if history is completeLukas Fleischer2013-03-071-1/+1
|/ | | | | | | | | | | | | | A more informative message for "complete" bundles was added in commit 8c3710fd3011 (tweak "bundle verify" of a complete history, 2012-06-04). However, the prerequisites ref list is currently read *after* we check if it equals zero, which means we never actually use the number of prerequisite refs to decide when to print the newly introduced message. The code incorrectly uses the number of references recorded in the bundle instead. Signed-off-by: Lukas Fleischer <git@cryptocrack.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* tweak "bundle verify" of a complete historyJunio C Hamano2012-06-041-6/+10
| | | | | | | | | | | | | | | | | | | | | | | A bundle that records a complete history without prerequiste is a useful way to sneakernet the sources of your configuration files under your home directory, etc. E.g. $ GIT_DIR=/srv/git/homesrc.git git bundle create x.bndl HEAD master Running "git bundle verify" on such a "complete" bundle, however, gives somewhat a funny output. $ git bundle verify x.bndl The bundle contains 2 refs b2611f37ebc7ed6435a72d77fbc5f8b48a7d7146 HEAD b2611f37ebc7ed6435a72d77fbc5f8b48a7d7146 refs/heads/master The bundle requires these 0 refs x.bndl is okay Reword "requires these 0 refs" to say "The bundle records a complete history" instead. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'nd/i18n'Junio C Hamano2012-05-021-17/+21
|\ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | More message strings marked for i18n. By Nguyễn Thái Ngọc Duy (10) and Jonathan Nieder (1) * nd/i18n: help: replace underlining "help -a" headers using hyphens with a blank line i18n: bundle: mark strings for translation i18n: index-pack: mark strings for translation i18n: apply: update say_patch_name to give translators complete sentence i18n: apply: mark strings for translation i18n: remote: mark strings for translation i18n: make warn_dangling_symref() automatically append \n i18n: help: mark strings for translation i18n: mark relative dates for translation strbuf: convenience format functions with \n automatically appended Makefile: feed all header files to xgettext
| * i18n: bundle: mark strings for translationNguyễn Thái Ngọc Duy2012-04-241-17/+21
| | | | | | | | | | Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * Merge branch 'tr/maint-bundle-boundary'Junio C Hamano2012-03-061-1/+1
| |\ | | | | | | | | | | | | | | | | | | | | | By Thomas Rast * tr/maint-bundle-boundary: bundle: keep around names passed to add_pending_object() t5510: ensure we stay in the toplevel test dir t5510: refactor bundle->pack conversion
| * \ Merge branch 'tr/maint-bundle-long-subject'Junio C Hamano2012-02-261-26/+10
| |\ \ | | | | | | | | | | | | | | | | | | | | | | | | | | | | * tr/maint-bundle-long-subject: t5704: match tests to modern style strbuf: improve strbuf_get*line documentation bundle: use a strbuf to scan the log for boundary commits bundle: put strbuf_readline_fd in strbuf.c with adjustments
* | \ \ Sync with 1.7.8.6Junio C Hamano2012-04-261-1/+1
|\ \ \ \
| * \ \ \ Sync with 1.7.7.7Junio C Hamano2012-04-261-1/+1
| |\ \ \ \ | | |_|_|/ | |/| | |
| | * | | bundle: remove stray single-quote from error messageJonathan Nieder2012-04-261-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | After running rev-list --boundary to retrieve the list of boundary commits, "git bundle create" runs its own revision walk. If in this stage git encounters an unfamiliar option, it writes a message with an unbalanced quotation mark: error: unrecognized argument: --foo' Drop the stray quote to match the "unrecognized argument: %s" message used elsewhere and save translators some work. This is mostly a futureproofing measure: for now, the "rev-list --boundary" command catches most strange arguments on its own and the above message is not seen unless you try something esoteric like "git bundle create test.bundle --header HEAD". Reported-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | | | Merge branch 'tr/maint-bundle-boundary' into maintJunio C Hamano2012-03-121-1/+1
|\ \ \ \ \ | |/ / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | "git bundle" did not record boundary commits correctly when there are many of them. By Thomas Rast * tr/maint-bundle-boundary: bundle: keep around names passed to add_pending_object() t5510: ensure we stay in the toplevel test dir t5510: refactor bundle->pack conversion
| * | | | bundle: keep around names passed to add_pending_object()tr/maint-bundle-boundaryThomas Rast2012-03-011-1/+1
| | |_|/ | |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The 'name' field passed to add_pending_object() is used to later deduplicate in object_array_remove_duplicates(). git-bundle had a bug in this area since 18449ab (git-bundle: avoid packing objects which are in the prerequisites, 2007-03-08): it passed the name of each boundary object in a static buffer. In other words, all that object_array_remove_duplicates() saw was the name of the *last* added boundary object. The recent switch to a strbuf in bc2fed4 (bundle: use a strbuf to scan the log for boundary commits, 2012-02-22) made this slightly worse: we now free the buffer at the end, so it is not even guaranteed that it still points into addressable memory by the time object_array_remove_ duplicates looks at it. On the plus side however, it was now detectable by valgrind. The fix is easy: pass a copy of the string to add_pending_object. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | | Merge branch 'tr/maint-bundle-long-subject' into maintJunio C Hamano2012-03-041-26/+10
|\ \ \ \ | |/ / / | | | / | |_|/ |/| | | | | | | | | | | * tr/maint-bundle-long-subject: t5704: match tests to modern style strbuf: improve strbuf_get*line documentation bundle: use a strbuf to scan the log for boundary commits bundle: put strbuf_readline_fd in strbuf.c with adjustments
| * | bundle: use a strbuf to scan the log for boundary commitsThomas Rast2012-02-231-7/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The first part of the bundle header contains the boundary commits, and could be approximated by # v2 git bundle $(git rev-list --pretty=oneline --boundary <ARGS> | grep ^-) git-bundle actually spawns exactly this rev-list invocation, and does the grepping internally. There was a subtle bug in the latter step: it used fgets() with a 1024-byte buffer. If the user has sufficiently long subjects (e.g., by not adhering to the git oneline-subject convention in the first place), the 'oneline' format can easily overflow the buffer. fgets() then returns the rest of the line in the next call(s). If one of these remaining parts started with '-', git-bundle would mistakenly insert it into the bundle thinking it was a boundary commit. Fix it by using strbuf_getwholeline() instead, which handles arbitrary line lengths correctly. Note that on the receiving side in parse_bundle_header() we were already using strbuf_getwholeline_fd(), so that part is safe. Reported-by: Jannis Pohlmann <jannis.pohlmann@codethink.co.uk> Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | bundle: put strbuf_readline_fd in strbuf.c with adjustmentsThomas Rast2012-02-221-19/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | The comment even said that it should eventually go there. While at it, match the calling convention and name of the function to the strbuf_get*line family. So it now is strbuf_getwholeline_fd. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Merge branch 'maint'Junio C Hamano2012-01-031-2/+2
|\ \ \ | |/ / | | | | | | | | | | | | | | | | | | * maint: docs: describe behavior of relative submodule URLs fix hang in git fetch if pointed at a 0 length bundle Documentation: read-tree --prefix works with existing subtrees Add MYMETA.json to perl/.gitignore
| * | fix hang in git fetch if pointed at a 0 length bundleBrian Harring2012-01-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | git-repo if interupted at the exact wrong time will generate zero length bundles- literal empty files. git-repo is wrong here, but git fetch shouldn't effectively spin loop if pointed at a zero length bundle. Signed-off-by: Brian Harring <ferringb@chromium.org> Helped-by: Johannes Sixt Helped-by: Nguyen Thai Ngoc Duy Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Convert many resolve_ref() calls to read_ref*() and ref_exists()Nguyễn Thái Ngọc Duy2011-11-131-1/+1
|/ / | | | | | | | | | | | | | | | | | | | | | | | | | | resolve_ref() may return a pointer to a static buffer, which is not safe for long-term use because if another resolve_ref() call happens, the buffer may be changed. Many call sites though do not care about this buffer. They simply check if the return value is NULL or not. Convert all these call sites to new wrappers to reduce resolve_ref() calls from 57 to 34. If we change resolve_ref() prototype later on to avoid passing static buffer out, this helps reduce changes. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Merge branch 'jc/unseekable-bundle'Junio C Hamano2011-10-211-36/+88
|\ \ | | | | | | | | | | | | | | | | | | | | | | | | * jc/unseekable-bundle: bundle: add parse_bundle_header() helper function bundle: allowing to read from an unseekable fd Conflicts: transport.c
| * | bundle: add parse_bundle_header() helper functionjc/unseekable-bundleJunio C Hamano2011-10-131-8/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move most of the code from read_bundle_header() to parse_bundle_header() that takes a file descriptor that is already opened for reading, and make the former responsible only for opening the file and noticing errors. As a logical consequence of this, is_bundle() helper function can be implemented as a non-complaining variant of read_bundle_header() that does not return an open file descriptor, and can be used to tighten the check used to decide the use of bundle transport in transport_get() function. Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | bundle: allowing to read from an unseekable fdJunio C Hamano2011-10-131-35/+64
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We wished that "git bundle" to eventually learn to read from a network socket which is not seekable. The current code opens with fopen(), reads the file halfway and run ftell(), and reopens the same file with open() and seeks, to skip the header. This patch by itself does not reach that goal yet, but I think it is a right step in that direction. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | | Merge branch 'rs/pending'Junio C Hamano2011-10-131-7/+4
|\ \ \ | |_|/ |/| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * rs/pending: commit: factor out clear_commit_marks_for_object_array checkout: use leak_pending flag bundle: use leak_pending flag bisect: use leak_pending flag revision: add leak_pending flag checkout: use add_pending_{object,sha1} in orphan check revision: factor out add_pending_sha1 checkout: check for "Previous HEAD" notice in t2020 Conflicts: builtin/checkout.c revision.c
| * | commit: factor out clear_commit_marks_for_object_arrayrs/pendingRené Scharfe2011-10-031-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Factor out the code to clear the commit marks for a whole struct object_array from builtin/checkout.c into its own exported function clear_commit_marks_for_object_array and use it in bisect and bundle as well. It handles tags and commits and ignores objects of any other type. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
| * | bundle: use leak_pending flagRené Scharfe2011-10-031-5/+3
| |/ | | | | | | | | | | | | | | | | | | Instead of creating a copy of the list of pending objects, copy the struct object_array that points to it, turn on leak_pending, and thus cause prepare_revision_walk to leave it to us. And free it once we're done. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | Teach progress eye-candy to fetch_refs_from_bundle()Junio C Hamano2011-09-191-2/+5
|/ | | | | | | | | | | | | | | | With the usual "git" transport, a large-ish transfer with "git fetch" and "git pull" give progress eye-candy to avoid boring users. However, not when they are reading from a bundle. I.e. $ git pull ../git-bundle.bndl master This teaches bundle.c:unbundle() to give "-v" option to index-pack and tell it to give progress bar when transport decides it is necessary. The operation in the other direction, "git bundle create", could also learn to honor --quiet but that is a separate issue. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* bundle: Use OFS_DELTA in bundle filesShawn O. Pearce2011-02-061-2/+3
| | | | | | | | | | | | | | | | | | git-bundle first appeared in 2e0afafe ("Add git-bundle") in Feb 2007, and first shipped in Git 1.5.1. However, OFS_DELTA is an even earlier invention, coming about in eb32d236 ("introduce delta objects with offset to base") in Sep 2006, and first shipped in Git 1.4.4.5. OFS_DELTA is smaller, about 3.2%-5% smaller, and is typically faster to access than REF_DELTA because the exact location of the delta base is available after parsing the object header. Since all bundle aware versions of Git are also OFS_DELTA aware, just make it the default. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Acked-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* bundle: detect if bundle file cannot be createdCsaba Henk2010-08-271-2/+4
| | | | | | | | | | bundle command silently died with no sign of failure if it could not create the bundle file. (Eg.: its path resovles to a directory, or the parent dir is sticky while file already exists and is owned by someone else.) Signed-off-by: Csaba Henk <csaba@gluster.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'jc/log-stdin'Junio C Hamano2009-11-231-10/+2
|\ | | | | | | | | | | | | | | | | | | | | | | * jc/log-stdin: Add trivial tests for --stdin option to log family Make --stdin option to "log" family read also pathspecs setup_revisions(): do not call get_pathspec() too early Teach --stdin option to "log" family read_revision_from_stdin(): use strbuf Conflicts: revision.c
| * Teach --stdin option to "log" familyJunio C Hamano2009-11-201-10/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Move the logic to read revs from standard input that rev-list knows about from it to revision machinery, so that all the users of setup_revisions() can feed the list of revs from the standard input when "--stdin" is used on the command line. Allow some users of the revision machinery that want different semantics from the "--stdin" option to disable it by setting an option in the rev_info structure. This also cleans up the kludge made to bundle.c via cut and paste. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | pack-objects: split implications of --all-progress from progress activationNicolas Pitre2009-11-231-1/+1
|/ | | | | | | | | | | | | | | | | | | Currently the --all-progress flag is used to use force progress display during the writing object phase even if output goes to stdout which is primarily the case during a push operation. This has the unfortunate side effect of forcing progress display even if stderr is not a terminal. Let's introduce the --all-progress-implied argument which has the same intent except for actually forcing the activation of any progress display. With this, progress display will be automatically inhibited whenever stderr is not a terminal, or full progress display will be included otherwise. This should let people use 'git push' within a cron job without filling their logs with useless percentage displays. Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Tested-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* don't dereference NULL upon fdopen failureJim Meyering2009-09-131-1/+1
| | | | | | | | There were several unchecked use of fdopen(); replace them with xfdopen() that checks and dies. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Terminate argv with NULL before calling setup_revisions()Nguyễn Thái Ngọc Duy2009-05-211-1/+1
| | | | | | | | | | | It is convention that argv should be terminated with NULL, even if argc is used to specify the size of argv. setup_revisions() requires this and may segfault otherwise. This patch makes sure that all argv (that I can find) is NULL terminated. Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'js/maint-all-implies-HEAD'Junio C Hamano2009-01-251-0/+2
|\ | | | | | | | | | | * js/maint-all-implies-HEAD: bundle: allow the same ref to be given more than once revision walker: include a detached HEAD in --all
| * bundle: allow the same ref to be given more than onceJunio C Hamano2009-01-171-0/+2
| | | | | | | | | | | | | | | | "git bundle create x master master" used to create a bundle that lists the same branch (master) twice. Cloning from such a bundle resulted in a needless warning "warning: Duplicated ref: refs/remotes/origin/master". Signed-off-by: Junio C Hamano <gitster@pobox.com>
* | bundle: allow rev-list options to exclude annotated tagsJohannes Schindelin2009-01-051-0/+32
|/ | | | | | | | | | | With options such as "--all --since=2.weeks.ago", annotated tags used to be included, when they should have been excluded. The reason is that we heavily abuse the revision walker to determine what needs to be included or excluded. And the revision walker does not show tags at all (and therefore never marks tags as uninteresting). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Fix non-literal format in printf-style callsDaniel Lowe2008-11-111-2/+2
| | | | | | | | | | These were found using gcc 4.3.2-1ubuntu11 with the warning: warning: format not a string literal and no format arguments Incorporated suggestions from Brandon Casey <casey@nrlssc.navy.mil>. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Enhance hold_lock_file_for_{update,append}() APIJunio C Hamano2008-10-191-1/+2
| | | | | | | | This changes the "die_on_error" boolean parameter to a mere "flags", and changes the existing callers of hold_lock_file_for_update/append() functions to pass LOCK_DIE_ON_ERROR. Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Teach git-bundle to read revision arguments from stdin like git-rev-list.Adam Brewster2008-07-071-2/+11
| | | | | | | | | | | | | This patch allows the caller to feed the revision parameters to git-bundle from its standard input. This way, a script do not have to worry about limitation of the length of command line. Documentation/git-bundle.txt says that git-bundle takes arguments acceptable to git-rev-list. Obviously some arguments that git-rev-list handles don't make sense for git-bundle (e.g. --bisect) but --stdin is pretty reasonable. Signed-off-by: Adam Brewster <adambrewster@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* start_command(), if .in/.out > 0, closes file descriptors, not the callersJohannes Sixt2008-02-231-2/+3
| | | | | | | | | | | | | | | | | | | Callers of start_command() can set the members .in and .out of struct child_process to a value > 0 to specify that this descriptor is used as the stdin or stdout of the child process. Previously, if start_command() was successful, this descriptor was closed upon return. Here we now make sure that the descriptor is also closed in case of failures. All callers are updated not to close the file descriptor themselves after start_command() was called. Note that earlier run_gpg_verify() of git-verify-tag set .out = 1, which worked because start_command() treated this as a special case, but now this is incorrect because it closes the descriptor. The intent here is to inherit stdout to the child, which is achieved by .out = 0. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* start_command(), .in/.out/.err = -1: Callers must close the file descriptorJohannes Sixt2008-02-231-0/+1
| | | | | | | | | | | | | | | By setting .in, .out, or .err members of struct child_process to -1, the callers of start_command() can request that a pipe is allocated that talks to the child process and one end is returned by replacing -1 with the file descriptor. Previously, a flag was set (for .in and .out, but not .err) to signal finish_command() to close the pipe end that start_command() had handed out, so it was optional for callers to close the pipe, and many already do so. Now we make it mandatory to close the pipe. Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* check return code of prepare_revision_walkMartin Koegler2008-02-171-1/+2
| | | | | | | | A failure in prepare_revision_walk can be caused by a not parseable object. Signed-off-by: Martin Koegler <mkoegler@auto.tuwien.ac.at> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Improve use of lockfile APIBrandon Casey2008-01-161-4/+10
| | | | | | | Remove remaining double close(2)'s. i.e. close() before commit_locked_index() or commit_lock_file(). Signed-off-by: Junio C Hamano <gitster@pobox.com>
* bundle, fast-import: detect write failureJim Meyering2008-01-101-3/+3
| | | | | | | | | | I noticed some unchecked writes. This fixes them. * bundle.c (create_bundle): Die upon write failure. * fast-import.c (keep_pack): Die upon write or close failure. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Don't access line[-1] for a zero-length "line" from fgets.Jim Meyering2008-01-041-1/+1
| | | | | | | | | | | | | | | A NUL byte at beginning of file, or just after a newline would provoke an invalid buf[-1] access in a few places. * builtin-grep.c (cmd_grep): Don't access buf[-1]. * builtin-pack-objects.c (get_object_list): Likewise. * builtin-rev-list.c (read_revisions_from_stdin): Likewise. * bundle.c (read_bundle_header): Likewise. * server-info.c (read_pack_info_file): Likewise. * transport.c (insert_packed_refs): Likewise. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
* Merge branch 'maint'Junio C Hamano2007-11-221-1/+8
| | | | | | * maint: Make test scripts executable. bundle create: keep symbolic refs' names instead of resolving them
* Style: place opening brace of a function definition at column 1Junio C Hamano2007-11-081-1/+2
| | | | Signed-off-by: Junio C Hamano <gitster@pobox.com>