diff options
| author | Carlos MartÃn Nieto <carlosmn@github.com> | 2017-05-20 14:13:27 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-05-20 14:13:27 +0200 |
| commit | 119bdd86582b3e98a107531def666c8ac7bb15b1 (patch) | |
| tree | 3ea399a45cccfc2ef2bfe53890382d5bfbc4cbe8 /src | |
| parent | 924f5d129ea826b9ce93dc62eb1a8d445788d832 (diff) | |
| parent | 8b107dc5e1cd0745628e2bfb473477342c719f25 (diff) | |
| download | libgit2-119bdd86582b3e98a107531def666c8ac7bb15b1.tar.gz | |
Merge pull request #4231 from wabain/open-revrange
revparse: support open-ended ranges
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 { |
