#include "run-command.h"
#include "exec_cmd.h"
+static inline void close_pair(int fd[2])
+{
+ close(fd[0]);
+ close(fd[1]);
+}
+
int start_command(struct child_process *cmd)
{
int need_in = !cmd->no_stdin && cmd->in < 0;
cmd->pid = fork();
if (cmd->pid < 0) {
- if (need_in) {
- close(fdin[0]);
- close(fdin[1]);
- }
+ if (need_in)
+ close_pair(fdin);
return -ERR_RUN_COMMAND_FORK;
}
close(fd);
} else if (need_in) {
dup2(fdin[0], 0);
- close(fdin[0]);
- close(fdin[1]);
+ close_pair(fdin);
} else if (cmd->in) {
dup2(cmd->in, 0);
close(cmd->in);
*/
#define ONELINE_SEEN (1u<<20)
-int get_sha1_oneline(const char *prefix, unsigned char *sha1)
+static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
{
struct commit_list *list = NULL, *backup = NULL, *l;
- struct commit *commit = NULL;
+ int retval = -1;
if (prefix[0] == '!') {
if (prefix[1] != '!')
commit_list_insert(l->item, &backup);
while (list) {
char *p;
+ struct commit *commit;
commit = pop_most_recent_commit(&list, ONELINE_SEEN);
- if (!commit)
- break;
parse_object(commit->object.sha1);
if (!commit->buffer || !(p = strstr(commit->buffer, "\n\n")))
continue;
if (!prefixcmp(p + 2, prefix)) {
hashcpy(sha1, commit->object.sha1);
+ retval = 0;
break;
}
}
free_commit_list(list);
for (l = backup; l; l = l->next)
clear_commit_marks(l->item, ONELINE_SEEN);
- return commit == NULL;
+ return retval;
}
/*
git add file2 &&
git commit -m add.file2 file2 &&
git bundle create bundle3 -1 HEAD &&
- sed "1,4d" < bundle3 > bundle.pack &&
+ (
+ while read x && test -n "$x"
+ do
+ :;
+ done
+ cat
+ ) <bundle3 >bundle.pack &&
git index-pack bundle.pack &&
test 4 = $(git verify-pack -v bundle.pack | wc -l)
'