commit 30837e32b8c05d75e429f5587a658d6df7ddfda8 from: Stefan Sperling date: Thu Jul 25 08:50:33 2019 UTC allow references to be passed to '-c commit' options commit - 3f9de99f9b4d3da34a06dfce54134ff891684df9 commit + 30837e32b8c05d75e429f5587a658d6df7ddfda8 blob - 59507d1863a1ad983bf5f3e0811d54e3c511f8f5 blob + 6bfe01e0cf9d122e717e568966eb3ac3f555b1f9 --- got/got.1 +++ got/got.1 @@ -143,7 +143,8 @@ reference will be used. .It Fl c Ar commit Check out files from the specified .Ar commit . -The expected argument is a commit ID SHA1 hash. +The expected argument is a commit ID SHA1 hash or an existing reference +which will be resolved to a commit ID. An abbreviated hash argument will be expanded to a full SHA1 hash automatically, provided the abbreviation is unique. If this option is not specified, the most recent commit on the selected @@ -201,7 +202,8 @@ This option requires that all paths in the work tree a .It Fl c Ar commit Update the work tree to the specified .Ar commit . -The expected argument is a commit ID SHA1 hash. +The expected argument is a commit ID SHA1 hash or an existing reference +which will be resolved to a commit ID. An abbreviated hash argument will be expanded to a full SHA1 hash automatically, provided the abbreviation is unique. If this option is not specified, the most recent commit on the work tree's @@ -243,7 +245,8 @@ are as follows: .It Fl c Ar commit Start traversing history at the specified .Ar commit . -The expected argument is the name of a branch or a commit ID SHA1 hash. +The expected argument is a commit ID SHA1 hash or an existing reference +which will be resolved to a commit ID. An abbreviated hash argument will be expanded to a full SHA1 hash automatically, provided the abbreviation is unique. If this option is not specified, default to the work tree's current branch @@ -307,7 +310,8 @@ are as follows: .It Fl c Ar commit Start traversing history at the specified .Ar commit . -The expected argument is the name of a branch or a commit ID SHA1 hash. +The expected argument is a commit ID SHA1 hash or an existing reference +which will be resolved to a commit ID. An abbreviated hash argument will be expanded to a full SHA1 hash automatically, provided the abbreviation is unique. .It Fl r Ar repository-path @@ -341,7 +345,8 @@ are as follows: .It Fl c Ar commit List files and directories as they appear in the specified .Ar commit . -The expected argument is the name of a branch or a commit ID SHA1 hash. +The expected argument is a commit ID SHA1 hash or an existing reference +which will be resolved to a commit ID. An abbreviated hash argument will be expanded to a full SHA1 hash automatically, provided the abbreviation is unique. .It Fl r Ar repository-path blob - b5341e17acdb3b81c77d3cce58a2ab5c6c010c6c blob + a16ed7b70ecc012e088c02a4df0d6f13e4e268a6 --- got/got.c +++ got/got.c @@ -900,10 +900,19 @@ cmd_checkout(int argc, char *argv[]) } if (commit_id_str) { - struct got_object_id *commit_id; - error = got_repo_match_object_id_prefix(&commit_id, - commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); - if (error != NULL) + struct got_object_id *commit_id = NULL; + struct got_reference *ref; + error = got_ref_open(&ref, repo, commit_id_str, 0); + if (error == NULL) { + error = got_ref_resolve(&commit_id, repo, ref); + got_ref_close(ref); + } else { + if (error->code != GOT_ERR_NOT_REF) + goto done; + error = got_repo_match_object_id_prefix(&commit_id, + commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); + } + if (error) goto done; error = check_linear_ancestry(commit_id, got_worktree_get_base_commit_id(worktree), repo); @@ -1108,9 +1117,19 @@ cmd_update(int argc, char *argv[]) if (error != NULL) goto done; } else { - error = got_repo_match_object_id_prefix(&commit_id, - commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); - if (error != NULL) + struct got_reference *ref; + error = got_ref_open(&ref, repo, commit_id_str, 0); + if (error == NULL) { + error = got_ref_resolve(&commit_id, repo, ref); + got_ref_close(ref); + } + else { + if (error->code != GOT_ERR_NOT_REF) + goto done; + error = got_repo_match_object_id_prefix(&commit_id, + commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); + } + if (error) goto done; free(commit_id_str); error = got_object_id_str(&commit_id_str, commit_id); @@ -2015,9 +2034,18 @@ cmd_blame(int argc, char *argv[]) if (error != NULL) goto done; } else { - error = got_repo_match_object_id_prefix(&commit_id, - commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); - if (error != NULL) + struct got_reference *ref; + error = got_ref_open(&ref, repo, commit_id_str, 0); + if (error == NULL) { + error = got_ref_resolve(&commit_id, repo, ref); + got_ref_close(ref); + } else { + if (error->code != GOT_ERR_NOT_REF) + goto done; + error = got_repo_match_object_id_prefix(&commit_id, + commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); + } + if (error) goto done; } @@ -2247,9 +2275,18 @@ cmd_tree(int argc, char *argv[]) if (error != NULL) goto done; } else { - error = got_repo_match_object_id_prefix(&commit_id, - commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); - if (error != NULL) + struct got_reference *ref; + error = got_ref_open(&ref, repo, commit_id_str, 0); + if (error == NULL) { + error = got_ref_resolve(&commit_id, repo, ref); + got_ref_close(ref); + } else { + if (error->code != GOT_ERR_NOT_REF) + goto done; + error = got_repo_match_object_id_prefix(&commit_id, + commit_id_str, GOT_OBJ_TYPE_COMMIT, repo); + } + if (error) goto done; }