git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v3 07/11] Documentation/replace: tell that -f option bypasses the type check

From
Christian Couder <christian.couder@gmail.com>
Date
Sep 3, 2013, 09:29 UTC
Message-ID
<CAP8UFD31dawrGEiukHYvfUFtDtqrK-OLMLdqFfdOBU=rDYuAcQ@mail.gmail.com>
In-Reply-To
<66A16BF0137D40568A34C316DDA6D32E@PhilipOakley>
On Mon, Sep 2, 2013 at 11:50 PM, Philip Oakley <philipoakley@iee.org> wrote:
Show 25 quoted lines
>
> From: "Christian Couder" <chriscool@tuxfamily.org>
>
>> You mean something like the following:
>>
>> $ cat  ./graft2replace.sh
>> #!/bin/bash
>>
>> while read orig parents
>> do
>>        printf "%s" "git cat-file commit $orig"
>>        printf "%s" " | perl -n -e 'print unless /^parent /'"
>>        insn=''
>>        for commit in $parents; do insn="$insn print \"parent
>> $commit\\n\";"; done
>>        printf "%s" " | perl -n -e 'print; if (/^tree /) { $insn }'"
>>        printf "%s\n" " > new_commit.txt"
>>        printf "%s\n" 'REPL=$(git hash-object -t commit -w new_commit.txt)'
>
>
> Does `hash-object` do the inverese of `cat-file commit`?
>
> I didn't find the hash-object(1) man page very informative on that matter
> and a (very) quick look at its code made me think it was just hashing the
> raw contents which wouldn't be what what was wanted.

I agree with Jonathan's suggest to add an EXAMPLE section in hash-object(1) manpage and maybe a new gitobject(5) manpage too.

You can also find a few examples of how git hash-object can be used in t/t6050-replace.sh:

For example:
     R=$(git cat-file commit $HASH2 | sed -e "s/A U/O/" | git
hash-object -t commit --stdin -w) &&
     git cat-file commit $R | grep "author O Thor" &&
     git update-ref refs/replace/$HASH2 $R
Show 27 quoted lines
>>        printf "%s\n" "git replace $orig \$REPL"
>> done
>>
>> This generates shell instructions from a graft file. Then you only need to
>> execute the generated shell instructions.
>> For example:
>>
>> $ cat graft_file.txt
>> 5bf34fff3186254d7254583675d10ddf98df989b
>> 79fe155489351e8af829a3106e7150397c57d863
>> dcfbab6bea3df3166503f3084cec2679f10f9e80
>> fb5657082148297b61fbca7e64d51c1e7870309a
>>
>> $ cat graft_file.txt | ./graft2replace.sh
>> git cat-file commit 5bf34fff3186254d7254583675d10ddf98df989b | perl -n -e
>> 'print unless /^parent /' | perl -n -e 'print; if (/^tree /) {  print
>> "parent 79fe155489351e8af829a3106e7150397c57d863\n"; print "parent
>> dcfbab6bea3df3166503f3084cec2679f10f9e80\n"; }' > new_commit.txt
>> REPL=$(git hash-object -t commit -w new_commit.txt)
>> git replace 5bf34fff3186254d7254583675d10ddf98df989b $REPL
>> git cat-file commit fb5657082148297b61fbca7e64d51c1e7870309a | perl -n -e
>> 'print unless /^parent /' | perl -n -e 'print; if (/^tree /) {  }' >
>> new_commit.txt
>> REPL=$(git hash-object -t commit -w new_commit.txt)
>> git replace fb5657082148297b61fbca7e64d51c1e7870309a $REPL
>>
>> Note that I haven't really tested it.

Also note that it is obviously broken if you have commits with a commit message that has lines starting with 'parent ' or 'tree '.

> I think we could call it 'git-graft', being the help function/script that
> converts raw grafts to proper object replacements ;-)

I will have a look at improving it, testing it and sending a patch to put it in contrib/.

Thanks, Christian.

Previous: Philip OakleyNext: Christian Couder
Message 23 of 33 in “Check replacement object type and minor updates”
  1. 00/11 Check replacement object type and minor updatesChristian Couder, Aug 31, 2013
  2. 01/11 replace: forbid replacing an object with one of a different typeChristian Couder, Aug 31, 2013
  3. Philip OakleyAug 31, 2013
  4. Christian CouderSep 1, 2013
  5. Philip OakleySep 1, 2013
  6. 02/11 Documentation/replace: state that objects must be of the same typeChristian Couder, Aug 31, 2013
  7. 03/11 t6050-replace: test that objects are of the same typeChristian Couder, Aug 31, 2013
  8. 04/11 t6050-replace: add test to clean up all the replace refsChristian Couder, Aug 31, 2013
  9. 05/11 Documentation/replace: add Creating Replacement Objects sectionChristian Couder, Aug 31, 2013
  10. Philip OakleyAug 31, 2013
  11. Christian CouderSep 1, 2013
  12. 06/11 replace: bypass the type check if -f option is usedChristian Couder, Aug 31, 2013
  13. 07/11 Documentation/replace: tell that -f option bypasses the type checkChristian Couder, Aug 31, 2013
  14. Philip OakleyAug 31, 2013
  15. Christian CouderSep 1, 2013
  16. Philip OakleySep 1, 2013
  17. Christian CouderSep 2, 2013
  18. Philip OakleySep 2, 2013
  19. Jonathan NiederSep 2, 2013
  20. Philip OakleySep 2, 2013
  21. Jonathan NiederSep 2, 2013
  22. Philip OakleySep 2, 2013
  23. Christian CouderSep 3, 2013
  24. 08/11 t6050-replace: check that -f option bypasses the type checkChristian Couder, Aug 31, 2013
  25. Eric SunshineSep 1, 2013
  26. Christian CouderSep 1, 2013
  27. 09/11 replace: allow long option namesChristian Couder, Aug 31, 2013
  28. 10/11 Documentation/replace: list long option namesChristian Couder, Aug 31, 2013
  29. 11/11 t6050-replace: use some long option namesChristian Couder, Aug 31, 2013
  30. Philip OakleyAug 31, 2013
  31. Christian CouderSep 1, 2013
  32. Eric SunshineSep 1, 2013
  33. Christian CouderSep 1, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.