After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 618974 - [PATCH 00/14] Restructure the _update member of GitBranch
[PATCH 00/14] Restructure the _update member of GitBranch
Status: RESOLVED FIXED
Product: jhbuild
Classification: Infrastructure
Component: general
2.29.x
Other All
: Normal normal
: ---
Assigned To: Jhbuild maintainers
Jhbuild QA
Depends on:
Blocks: 618254 619935
 
 
Reported: 2010-05-18 12:01 UTC by Dirk Wallenstein
Modified: 2010-06-08 08:51 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
[git] Introduce a predicate execution wrapper (1.49 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Rewrite the branch name getter (3.31 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Make git version checks more readable (2.03 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Use a new predicate to test if a branch tracks a remote branch (1.91 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Use a new predicate to determine the need to stash (2.57 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Rename would_be_branch to wanted_branch (2.16 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Extract the branch switch into a function (3.93 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Try to find requested branch remotely if not available (2.41 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Switch branches previous to stash and pull (1.59 KB, patch)
2010-05-18 12:45 UTC, Dirk Wallenstein
none Details | Review
[git] Extract the pull operation into a function (3.22 KB, patch)
2010-05-18 12:46 UTC, Dirk Wallenstein
none Details | Review
[git] Move the quiet option to its point of use (1.39 KB, patch)
2010-05-18 12:46 UTC, Dirk Wallenstein
none Details | Review
[git] Extract sticky date operation into a function (2.35 KB, patch)
2010-05-18 12:46 UTC, Dirk Wallenstein
none Details | Review
[git] Align local branch predicate with other predicates (2.37 KB, patch)
2010-05-18 12:46 UTC, Dirk Wallenstein
none Details | Review
[git] Clarify branch switch destination calculation (4.11 KB, patch)
2010-05-18 12:46 UTC, Dirk Wallenstein
none Details | Review
[git] Consider staged, uncommited changes as dirty (1.16 KB, patch)
2010-05-22 17:55 UTC, Dirk Wallenstein
none Details | Review
Always trigger a build for dirty git branches (1.35 KB, patch)
2010-05-22 18:45 UTC, Dirk Wallenstein
none Details | Review
Trigger a build for dirty branches more generally (1.50 KB, patch)
2010-05-24 08:23 UTC, Dirk Wallenstein
none Details | Review
[git] Avoid the ternary operator for python-2.3 conformance (1.11 KB, patch)
2010-05-24 10:19 UTC, Dirk Wallenstein
none Details | Review
[git] Remove the '_' prefix from all new functions (7.72 KB, patch)
2010-05-24 10:19 UTC, Dirk Wallenstein
none Details | Review

Description Dirk Wallenstein 2010-05-18 12:01:35 UTC
There are a lot of things happening inside _update, and I hope this
series simplifies that a bit. The previous behavior is mostly kept,
except in locations where I thought, that it could be improved: 
- Use '--ignore-submodules' to prevent commits in submodules to trigger
  a stashing operation.
- (return to a) pull after the branch switch, but ensure a recently
  added branch is found when switching
- Fail when there is an attempt to switch dirty branches. Uncommited
  changes on the same branch are still moved along. 

Dirk Wallenstein (14):
  [git] Introduce a predicate execution wrapper
  [git] Rewrite the branch name getter
  [git] Make git version checks more readable
  [git] Use a new predicate to test if a branch tracks a remote branch
  [git] Use a new predicate to determine the need to stash
  [git] Rename would_be_branch to wanted_branch
  [git] Extract the branch switch into a function
  [git] Try to find requested branch remotely if not available
  [git] Switch branches previous to stash and pull
  [git] Extract the pull operation into a function
  [git] Move the quiet option to its point of use
  [git] Extract sticky date operation into a function
  [git] Align local branch predicate with other predicates
  [git] Clarify branch switch destination calculation

 jhbuild/versioncontrol/git.py |  238 ++++++++++++++++++++++++++---------------
 1 files changed, 150 insertions(+), 88 deletions(-)
Comment 1 Dirk Wallenstein 2010-05-18 12:45:31 UTC
Created attachment 161336 [details] [review]
[git] Introduce a predicate execution wrapper

There are often git commands where only a boolean return value is of
interest. This new wrapper can be easily used to create such predicates.
Comment 2 Dirk Wallenstein 2010-05-18 12:45:35 UTC
Created attachment 161337 [details] [review]
[git] Rewrite the branch name getter

The new getter returns a valid branchname or None in case of a detached
head. The name is changed to have a '_' prefix. There are no external
users.
Comment 3 Dirk Wallenstein 2010-05-18 12:45:38 UTC
Created attachment 161338 [details] [review]
[git] Make git version checks more readable

Wrap the generic version checker into a git specific one and use it.
Comment 4 Dirk Wallenstein 2010-05-18 12:45:41 UTC
Created attachment 161339 [details] [review]
[git] Use a new predicate to test if a branch tracks a remote branch

This allows the remote to have a different name than 'origin', and gives
the operation a meaningful name.
Comment 5 Dirk Wallenstein 2010-05-18 12:45:44 UTC
Created attachment 161340 [details] [review]
[git] Use a new predicate to determine the need to stash

Introduce a predicate to test if the repository is dirty, optionally
including existing submodules.
This function is used to recognize uncommited changes to be stashed.
This should now work more reliable in the face of changes in submodules,
as the output of 'git diff --submodule' may have multiple lines, where
not every line starts with 'Submodule '.
To reliably exclude differences in submodules, a dependency to a two
year old git version is added.
Comment 6 Dirk Wallenstein 2010-05-18 12:45:48 UTC
Created attachment 161341 [details] [review]
[git] Rename would_be_branch to wanted_branch

This seems to better describe the purpose.
Comment 7 Dirk Wallenstein 2010-05-18 12:45:51 UTC
Created attachment 161342 [details] [review]
[git] Extract the branch switch into a function

The new function will not switch a branch if there are uncommited
changes. This will have no impact, yet, as a dirty state is always
stashed prior to a branch switch.
Comment 8 Dirk Wallenstein 2010-05-18 12:45:55 UTC
Created attachment 161343 [details] [review]
[git] Try to find requested branch remotely if not available

If a branch switch is requested but the branch is not available,
upstream will be fetched and the branch will be looked up again, before
failing.

This should make the branch switching independent of the concerns stated
in (GNOME bug 591470) and commit f7d5f81b6ca02ee5.
Comment 9 Dirk Wallenstein 2010-05-18 12:45:59 UTC
Created attachment 161344 [details] [review]
[git] Switch branches previous to stash and pull

Now the refusal of the previously extracted function to switch dirty
branches will take effect. It is very unlikely that a user wants to
apply uncommited changes onto another branch by means of a jhbuild
update operation. Such an operation certainly deserves manual
inspection.

This will now update the new branch instead of the previous one.

The problem with not finding recently added remote branches is solved in
a previous commit.
Comment 10 Dirk Wallenstein 2010-05-18 12:46:03 UTC
Created attachment 161345 [details] [review]
[git] Extract the pull operation into a function

The pull operation will only be executed if the current branch is
tracking a remote branch.
Comment 11 Dirk Wallenstein 2010-05-18 12:46:07 UTC
Created attachment 161346 [details] [review]
[git] Move the quiet option to its point of use
Comment 12 Dirk Wallenstein 2010-05-18 12:46:10 UTC
Created attachment 161347 [details] [review]
[git] Extract sticky date operation into a function
Comment 13 Dirk Wallenstein 2010-05-18 12:46:14 UTC
Created attachment 161348 [details] [review]
[git] Align local branch predicate with other predicates

There's no need to log the simple test for a local branch. Therefore,
the function can be aligned with the other predicates.
Comment 14 Dirk Wallenstein 2010-05-18 12:46:18 UTC
Created attachment 161349 [details] [review]
[git] Clarify branch switch destination calculation

Extract the calculation that determines if a branch switch is necessary
into a function. This also simplifies the calculations a bit while
preserving the previous behavior.
Comment 15 Dirk Wallenstein 2010-05-22 17:55:11 UTC
Created attachment 161732 [details] [review]
[git] Consider staged, uncommited changes as dirty

is_dirty made the wrong diff previously. This now considers any
deviation between HEAD and the current working tree as dirty.
Comment 16 Dirk Wallenstein 2010-05-22 18:45:38 UTC
Created attachment 161734 [details] [review]
Always trigger a build for dirty git branches

A dirty git branch will be considered not up to date in every
build_policy.
Comment 17 Dirk Wallenstein 2010-05-24 08:23:45 UTC
Created attachment 161834 [details] [review]
Trigger a build for dirty branches more generally

This removes the git dependency of the dirty branch check for the
build_policy, and allows every branch type to support that, by defining
an 'is_dirty' member.
Comment 18 Frederic Peters 2010-05-24 08:32:58 UTC
I didn't get a deep look at the Git usage changes, I believe you know what you're doing. About the coding style, as a general rule I don't like prefixing methods with _ that much, and JHBuild should work with Python 2.3 (sth like quiet = ['-q'] if self.config.quiet_mode else [] is not supported).
Comment 19 Dirk Wallenstein 2010-05-24 10:19:01 UTC
Created attachment 161843 [details] [review]
[git] Avoid the ternary operator for python-2.3 conformance

This reverts the syntax change additionally introduced in the commit
'[git] Move the quiet option to its point of use'
Comment 20 Dirk Wallenstein 2010-05-24 10:19:05 UTC
Created attachment 161844 [details] [review]
[git] Remove the '_' prefix from all new functions

This reverts the introduction of new functions with a '_' prefix in the
recent commit series.
Comment 21 Dirk Wallenstein 2010-05-24 10:20:05 UTC
(In reply to comment #18)
> I didn't get a deep look at the Git usage changes, I believe you know what
> you're doing. About the coding style, as a general rule I don't like prefixing
> methods with _ that much, and JHBuild should work with Python 2.3 (sth like
> quiet = ['-q'] if self.config.quiet_mode else [] is not supported).

I've tested those changes and it works alright.
I've looked through the commits and I think the ternary operator was the
only thing not conforming to python-2.3.
Comment 22 Frederic Peters 2010-06-07 17:16:15 UTC
Ok, fine; you should go ahead and rebase your patches, then push.
Comment 23 Frederic Peters 2010-06-08 08:51:36 UTC
Pushed everything; thanks.