How to apply a patch made by repo diff?

9,485 views
Skip to first unread message

Chih-Wei

unread,
Apr 26, 2009, 10:49:11 PM4/26/09
to Repo and Gerrit Discussion
Hi,
The repo diff generated a patch like

project external/e2fsprogs/
diff --git a/Android.mk b/Android.mk
...

However, there is no easy way to apply it.
One has to cd to the project directory to use git apply command.
Am I correct?

Is there a plan to add 'repo apply' command which
will automatically apply the specific patch to appropriate projects?

Shawn Pearce

unread,
Apr 27, 2009, 10:17:13 AM4/27/09
to repo-d...@googlegroups.com
On Sun, Apr 26, 2009 at 19:49, Chih-Wei <cwh...@linux.org.tw> wrote:

The repo diff generated a patch like

project external/e2fsprogs/
diff --git a/Android.mk b/Android.mk
...

However, there is no easy way to apply it.
One has to cd to the project directory to use git apply command.
Am I correct?

Sadly, yes.  Its worse when multiple projects are listed as then you need to split the patch file by hand.

repo diff was never intended for use in a "diff | apply" sort of pipeline.  It was written really quickly as a way to help a user see what is unmodified in their client prior to commit.  I agree it isn't suited for this purpose.  If we are seriously going to support the idea of patches from "repo diff" being able to be applied later then we should also support more options to repo diff, like git diff supports, so you can obtain different views.

Is there a plan to add 'repo apply' command which
will automatically apply the specific patch to appropriate projects?

No, but if someone proposes change(s) on review.source.android.com to implement a "repo apply" subcommand, I'll review it, and if it does what it claims to do, I'll include it in the next build of repo.

So.  Answer is, yes, we can have a repo apply, but its not critical to me, so I won't write it myself.

Chih-Wei

unread,
Apr 28, 2009, 3:34:51 AM4/28/09
to Repo and Gerrit Discussion
On 4月27日, 下午10時17分, Shawn Pearce <s...@google.com> wrote:
> On Sun, Apr 26, 2009 at 19:49, Chih-Wei <cwhu...@linux.org.tw> wrote:
> > However, there is no easy way to apply it.
> > One has to cd to the project directory to use git apply command.
> > Am I correct?
>
> Sadly, yes. Its worse when multiple projects are listed as then you need to
> split the patch file by hand.

Yes, exactly.

> So. Answer is, yes, we can have a repo apply, but its not critical to me,
> so I won't write it myself.

However, people do post patches made by repo diff,
and others do ask how to use them. For example,
http://groups.google.com/group/android-porting/browse_thread/thread/cf10679160e948a5/5f251a2b8051d66d?hl=zh-TW&lnk=gst&q=patch#5f251a2b8051d66d

Unfortunately I'm not familiar with python, or I may try to help.

Just curious. How do the core team apply patches from contributors?
Do you also split a patch containing multiple projects by hand?
(or you won't accept such a patch at all?)

Jean-Baptiste Queru

unread,
Apr 28, 2009, 8:38:20 AM4/28/09
to repo-d...@googlegroups.com
The Android team doesn't accept patches, we only accept commits
uploaded to Gerrit through repo upload.

JBQ

2009/4/28 Chih-Wei <cwh...@linux.org.tw>:
--
Jean-Baptiste M. "JBQ" Queru
Android Engineer, Google.

Questions sent directly to me that have no reason for being private
will likely get ignored or forwarded to a public forum with no further
warning.

Elvis Dowson

unread,
May 13, 2009, 3:21:21 PM5/13/09
to Repo and Gerrit Discussion
I think a repo apply command is really necessary. Imagine my surprise
today, when I sent a patch to a colleague working on an android port
and we discovered that the output of the repo diff cannot be used
directly, without splitting up the patches and using git apply. Really
tedious. Most of the changes are not stuff that we can submit to the
gerrit system, since it's specific modifications and adaptations for a
specific target hardware :-)

Elvis Dowson

Kapil

unread,
Mar 5, 2012, 2:33:31 AM3/5/12
to repo-d...@googlegroups.com
Consider

## Script to patch up diff reated by `repo diff`

if [ -z "$1" ] || [ ! -e "$1" ]; then
    echo "Usages: $0 <repo_diff_file>";
    exit 0;
fi

rm -fr _tmp_splits*
cat $1 | csplit -qf '' -b "_tmp_splits.%d.diff" - '/^project.*\/$/' '{*}'

working_dir=`pwd`

for proj_diff in `ls _tmp_splits.*.diff`
do
    chg_dir=`cat $proj_diff | grep '^project.*\/$' | cut -d " " -f 2`
    echo "FILE: $proj_diff $chg_dir"
    if [ -e $chg_dir ]; then
        ( cd $chg_dir; \
            cat $working_dir/$proj_diff | grep -v '^project.*\/$' | patch -Np1;);
    else
        echo "$0: Project directory $chg_dir don't exists.";
    fi
done
Reply all
Reply to author
Forward
0 new messages