diff options
| author | Haibo Huang <hhb@google.com> | 2018-08-03 11:52:25 -0700 |
|---|---|---|
| committer | Haibo Huang <hhb@google.com> | 2018-08-06 14:51:32 -0700 |
| commit | 9dcade4c2d57a3000aef93a1bbfbf5bdf5a96a32 (patch) | |
| tree | 8efbaae28dc974bafcca2b61ee699eda36816495 /git_utils.py | |
| parent | 1c3a4f469f78103482b94e3f7a8d0c19becf2bfc (diff) | |
| download | platform_tools_external_updater-9dcade4c2d57a3000aef93a1bbfbf5bdf5a96a32.tar.gz platform_tools_external_updater-9dcade4c2d57a3000aef93a1bbfbf5bdf5a96a32.tar.bz2 platform_tools_external_updater-9dcade4c2d57a3000aef93a1bbfbf5bdf5a96a32.zip | |
[Updater] Prefer url similar to previous one
This change computes edit distant between old url and each of new urls.
And use the url most like previous one.
Test: update any library
Change-Id: I959a22168652c7543da2cdb29d36a1d061ade7e9
Diffstat (limited to 'git_utils.py')
| -rw-r--r-- | git_utils.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/git_utils.py b/git_utils.py index 8e8f96d..5743b8f 100644 --- a/git_utils.py +++ b/git_utils.py @@ -22,6 +22,7 @@ def _run(cmd, cwd): return subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, cwd=cwd) + def fetch(proj_path, remote_names): """Runs git fetch. @@ -31,6 +32,7 @@ def fetch(proj_path, remote_names): """ _run(['git', 'fetch', '--multiple'] + remote_names, cwd=proj_path) + def add_remote(proj_path, name, url): """Adds a git remote. @@ -41,6 +43,7 @@ def add_remote(proj_path, name, url): """ _run(['git', 'remote', 'add', name, url], cwd=proj_path) + def list_remotes(proj_path): """Lists all Git remotes. @@ -54,6 +57,7 @@ def list_remotes(proj_path): lines = out.stdout.decode('utf-8').splitlines() return dict([line.split()[0:2] for line in lines]) + def get_commits_ahead(proj_path, branch, base_branch): """Lists commits in `branch` but not `base_branch`.""" out = _run(['git', 'rev-list', '--left-only', @@ -61,11 +65,13 @@ def get_commits_ahead(proj_path, branch, base_branch): proj_path) return out.stdout.decode('utf-8').splitlines() + def get_commit_time(proj_path, commit): """Gets commit time of one commit.""" out = _run(['git', 'show', '-s', '--format=%ct', commit], cwd=proj_path) return datetime.datetime.fromtimestamp(int(out.stdout)) + def list_remote_branches(proj_path, remote_name): """Lists all branches for a remote.""" out = _run(['git', 'branch', '-r'], cwd=proj_path) |
