summaryrefslogtreecommitdiffstats
path: root/git_refs.py
Commit message (Collapse)AuthorAgeFilesLines
* project: fix m/ pseudo ref handling with git worktreesMike Frysinger2020-02-291-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since most ref namespaces are shared among all worktrees, trying to set the pseudo m/<branch> in the common git repo ends up clobbering each other when using shared checkouts. For example, in CrOS: <project path="src/third_party/kernel/v3.8" name="chromiumos/third_party/kernel" revision="refs/heads/chromeos-3.8" /> <project path="src/third_party/kernel/v3.10" name="chromiumos/third_party/kernel" revision="refs/heads/chromeos-3.10" /> Trying to set m/master in chromiumos/third_party/kernel.git/ will keep clobbering the other. Instead, when using git worktrees, lets set the m/ pseudo ref to point into the refs/worktree/ namespace which is unique to each git worktree. So we have in the common dir: chromiumos/third_party/kernel.git/: refs/remotes/m/master: ref: refs/worktree/m/master And then in each worktree we point refs/worktree/m/master to the respective manifest revision expression. Now people can use the m/master in each git worktree and have it resolve to the right commit for that worktree. Bug: https://crbug.com/gerrit/12404 Change-Id: I78814bdd5dd67bb13218c4c6ccd64f8a15dd0a52 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/256952 Tested-by: Mike Frysinger <vapier@google.com> Reviewed-by: David Pursehouse <dpursehouse@collab.net>
* Fix various whitespace issues reported by pyflakesDavid Pursehouse2020-02-121-5/+5
| | | | | | | | | | | | | | | | | | | | | | - E201 whitespace after '[' - E202 whitespace before '}' - E221 multiple spaces before operator - E222 multiple spaces after operator - E225 missing whitespace around operator - E226 missing whitespace around arithmetic operator - E231 missing whitespace after ',' - E261 at least two spaces before inline comment - E271 multiple spaces after keyword Fixed automatically with autopep8: git ls-files | grep py$ | xargs autopep8 --in-place \ --select E201,E202,E221,E222,E225,E226,E231,E261,E271 Change-Id: I367113eb8c847eb460532c7c2f8643f33040308c Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/254601 Reviewed-by: Mike Frysinger <vapier@google.com> Tested-by: David Pursehouse <dpursehouse@collab.net>
* use open context managers in more placesMike Frysinger2019-11-121-10/+3
| | | | | | | | | | Use open() as a context manager to simplify the close logic and make the code easier to read & understand. This is also more Pythonic. Change-Id: I579d03cca86f99b2c6c6a1f557f6e5704e2515a7 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/244734 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
* rename local trace moduleMike Frysinger2019-08-271-1/+1
| | | | | | | | | | There is a standard Python "trace" module, so having a local trace.py prevents us being able to import that. Rename the module to avoid. Change-Id: I23e29ec95a2204bb168a641323d05e76968d9b57 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/234832 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
* set default file encoding to utf-8Mike Frysinger2019-06-131-0/+1
| | | | | | | | There's no reason to support any other encoding in these files. This only affects the files themselves and not streams they open. Bug: https://crbug.com/gerrit/10418 Change-Id: I053cb40cd3666ce5c8a0689b9dd938f24ca765bf
* Add support for long pathsRenaud Paquay2018-10-221-2/+3
| | | | | | | | | | | | | | | | | | | | * Add more file i/o wrappers in platform_utils to allow using long paths (length > MAX_PATH) on Windows. * Paths using the long path syntax ("\\?\" prefix) should never escape the platform_utils API surface area, so that this specific syntax is not visible to the rest of the repo code base. * Forward many calls from os.xxx to platform_utils.xxx in various place to ensure long paths support, specifically when repo decides to delete obsolete directories. * There are more places that need to be converted to support long paths, this commit is an initial effort to unblock a few common use cases. * Also, fix remove function to handle directory symlinks Change-Id: If82ccc408e516e96ff7260be25f8fd2fe3f9571a
* Handle Windows line endings when reading binary filesRenaud Paquay2017-08-311-1/+1
| | | | | | | | | Without this change, '.git\HEAD' files, for examples, are sometime read incorrectly resulting in the current branch to be reset to "master" when running a "repo init -b xxx" on an already initialized repository. Change-Id: I48c7ef85ff81626edf156914329a560e14252f2a
* When starting a branch, do not use a tag or change value for branch.mergeZac Livingston2017-08-251-5/+6
| | | | | | | | | | | | | When starting a branch, branch.merge is set to project revision unless the revision is a SHA1. In that case, branch.merge is set to dest_branch if defined or manifest default revision otherwise. This special handling allows repo upload to work when the project revision is a SHA1. Extend the special handling to also happen when the project revision is a tag value or a change value so that repo upload will work in those case as well. Change-Id: Iff81ece40e770cd02535e80dcb023564d42dcf47
* Fix some python3 encoding issuesChirayu Desai2013-11-211-1/+1
| | | | | | * Add .decode('utf-8') where needed * Add 'b' to `open` where needed, and remove where unnecessary Change-Id: I0f03ecf9ed1a78e3b2f15f9469deb9aaab698657
* Some fixes for supporting python3Chirayu Desai2013-04-181-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Fix imports. * Use python3 syntax. * Wrap map() calls with list(). * Use list() only wherever needed. (Thanks Conley!) * Fix dictionary iteration methods (s/iteritems/items/). * Make use of sorted() in appropriate places * Use iterators directly in the loop. * Don't use .keys() wherever it isn't needed. * Use sys.maxsize instead of sys.maxint TODO: * Make repo work fully with python3. :) Some of this was done by the '2to3' tool [1], by applying the needed fixes in a way that doesn't break compatibility with python2. Links: [1]: http://docs.python.org/2/library/2to3.html Change-Id: Ibdf3bf9a530d716db905733cb9bfef83a48820f7 Signed-off-by: Chirayu Desai <cdesai@cyanogenmod.org>
* Even more coding style cleanupDavid Pursehouse2012-10-301-2/+2
| | | | | | | | | | | Fixing some more pylint warnings: W1401: Anomalous backslash in string W0623: Redefining name 'name' from outer scope W0702: No exception type(s) specified E0102: name: function already defined line n Change-Id: I5afcdb4771ce210390a79981937806e30900a93c
* Coding style cleanupDavid Pursehouse2012-10-091-8/+8
| | | | | | | | | | | | | | | Fix the following issues reported by pylint: C0321: More than one statement on a single line W0622: Redefining built-in 'name' W0612: Unused variable 'name' W0613: Unused argument 'name' W0102: Dangerous default value 'value' as argument W0105: String statement has no effect Also fixed a few cases of inconsistent indentation. Change-Id: Ie0db839e7c57d576cff12d8c055fe87030d00744
* Remove unused importsDavid Pursehouse2012-08-231-1/+0
| | | | | | There are several imports that are not used. Remove them. Change-Id: I2ac3be66827bd68d3faedcef7d6bbf30ea01d3f2
* Improve error handling when reading loose refsv1.7.8Shawn O. Pearce2011-11-291-5/+7
| | | | | | | When repo is trying to figure out branches the repository has by traversing refs/heads, add exception handling for readline. Change-Id: If3b2a3720c6496f52f629aa9a2539f186d6ec882
* Make usage of open safer by setting binary mode and closing fdsShawn O. Pearce2009-04-181-2/+2
| | | | Signed-off-by: Shawn O. Pearce <sop@google.com>
* Fix `repo --trace` to show ref and config loadsShawn O. Pearce2009-04-181-5/+5
| | | | | | | | | The value of the varible TRACE was copied during the import, which happens before the --trace option can be processed. So instead we now use a function to determine if the value is set, as the function can be safely copied early during import. Signed-off-by: Shawn O. Pearce <sop@google.com>
* Enable tracing of ref scans and config unpicklingShawn O. Pearce2009-04-171-0/+6
| | | | | | | | These are not as expensive as spawning a git command, but they are not free either. We want to keep track of how many times we wind up calling them on any particular operation. Signed-off-by: Shawn O. Pearce <sop@google.com>
* Avoid unnecessary git symbolic-ref calls during repo syncShawn O. Pearce2009-04-171-2/+12
| | | | | | | | If the m/BRANCH ref is already pointing at the value set in the manifest there is no reason to set it again. Leave it alone, thus saving a full fork+exec call. Signed-off-by: Shawn O. Pearce <sop@google.com>
* Improve repo sync performance by avoid git forksShawn O. Pearce2009-04-171-0/+11
| | | | | | | | | | | By resolving the current HEAD and the manifest revision using pure Python, we can in the common case of "no changes" avoid a lot of git operations and directly jump out of the local sync method. This reduces the no-op `repo sync -l` time for Android's 114 projects from more than 6s to under 0.8s. Signed-off-by: Shawn O. Pearce <sop@google.com>
* Implement git ref reading purely in PythonShawn O. Pearce2009-04-171-0/+133
Its much faster to read the refs from 114 projects when the reader is pure Python and just doing file IO than forking 114 git commands and parsing their output. The reader caches refs based upon file mtimes. If any single ref file has been modified since the last read, we re-read the entire repository's ref namespace. This simplifies the code as we don't need to worry about shooting down symbolic-refs, but it may cause more IO than is necessary if only one ref gets updated. This change drops `repo branches` in Android from 1.658s to 0.206s. Likewise, `repo sync` improves dramatically as well. Signed-off-by: Shawn O. Pearce <sop@google.com>