Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change names of ipfs dag put flags to make changes clearer #8439

Merged
merged 2 commits into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/commands/dag/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ into an object of the specified format.
cmds.FileArg("object data", true, true, "The object to put").EnableStdin(),
},
Options: []cmds.Option{
cmds.StringOption("format", "f", "Format that the object will be added as.").WithDefault("dag-cbor"),
cmds.StringOption("input-enc", "Format that the input object will be.").WithDefault("dag-json"),
cmds.StringOption("store-codec", "Codec that the stored object will be encoded with").WithDefault("dag-cbor"),
cmds.StringOption("input-codec", "Codec that the input object is encoded in").WithDefault("dag-json"),
cmds.BoolOption("pin", "Pin this object when adding."),
cmds.StringOption("hash", "Hash function to use").WithDefault("sha2-256"),
},
Expand Down
14 changes: 7 additions & 7 deletions core/commands/dag/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,17 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
return err
}

ienc, _ := req.Options["input-enc"].(string)
format, _ := req.Options["format"].(string)
inputCodec, _ := req.Options["input-codec"].(string)
storeCodec, _ := req.Options["store-codec"].(string)
hash, _ := req.Options["hash"].(string)
dopin, _ := req.Options["pin"].(bool)

var icodec mc.Code
if err := icodec.Set(ienc); err != nil {
if err := icodec.Set(inputCodec); err != nil {
return err
}
var fcodec mc.Code
if err := fcodec.Set(format); err != nil {
var scodec mc.Code
if err := scodec.Set(storeCodec); err != nil {
return err
}
var mhType mc.Code
Expand All @@ -51,7 +51,7 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e

cidPrefix := cid.Prefix{
Version: 1,
Codec: uint64(fcodec),
Codec: uint64(scodec),
MhType: uint64(mhType),
MhLength: -1,
}
Expand All @@ -60,7 +60,7 @@ func dagPut(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) e
if err != nil {
return err
}
encoder, err := multicodec.LookupEncoder(uint64(fcodec))
encoder, err := multicodec.LookupEncoder(uint64(scodec))
if err != nil {
return err
}
Expand Down
34 changes: 17 additions & 17 deletions test/sharness/t0053-dag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_dag_cmd() {
'

test_expect_success "can add an ipld object using dag-json to dag-json" '
IPLDHASH=$(cat ipld_object | ipfs dag put --input-enc=dag-json -f dag-json)
IPLDHASH=$(cat ipld_object | ipfs dag put --input-codec dag-json --store-codec dag-json)
'

test_expect_success "CID looks correct" '
Expand All @@ -54,7 +54,7 @@ test_dag_cmd() {
'

test_expect_success "can add an ipld object using dag-json to dag-cbor" '
IPLDHASH=$(cat ipld_object | ipfs dag put --input-enc=dag-json -f dag-cbor)
IPLDHASH=$(cat ipld_object | ipfs dag put --input-codec dag-json --store-codec dag-cbor)
'

test_expect_success "CID looks correct" '
Expand All @@ -75,7 +75,7 @@ test_dag_cmd() {
# (1) dag-cbor input

test_expect_success "can add a dag-cbor input block stored as dag-cbor" '
IPLDCBORHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-cbor)
IPLDCBORHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-cbor)
'

test_expect_success "dag-cbor CID looks correct" '
Expand All @@ -84,7 +84,7 @@ test_dag_cmd() {
'

test_expect_success "can add a dag-cbor input block stored as dag-pb" '
IPLDPBHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-pb)
IPLDPBHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-pb)
'

test_expect_success "dag-pb CID looks correct" '
Expand All @@ -93,7 +93,7 @@ test_dag_cmd() {
'

test_expect_success "can add a dag-cbor input block stored as dag-json" '
IPLDJSONHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-enc=dag-cbor -f dag-json)
IPLDJSONHASH=$(cat ipld_object_dagcbor | ipfs dag put --input-codec dag-cbor --store-codec dag-json)
'

test_expect_success "dag-json CID looks correct" '
Expand All @@ -104,7 +104,7 @@ test_dag_cmd() {
# (2) dag-json input

test_expect_success "can add a dag-json input block stored as dag-cbor" '
IPLDCBORHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-cbor)
IPLDCBORHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-cbor)
'

test_expect_success "dag-cbor CID looks correct" '
Expand All @@ -113,7 +113,7 @@ test_dag_cmd() {
'

test_expect_success "can add a dag-json input block stored as dag-pb" '
IPLDPBHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-pb)
IPLDPBHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-pb)
'

test_expect_success "dag-pb CID looks correct" '
Expand All @@ -122,7 +122,7 @@ test_dag_cmd() {
'

test_expect_success "can add a dag-json input block stored as dag-json" '
IPLDJSONHASH=$(cat ipld_object_dagjson | ipfs dag put --input-enc=dag-json -f dag-json)
IPLDJSONHASH=$(cat ipld_object_dagjson | ipfs dag put --input-codec dag-json --store-codec dag-json)
'

test_expect_success "dag-json CID looks correct" '
Expand All @@ -133,7 +133,7 @@ test_dag_cmd() {
# (3) dag-pb input

test_expect_success "can add a dag-pb input block stored as dag-cbor" '
IPLDCBORHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-cbor)
IPLDCBORHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-cbor)
'

test_expect_success "dag-cbor CID looks correct" '
Expand All @@ -142,7 +142,7 @@ test_dag_cmd() {
'

test_expect_success "can add a dag-pb input block stored as dag-pb" '
IPLDPBHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-pb)
IPLDPBHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-pb)
'

test_expect_success "dag-pb CID looks correct" '
Expand All @@ -151,7 +151,7 @@ test_dag_cmd() {
'

test_expect_success "can add a dag-pb input block stored as dag-json" '
IPLDJSONHASH=$(cat ipld_object_dagpb | ipfs dag put --input-enc=dag-pb -f dag-json)
IPLDJSONHASH=$(cat ipld_object_dagpb | ipfs dag put --input-codec dag-pb --store-codec dag-json)
'

test_expect_success "dag-json CID looks correct" '
Expand Down Expand Up @@ -245,7 +245,7 @@ test_dag_cmd() {
'

test_expect_success "retrieved object hashes back correctly" '
IPLDHASH2=$(cat ipld_obj_out | ipfs dag put --input-enc=dag-json -f dag-cbor) &&
IPLDHASH2=$(cat ipld_obj_out | ipfs dag put --input-codec dag-json --store-codec dag-cbor) &&
test "$IPLDHASH" = "$IPLDHASH2"
'

Expand All @@ -272,7 +272,7 @@ test_dag_cmd() {
'

test_expect_success "non-canonical dag-cbor input is normalized" '
HASH=$(cat ../t0053-dag-data/non-canon.cbor | ipfs dag put --format=dag-cbor --input-enc=dag-cbor) &&
HASH=$(cat ../t0053-dag-data/non-canon.cbor | ipfs dag put --store-codec dag-cbor --input-codec dag-cbor) &&
test $HASH = "bafyreiawx7ona7oa2ptcoh6vwq4q6bmd7x2ibtkykld327bgb7t73ayrqm" ||
test_fsh echo $HASH
'
Expand All @@ -283,7 +283,7 @@ test_dag_cmd() {
'

test_expect_success "add an ipld with pin" '
PINHASH=$(printf {\"foo\":\"bar\"} | ipfs dag put --input-enc=dag-json --pin=true)
PINHASH=$(printf {\"foo\":\"bar\"} | ipfs dag put --input-codec dag-json --pin=true)
'

test_expect_success "after gc, objects still accessible" '
Expand All @@ -307,7 +307,7 @@ test_dag_cmd() {

test_expect_success "dag put with json dag-pb works" '
ipfs dag get $HASH > pbjson &&
cat pbjson | ipfs dag put --format=dag-pb --input-enc=dag-json > dag_put_out
cat pbjson | ipfs dag put --store-codec=dag-pb --input-codec=dag-json > dag_put_out
'

test_expect_success "dag put with dag-pb works output looks good" '
Expand All @@ -317,7 +317,7 @@ test_dag_cmd() {

test_expect_success "dag put with raw dag-pb works" '
ipfs block get $HASH > pbraw &&
cat pbraw | ipfs dag put --format=dag-pb --input-enc=dag-pb > dag_put_out
cat pbraw | ipfs dag put --store-codec=dag-pb --input-codec=dag-pb > dag_put_out
'

test_expect_success "dag put with dag-pb works output looks good" '
Expand All @@ -327,7 +327,7 @@ test_dag_cmd() {

test_expect_success "dag put with raw node works" '
echo "foo bar" > raw_node_in &&
HASH=$(ipfs dag put --format=raw --input-enc=raw -- raw_node_in) &&
HASH=$(ipfs dag put --store-codec=raw --input-codec=raw -- raw_node_in) &&
ipfs block get "$HASH" > raw_node_out &&
test_cmp raw_node_in raw_node_out'

Expand Down
4 changes: 2 additions & 2 deletions test/sharness/t0055-dag-put-json-new-line.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ test_expect_success 'create test JSON files' '
'

test_expect_success 'puts as CBOR work' '
GOT_HASH_WITHOUT_NEWLINE="$(cat without_newline.json | ipfs dag put -f dag-cbor)"
GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put -f dag-cbor)"
GOT_HASH_WITHOUT_NEWLINE="$(cat without_newline.json | ipfs dag put --store-codec dag-cbor)"
GOT_HASH_WITH_NEWLINE="$(cat with_newline.json | ipfs dag put --store-codec dag-cbor)"
'

test_expect_success 'put hashes with or without newline are equal' '
Expand Down
2 changes: 1 addition & 1 deletion test/sharness/t0280-plugin-git.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ test_expect_success "prepare test data" '

test_dag_git() {
test_expect_success "add objects via dag put" '
find objects -type f -exec ipfs dag put --format=git-raw --input-enc=0x300078 --hash=sha1 {} \; -exec echo -n \; > hashes
find objects -type f -exec ipfs dag put --store-codec=git-raw --input-codec=0x300078 --hash=sha1 {} \; -exec echo -n \; > hashes
'

test_expect_success "successfully get added objects" '
Expand Down