commit 5e54fb308c7ad735d944068c063de6ac5276b93a from: Stefan Sperling date: Fri May 31 13:01:03 2019 UTC test and fix 'got revert' with a path in a sub-directory Relax input path requirements of got_object_id_by_path() to make things easier to callers. Allows the revert code to pass a path from the file index in lieu of a repository path. commit - f6d88e1a0cac5d10deaafff839c36f2a9860dd8c commit + 5e54fb308c7ad735d944068c063de6ac5276b93a blob - 8491d04ea6102f5ea80a92987aebf4b3dc4e1f37 blob + 1c9eb57ad51151c9e4e3a1f258c9a1cd977fa114 --- lib/object.c +++ lib/object.c @@ -1383,17 +1383,13 @@ got_object_id_by_path(struct got_object_id **id, struc size_t seglen; *id = NULL; - - /* We are expecting an absolute in-repository path. */ - if (path[0] != '/') - return got_error(GOT_ERR_NOT_ABSPATH); err = got_object_open_as_commit(&commit, repo, commit_id); if (err) goto done; /* Handle opening of root of commit's tree. */ - if (path[1] == '\0') { + if (got_path_is_root_dir(path)) { *id = got_object_id_dup(commit->tree_id); if (*id == NULL) err = got_error_from_errno("got_object_id_dup"); @@ -1405,7 +1401,8 @@ got_object_id_by_path(struct got_object_id **id, struc goto done; s = path; - s++; /* skip leading '/' */ + while (s[0] == '/') + s++; seg = s; seglen = 0; while (*s) { blob - 584c34ece375b5bcf37239b7a0182a3c669c81a2 blob + eec57c20d733b805cc1aa054046717a7aadac832 --- regress/cmdline/revert.sh +++ regress/cmdline/revert.sh @@ -26,11 +26,11 @@ function test_revert_basic { return 1 fi - echo "modified alpha" > $testroot/wt/alpha + echo "modified epsilon/zeta" > $testroot/wt/epsilon/zeta - echo 'R alpha' > $testroot/stdout.expected + echo 'R epsilon/zeta' > $testroot/stdout.expected - (cd $testroot/wt && got revert alpha > $testroot/stdout) + (cd $testroot/wt && got revert epsilon/zeta > $testroot/stdout) cmp -s $testroot/stdout.expected $testroot/stdout ret="$?" @@ -40,8 +40,8 @@ function test_revert_basic { return 1 fi - echo "alpha" > $testroot/content.expected - cat $testroot/wt/alpha > $testroot/content + echo "zeta" > $testroot/content.expected + cat $testroot/wt/epsilon/zeta > $testroot/content cmp -s $testroot/content.expected $testroot/content ret="$?"