Git fork

Merge branch 'rs/get-oid-with-flags-cleanup'

Code clean-up.

* rs/get-oid-with-flags-cleanup:
use repo_get_oid_with_flags()

+17 -50
+2 -5
builtin/ls-tree.c
··· 373 OPT_END() 374 }; 375 struct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format; 376 - struct object_context obj_context = {0}; 377 int ret; 378 379 repo_config(the_repository, git_default_config, NULL); ··· 405 ls_tree_usage, ls_tree_options); 406 if (argc < 1) 407 usage_with_options(ls_tree_usage, ls_tree_options); 408 - if (get_oid_with_context(the_repository, argv[0], 409 - GET_OID_HASH_ANY, &oid, 410 - &obj_context)) 411 die("Not a valid object name %s", argv[0]); 412 413 /* ··· 447 448 ret = !!read_tree(the_repository, tree, &options.pathspec, fn, &options); 449 clear_pathspec(&options.pathspec); 450 - object_context_release(&obj_context); 451 return ret; 452 }
··· 373 OPT_END() 374 }; 375 struct ls_tree_cmdmode_to_fmt *m2f = ls_tree_cmdmode_format; 376 int ret; 377 378 repo_config(the_repository, git_default_config, NULL); ··· 404 ls_tree_usage, ls_tree_options); 405 if (argc < 1) 406 usage_with_options(ls_tree_usage, ls_tree_options); 407 + if (repo_get_oid_with_flags(the_repository, argv[0], &oid, 408 + GET_OID_HASH_ANY)) 409 die("Not a valid object name %s", argv[0]); 410 411 /* ··· 445 446 ret = !!read_tree(the_repository, tree, &options.pathspec, fn, &options); 447 clear_pathspec(&options.pathspec); 448 return ret; 449 }
+2 -5
builtin/rev-parse.c
··· 708 struct object_id oid; 709 unsigned int flags = 0; 710 const char *name = NULL; 711 - struct object_context unused; 712 struct strbuf buf = STRBUF_INIT; 713 int seen_end_of_options = 0; 714 enum format_type format = FORMAT_DEFAULT; ··· 1141 name++; 1142 type = REVERSED; 1143 } 1144 - if (!get_oid_with_context(the_repository, name, 1145 - flags, &oid, &unused)) { 1146 - object_context_release(&unused); 1147 if (output_algo) 1148 repo_oid_to_algop(the_repository, &oid, 1149 output_algo, &oid); ··· 1153 show_rev(type, &oid, name); 1154 continue; 1155 } 1156 - object_context_release(&unused); 1157 if (verify) 1158 die_no_single_rev(quiet); 1159 if (has_dashdash)
··· 708 struct object_id oid; 709 unsigned int flags = 0; 710 const char *name = NULL; 711 struct strbuf buf = STRBUF_INIT; 712 int seen_end_of_options = 0; 713 enum format_type format = FORMAT_DEFAULT; ··· 1140 name++; 1141 type = REVERSED; 1142 } 1143 + if (!repo_get_oid_with_flags(the_repository, name, &oid, 1144 + flags)) { 1145 if (output_algo) 1146 repo_oid_to_algop(the_repository, &oid, 1147 output_algo, &oid); ··· 1151 show_rev(type, &oid, name); 1152 continue; 1153 } 1154 if (verify) 1155 die_no_single_rev(quiet); 1156 if (has_dashdash)
+5 -9
builtin/stash.c
··· 1089 int quiet = 0; 1090 const char *stash_msg = NULL; 1091 struct object_id obj; 1092 - struct object_context dummy = {0}; 1093 struct option options[] = { 1094 OPT__QUIET(&quiet, N_("be quiet")), 1095 OPT_STRING('m', "message", &stash_msg, "message", ··· 1109 return -1; 1110 } 1111 1112 - if (get_oid_with_context(the_repository, 1113 - argv[0], quiet ? GET_OID_QUIETLY : 0, &obj, 1114 - &dummy)) { 1115 if (!quiet) 1116 fprintf_ln(stderr, _("Cannot update %s with %s"), 1117 ref_stash, argv[0]); ··· 1122 ret = do_store_stash(&obj, stash_msg, quiet); 1123 1124 out: 1125 - object_context_release(&dummy); 1126 return ret; 1127 } 1128 ··· 2238 const char **argv) 2239 { 2240 struct object_id base; 2241 - struct object_context unused; 2242 struct commit *prev; 2243 struct commit_list *items = NULL, **iter = &items, *cur; 2244 int res = 0; ··· 2272 struct commit *stash; 2273 2274 if (parse_stash_revision(&revision, argv[i], 1) || 2275 - get_oid_with_context(r, revision.buf, 2276 - GET_OID_QUIETLY | GET_OID_GENTLY, 2277 - &oid, &unused)) { 2278 res = error(_("unable to find stash entry %s"), argv[i]); 2279 goto out; 2280 }
··· 1089 int quiet = 0; 1090 const char *stash_msg = NULL; 1091 struct object_id obj; 1092 struct option options[] = { 1093 OPT__QUIET(&quiet, N_("be quiet")), 1094 OPT_STRING('m', "message", &stash_msg, "message", ··· 1108 return -1; 1109 } 1110 1111 + if (repo_get_oid_with_flags(the_repository, argv[0], &obj, 1112 + quiet ? GET_OID_QUIETLY : 0)) { 1113 if (!quiet) 1114 fprintf_ln(stderr, _("Cannot update %s with %s"), 1115 ref_stash, argv[0]); ··· 1120 ret = do_store_stash(&obj, stash_msg, quiet); 1121 1122 out: 1123 return ret; 1124 } 1125 ··· 2235 const char **argv) 2236 { 2237 struct object_id base; 2238 struct commit *prev; 2239 struct commit_list *items = NULL, **iter = &items, *cur; 2240 int res = 0; ··· 2268 struct commit *stash; 2269 2270 if (parse_stash_revision(&revision, argv[i], 1) || 2271 + repo_get_oid_with_flags(r, revision.buf, &oid, 2272 + GET_OID_QUIETLY | 2273 + GET_OID_GENTLY)) { 2274 res = error(_("unable to find stash entry %s"), argv[i]); 2275 goto out; 2276 }
+3 -6
list-objects-filter.c
··· 524 struct filter *filter) 525 { 526 struct filter_sparse_data *d = xcalloc(1, sizeof(*d)); 527 - struct object_context oc; 528 struct object_id sparse_oid; 529 530 - if (get_oid_with_context(the_repository, 531 - filter_options->sparse_oid_name, 532 - GET_OID_BLOB, &sparse_oid, &oc)) 533 die(_("unable to access sparse blob in '%s'"), 534 filter_options->sparse_oid_name); 535 if (add_patterns_from_blob_to_list(&sparse_oid, "", 0, &d->pl) < 0) ··· 544 filter->filter_data = d; 545 filter->filter_object_fn = filter_sparse; 546 filter->free_fn = filter_sparse_free; 547 - 548 - object_context_release(&oc); 549 } 550 551 /*
··· 524 struct filter *filter) 525 { 526 struct filter_sparse_data *d = xcalloc(1, sizeof(*d)); 527 struct object_id sparse_oid; 528 529 + if (repo_get_oid_with_flags(the_repository, 530 + filter_options->sparse_oid_name, 531 + &sparse_oid, GET_OID_BLOB)) 532 die(_("unable to access sparse blob in '%s'"), 533 filter_options->sparse_oid_name); 534 if (add_patterns_from_blob_to_list(&sparse_oid, "", 0, &d->pl) < 0) ··· 543 filter->filter_data = d; 544 filter->filter_object_fn = filter_sparse; 545 filter->free_fn = filter_sparse_free; 546 } 547 548 /*
+5 -25
object-name.c
··· 1857 const char *name, 1858 struct object_id *oid) 1859 { 1860 - struct object_context unused; 1861 - int ret = get_oid_with_context(r, name, GET_OID_COMMITTISH, 1862 - oid, &unused); 1863 - object_context_release(&unused); 1864 - return ret; 1865 } 1866 1867 int repo_get_oid_treeish(struct repository *r, 1868 const char *name, 1869 struct object_id *oid) 1870 { 1871 - struct object_context unused; 1872 - int ret = get_oid_with_context(r, name, GET_OID_TREEISH, 1873 - oid, &unused); 1874 - object_context_release(&unused); 1875 - return ret; 1876 } 1877 1878 int repo_get_oid_commit(struct repository *r, 1879 const char *name, 1880 struct object_id *oid) 1881 { 1882 - struct object_context unused; 1883 - int ret = get_oid_with_context(r, name, GET_OID_COMMIT, 1884 - oid, &unused); 1885 - object_context_release(&unused); 1886 - return ret; 1887 } 1888 1889 int repo_get_oid_tree(struct repository *r, 1890 const char *name, 1891 struct object_id *oid) 1892 { 1893 - struct object_context unused; 1894 - int ret = get_oid_with_context(r, name, GET_OID_TREE, 1895 - oid, &unused); 1896 - object_context_release(&unused); 1897 - return ret; 1898 } 1899 1900 int repo_get_oid_blob(struct repository *r, 1901 const char *name, 1902 struct object_id *oid) 1903 { 1904 - struct object_context unused; 1905 - int ret = get_oid_with_context(r, name, GET_OID_BLOB, 1906 - oid, &unused); 1907 - object_context_release(&unused); 1908 - return ret; 1909 } 1910 1911 /* Must be called only when object_name:filename doesn't exist. */
··· 1857 const char *name, 1858 struct object_id *oid) 1859 { 1860 + return repo_get_oid_with_flags(r, name, oid, GET_OID_COMMITTISH); 1861 } 1862 1863 int repo_get_oid_treeish(struct repository *r, 1864 const char *name, 1865 struct object_id *oid) 1866 { 1867 + return repo_get_oid_with_flags(r, name, oid, GET_OID_TREEISH); 1868 } 1869 1870 int repo_get_oid_commit(struct repository *r, 1871 const char *name, 1872 struct object_id *oid) 1873 { 1874 + return repo_get_oid_with_flags(r, name, oid, GET_OID_COMMIT); 1875 } 1876 1877 int repo_get_oid_tree(struct repository *r, 1878 const char *name, 1879 struct object_id *oid) 1880 { 1881 + return repo_get_oid_with_flags(r, name, oid, GET_OID_TREE); 1882 } 1883 1884 int repo_get_oid_blob(struct repository *r, 1885 const char *name, 1886 struct object_id *oid) 1887 { 1888 + return repo_get_oid_with_flags(r, name, oid, GET_OID_BLOB); 1889 } 1890 1891 /* Must be called only when object_name:filename doesn't exist. */