]> git.ipfire.org Git - thirdparty/git.git/blobdiff - bundle.c
Enhance hold_lock_file_for_{update,append}() API
[thirdparty/git.git] / bundle.c
index bd12ec8537781c5c82e77637312ccabb708d5040..7d17a1fde16204859849aaf28945739aaa685f91 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -178,6 +178,7 @@ int create_bundle(struct bundle_header *header, const char *path,
        int i, ref_count = 0;
        char buffer[1024];
        struct rev_info revs;
+       int read_from_stdin = 0;
        struct child_process rls;
        FILE *rls_fout;
 
@@ -185,7 +186,8 @@ int create_bundle(struct bundle_header *header, const char *path,
        if (bundle_to_stdout)
                bundle_fd = 1;
        else
-               bundle_fd = hold_lock_file_for_update(&lock, path, 1);
+               bundle_fd = hold_lock_file_for_update(&lock, path,
+                                                     LOCK_DIE_ON_ERROR);
 
        /* write signature */
        write_or_die(bundle_fd, bundle_signature, strlen(bundle_signature));
@@ -227,8 +229,16 @@ int create_bundle(struct bundle_header *header, const char *path,
 
        /* write references */
        argc = setup_revisions(argc, argv, &revs, NULL);
-       if (argc > 1)
-               return error("unrecognized argument: %s'", argv[1]);
+
+       for (i = 1; i < argc; i++) {
+               if (!strcmp(argv[i], "--stdin")) {
+                       if (read_from_stdin++)
+                               die("--stdin given twice?");
+                       read_revisions_from_stdin(&revs);
+                       continue;
+               }
+               return error("unrecognized argument: %s'", argv[i]);
+       }
 
        for (i = 0; i < revs.pending.nr; i++) {
                struct object_array_entry *e = revs.pending.objects + i;
@@ -333,10 +343,12 @@ int create_bundle(struct bundle_header *header, const char *path,
                write_or_die(rls.in, sha1_to_hex(object->sha1), 40);
                write_or_die(rls.in, "\n", 1);
        }
+       close(rls.in);
        if (finish_command(&rls))
                return error ("pack-objects died");
-
-       return bundle_to_stdout ? close(bundle_fd) : commit_lock_file(&lock);
+       if (!bundle_to_stdout)
+               commit_lock_file(&lock);
+       return 0;
 }
 
 int unbundle(struct bundle_header *header, int bundle_fd)