diff options
| author | William Bain <bain.william.a@gmail.com> | 2017-05-03 11:20:57 -0600 |
|---|---|---|
| committer | William Bain <bain.william.a@gmail.com> | 2017-05-05 09:46:56 -0600 |
| commit | 8b107dc5e1cd0745628e2bfb473477342c719f25 (patch) | |
| tree | f8a8de71ab98716613135cc1497c43876165e232 /src | |
| parent | 7849e467579f64ccbbfdc4463af97a215d1ac8e3 (diff) | |
| download | libgit2-8b107dc5e1cd0745628e2bfb473477342c719f25.tar.gz | |
revparse: support open-ended ranges
Support '..' and '...' ranges where one side is not specified.
The unspecified side defaults to HEAD.
Closes #4223
Diffstat (limited to 'src')
| -rw-r--r-- | src/revparse.c | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/src/revparse.c b/src/revparse.c index d5511b47b..fd6bd1ea6 100644 --- a/src/revparse.c +++ b/src/revparse.c @@ -892,6 +892,17 @@ int git_revparse( const char *rstr; revspec->flags = GIT_REVPARSE_RANGE; + /* + * Following git.git, don't allow '..' because it makes command line + * arguments which can be either paths or revisions ambiguous when the + * path is almost certainly intended. The empty range '...' is still + * allowed. + */ + if (!git__strcmp(spec, "..")) { + giterr_set(GITERR_INVALID, "Invalid pattern '..'"); + return GIT_EINVALIDSPEC; + } + lstr = git__substrdup(spec, dotdot - spec); rstr = dotdot + 2; if (dotdot[2] == '.') { @@ -899,9 +910,17 @@ int git_revparse( rstr++; } - error = git_revparse_single(&revspec->from, repo, lstr); - if (!error) - error = git_revparse_single(&revspec->to, repo, rstr); + error = git_revparse_single( + &revspec->from, + repo, + *lstr == '\0' ? "HEAD" : lstr); + + if (!error) { + error = git_revparse_single( + &revspec->to, + repo, + *rstr == '\0' ? "HEAD" : rstr); + } git__free((void*)lstr); } else { |
