commit: Drop the ability to --add --remove

This forces us to have two code paths for doing a commit; let's just
drop this ability for now since it's not very useful.
This commit is contained in:
Colin Walters 2011-11-08 18:11:42 -05:00
parent 1ba3a67eb5
commit 2be1407622
3 changed files with 57 additions and 94 deletions

View File

@ -38,8 +38,6 @@ static char *subject;
static char *body; static char *body;
static char *parent; static char *parent;
static char *branch; static char *branch;
static char **additions;
static char **removals;
static GOptionEntry options[] = { static GOptionEntry options[] = {
{ "subject", 's', 0, G_OPTION_ARG_STRING, &subject, "One line subject", "subject" }, { "subject", 's', 0, G_OPTION_ARG_STRING, &subject, "One line subject", "subject" },
@ -52,8 +50,6 @@ static GOptionEntry options[] = {
{ "from-stdin", 0, 0, G_OPTION_ARG_NONE, &from_stdin, "Read new tree files from stdin", "file descriptor" }, { "from-stdin", 0, 0, G_OPTION_ARG_NONE, &from_stdin, "Read new tree files from stdin", "file descriptor" },
{ "from-file", 0, 0, G_OPTION_ARG_FILENAME, &from_file, "Read new tree files from another file", "path" }, { "from-file", 0, 0, G_OPTION_ARG_FILENAME, &from_file, "Read new tree files from another file", "path" },
{ "separator-null", 0, 0, G_OPTION_ARG_NONE, &separator_null, "", "Use '\\0' as filename separator, as with find -print0" }, { "separator-null", 0, 0, G_OPTION_ARG_NONE, &separator_null, "", "Use '\\0' as filename separator, as with find -print0" },
{ "add", 'a', 0, G_OPTION_ARG_FILENAME_ARRAY, &additions, "Relative file path to add", "filename" },
{ "remove", 'r', 0, G_OPTION_ARG_FILENAME_ARRAY, &removals, "Relative file path to remove", "filename" },
{ NULL } { NULL }
}; };
@ -196,16 +192,15 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
gboolean ret = FALSE; gboolean ret = FALSE;
OstreeRepo *repo = NULL; OstreeRepo *repo = NULL;
char *dir = NULL; char *dir = NULL;
gboolean using_filename_cmdline;
gboolean using_filedescriptors;
GPtrArray *additions_array = NULL;
GPtrArray *removals_array = NULL;
GChecksum *commit_checksum = NULL; GChecksum *commit_checksum = NULL;
char **iter;
char separator; char separator;
GVariant *metadata = NULL; GVariant *metadata = NULL;
GMappedFile *metadata_mappedf = NULL; GMappedFile *metadata_mappedf = NULL;
GFile *metadata_f = NULL; GFile *metadata_f = NULL;
gboolean temp_fd = -1;
int pipefd[2] = { -1, -1 };
GOutputStream *out = NULL;
FindThreadData fdata;
context = g_option_context_new ("[DIR] - Commit a new revision"); context = g_option_context_new ("[DIR] - Commit a new revision");
g_option_context_add_main_entries (context, options, NULL); g_option_context_add_main_entries (context, options, NULL);
@ -258,16 +253,6 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
if (!ostree_repo_check (repo, error)) if (!ostree_repo_check (repo, error))
goto out; goto out;
using_filename_cmdline = (removals || additions);
using_filedescriptors = (from_file || from_fd >= 0 || from_stdin);
if (using_filename_cmdline && using_filedescriptors)
{
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
"File descriptors may not be combined with --add or --remove");
goto out;
}
if (!branch) if (!branch)
{ {
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
@ -282,59 +267,26 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
goto out; goto out;
} }
if (using_filename_cmdline) if (!(from_file || from_fd >= 0 || from_stdin))
{ {
g_assert (removals || additions); /* We're using the current directory */
additions_array = g_ptr_array_new ();
removals_array = g_ptr_array_new ();
if (additions)
for (iter = additions; *iter; iter++)
g_ptr_array_add (additions_array, *iter);
if (removals)
for (iter = removals; *iter; iter++)
g_ptr_array_add (removals_array, *iter);
if (!ostree_repo_commit (repo, branch, parent, subject, body, metadata,
dir, additions_array,
removals_array,
&commit_checksum,
error))
goto out;
} }
else if (using_filedescriptors)
{
gboolean temp_fd = -1;
if (from_stdin) if (from_stdin)
from_fd = 0; from_fd = 0;
else if (from_file) else if (from_file)
{
temp_fd = ot_util_open_file_read (from_file, error);
if (temp_fd < 0)
{ {
temp_fd = ot_util_open_file_read (from_file, error); g_prefix_error (error, "Failed to open '%s': ", from_file);
if (temp_fd < 0)
{
g_prefix_error (error, "Failed to open '%s': ", from_file);
goto out;
}
from_fd = temp_fd;
}
if (!ostree_repo_commit_from_filelist_fd (repo, branch, parent, subject, body, metadata,
dir, from_fd, separator,
&commit_checksum, error))
{
if (temp_fd >= 0)
close (temp_fd);
goto out; goto out;
} }
if (temp_fd >= 0) from_fd = temp_fd;
close (temp_fd);
} }
else else
{ {
int pipefd[2];
GOutputStream *out;
FindThreadData fdata;
if (pipe (pipefd) < 0) if (pipe (pipefd) < 0)
{ {
ot_util_set_error_from_errno (error, errno); ot_util_set_error_from_errno (error, errno);
@ -342,6 +294,7 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
} }
out = (GOutputStream*)g_unix_output_stream_new (pipefd[1], TRUE); out = (GOutputStream*)g_unix_output_stream_new (pipefd[1], TRUE);
from_fd = pipefd[0];
fdata.dir = ot_util_new_file_for_path (dir); fdata.dir = ot_util_new_file_for_path (dir);
fdata.separator = separator; fdata.separator = separator;
@ -351,27 +304,30 @@ ostree_builtin_commit (int argc, char **argv, const char *repo_path, GError **er
if (g_thread_create_full (find_thread, &fdata, 0, FALSE, FALSE, G_THREAD_PRIORITY_NORMAL, error) == NULL) if (g_thread_create_full (find_thread, &fdata, 0, FALSE, FALSE, G_THREAD_PRIORITY_NORMAL, error) == NULL)
goto out; goto out;
if (!ostree_repo_commit_from_filelist_fd (repo, branch, parent, subject, body, metadata, out = NULL;
dir, pipefd[0], separator,
&commit_checksum, error))
goto out;
(void)close (pipefd[0]);
} }
if (!ostree_repo_commit_from_filelist_fd (repo, branch, parent, subject, body, metadata,
dir, from_fd, separator,
&commit_checksum, error))
goto out;
ret = TRUE; ret = TRUE;
g_print ("%s\n", g_checksum_get_string (commit_checksum)); g_print ("%s\n", g_checksum_get_string (commit_checksum));
out: out:
g_clear_object (&out);
if (temp_fd >= 0)
(void)close (temp_fd);
if (pipefd[0] > 0)
(void) close (pipefd[0]);
if (pipefd[1] > 0)
(void) close (pipefd[1]);
g_free (dir); g_free (dir);
if (metadata_mappedf) if (metadata_mappedf)
g_mapped_file_unref (metadata_mappedf); g_mapped_file_unref (metadata_mappedf);
if (context) if (context)
g_option_context_free (context); g_option_context_free (context);
g_clear_object (&repo); g_clear_object (&repo);
if (removals_array)
g_ptr_array_free (removals_array, TRUE);
if (additions_array)
g_ptr_array_free (additions_array, TRUE);
if (commit_checksum) if (commit_checksum)
g_checksum_free (commit_checksum); g_checksum_free (commit_checksum);
return ret; return ret;

View File

@ -63,12 +63,28 @@ setup_test_repository () {
oldpwd=`pwd` oldpwd=`pwd`
cd ${test_tmpdir}
mkdir repo
cd repo
ot_repo="--repo=`pwd`"
export OSTREE="ostree ${ot_repo}"
if test "$mode" = "archive"; then
$OSTREE init --archive
else
$OSTREE init
fi
cd ${test_tmpdir}
mkdir files mkdir files
cd files cd files
ot_files=`pwd` ot_files=`pwd`
export ht_files export ht_files
ln -s nosuchfile somelink ln -s nosuchfile somelink
echo first > firstfile echo first > firstfile
cd ${test_tmpdir}/files
$OSTREE commit -b test2 -s "Test Commit 1" -m "Commit body first"
mkdir baz mkdir baz
echo moo > baz/cow echo moo > baz/cow
echo alien > baz/saucer echo alien > baz/saucer
@ -78,19 +94,8 @@ setup_test_repository () {
mkdir baz/another/ mkdir baz/another/
echo x > baz/another/y echo x > baz/another/y
cd ${test_tmpdir} cd ${test_tmpdir}/files
mkdir repo $OSTREE commit -b test2 -s "Test Commit 2" -m "Commit body second"
cd repo
ot_repo="--repo=`pwd`"
export OSTREE="ostree ${ot_repo}"
cd ../files
if test "$mode" = "archive"; then
$OSTREE init --archive
else
$OSTREE init
fi
$OSTREE commit -b test2 -s "Test Commit 1" -m "Commit body first" --add=firstfile --add=somelink
$OSTREE commit -b test2 -s "Test Commit 2" -m "Commit body second" --add=baz/cow --add=baz/saucer --add=baz/deeper/ohyeah --add=baz/another/y --add=baz/alink
$OSTREE fsck -q $OSTREE fsck -q
cd $oldpwd cd $oldpwd
@ -108,13 +113,13 @@ setup_fake_remote_repo1() {
mkdir baz mkdir baz
echo moo > baz/cow echo moo > baz/cow
echo alien > baz/saucer echo alien > baz/saucer
find | grep -v '^\.$' | ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s "A remote commit" -m "Some Commit body" --from-stdin ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s "A remote commit" -m "Some Commit body"
mkdir baz/deeper mkdir baz/deeper
ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s "Add deeper" --add=baz/deeper ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s "Add deeper"
echo hi > baz/deeper/ohyeah echo hi > baz/deeper/ohyeah
mkdir baz/another/ mkdir baz/another/
echo x > baz/another/y echo x > baz/another/y
find | grep -v '^\.$' | ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s "The rest" --from-stdin ostree --repo=${test_tmpdir}/ostree-srv/gnomerepo commit -b main -s "The rest"
cd .. cd ..
rm -rf gnomerepo-files rm -rf gnomerepo-files

View File

@ -47,8 +47,9 @@ assert_file_has_content baz/cow moo
assert_has_file baz/deeper/ohyeah assert_has_file baz/deeper/ohyeah
echo "ok content" echo "ok content"
$OSTREE commit -b test2 -s delete -r firstfile rm firstfile
assert_has_file firstfile # It should still exist in this checkout $OSTREE commit -b test2 -s delete
cd $test_tmpdir cd $test_tmpdir
$OSTREE checkout test2 $test_tmpdir/checkout-test2-2 $OSTREE checkout test2 $test_tmpdir/checkout-test2-2
cd $test_tmpdir/checkout-test2-2 cd $test_tmpdir/checkout-test2-2
@ -95,13 +96,14 @@ echo "ok cwd contents"
cd ${test_tmpdir}/checkout-test2-4 cd ${test_tmpdir}/checkout-test2-4
echo afile > oh-look-a-file echo afile > oh-look-a-file
cat > ostree-commit-metadata <<EOF cat > ${test_tmpdir}/ostree-commit-metadata <<EOF
{'origin': <'http://example.com'>, 'buildid': <@u 42>} {'origin': <'http://example.com'>, 'buildid': <@u 42>}
EOF EOF
$OSTREE commit -b test2 -s "Metadata test" --metadata-variant-text=./ostree-commit-metadata --add=oh-look-a-file $OSTREE commit -b test2 -s "Metadata test" --metadata-variant-text=${test_tmpdir}/ostree-commit-metadata
rm ostree-commit-metadata
echo "ok metadata commit" echo "ok metadata commit"
cd ${test_tmpdir}
rm ostree-commit-metadata
$OSTREE show test2 > ${test_tmpdir}/show $OSTREE show test2 > ${test_tmpdir}/show
assert_file_has_content ${test_tmpdir}/show 'example.com' assert_file_has_content ${test_tmpdir}/show 'example.com'
assert_file_has_content ${test_tmpdir}/show 'buildid' assert_file_has_content ${test_tmpdir}/show 'buildid'